Skip to content

Commit

Permalink
Added paging to log windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mauer committed Mar 18, 2024
1 parent 3c2f973 commit 9985d65
Show file tree
Hide file tree
Showing 16 changed files with 347 additions and 409 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: false
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
+ Added sublayer support for outbound messages
+ Enabled slider mappings for virtual devices
+ Renamed velocity to data_2 to be more aligned with the midi specification
+ Added paging to logging windows for better performance, remove max log setting

-----------------------------------------------------------------------------------------------------------------------

Expand Down
35 changes: 2 additions & 33 deletions src/common/midi_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ namespace xmidictrl {
/**
* Constructor
*/
midi_logger::midi_logger(bool in_enabled, int in_max_messages)
midi_logger::midi_logger(bool in_enabled)
: m_enabled(in_enabled)
, m_max_messages(in_max_messages)
{}


Expand Down Expand Up @@ -89,26 +88,10 @@ void midi_logger::disable()
}


/**
* Set the maximum number of midi messages in the logger
*
* @param in_max_messages max. number of messages
*/
void midi_logger::set_max_messages(int in_max_messages)
{
std::mutex mutex;
std::scoped_lock lock(mutex);

m_max_messages = in_max_messages;

adjust_log_size();
}


/**
* Return a specific midi message
*/
midi_message* midi_logger::message(int in_index)
midi_message* midi_logger::message(size_t in_index)
{
std::mutex mutex;
std::scoped_lock lock(mutex);
Expand All @@ -128,21 +111,7 @@ void midi_logger::add(const std::shared_ptr<midi_message>& in_msg)
if (!m_enabled)
return;

adjust_log_size();

m_messages.push_back(in_msg);
}


/**
* Adjust the log size depending on the current settings
*/
void midi_logger::adjust_log_size()
{
std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);

while (m_messages.size() >= m_max_messages) m_messages.pop_front();
}

} // Namespace xmidictrl
27 changes: 11 additions & 16 deletions src/common/midi_logger.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------------------------------------------------
// XMidiCtrl - MIDI Controller plugin for X-Plane
//
// Copyright (c) 2021-2023 Marco Auer
// Copyright (c) 2021-2024 Marco Auer
//
// XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the
// GNU Affero General Public License as published by the Free Software Foundation, either version 3
Expand Down Expand Up @@ -29,28 +29,23 @@ namespace xmidictrl {

class midi_logger {
public:
explicit midi_logger(bool in_enabled, int in_max_messages);
~midi_logger() = default;
explicit midi_logger(bool in_enabled);
~midi_logger() = default;

void clear();
size_t count();
void clear();
size_t count();

void enable();
void disable();
void enable();
void disable();

void set_max_messages(int in_max_messages);
midi_message* message(size_t in_index);

midi_message* message(int in_index);

void add(const std::shared_ptr<midi_message>& in_msg);
void add(const std::shared_ptr<midi_message>& in_msg);

private:
void adjust_log_size();

bool m_enabled;
int m_max_messages;
bool m_enabled;

std::deque<std::shared_ptr<midi_message>> m_messages;
std::deque<std::shared_ptr<midi_message>> m_messages;
};

} // Namespace xmidictrl
Expand Down
Loading

0 comments on commit 9985d65

Please sign in to comment.