From c73c120334f4e170dba029f3794e5e8ba601c127 Mon Sep 17 00:00:00 2001 From: Michael Fisher Date: Sun, 7 Jun 2020 03:36:53 -0400 Subject: [PATCH] Added clear button to midi monitor node Closes #176 --- src/engine/nodes/MidiMonitorNode.cpp | 8 +++++--- src/gui/nodes/MidiMonitorNodeEditor.cpp | 14 +++++++++++++- src/gui/nodes/MidiMonitorNodeEditor.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/engine/nodes/MidiMonitorNode.cpp b/src/engine/nodes/MidiMonitorNode.cpp index 5e41a7f41..74d198ef4 100644 --- a/src/engine/nodes/MidiMonitorNode.cpp +++ b/src/engine/nodes/MidiMonitorNode.cpp @@ -85,10 +85,12 @@ void MidiMonitorNode::getMessages (MidiBuffer& destBuffer) void MidiMonitorNode::clearMessages() { midiLog.clearQuick(); + { + ScopedLock sl (lock); + inputMessages.reset (currentSampleRate); + numSamples = 0; + } messagesLogged(); - ScopedLock sl (lock); - inputMessages.reset (currentSampleRate); - numSamples = 0; } void MidiMonitorNode::timerCallback() diff --git a/src/gui/nodes/MidiMonitorNodeEditor.cpp b/src/gui/nodes/MidiMonitorNodeEditor.cpp index 2f7648f07..c91ec835f 100644 --- a/src/gui/nodes/MidiMonitorNodeEditor.cpp +++ b/src/gui/nodes/MidiMonitorNodeEditor.cpp @@ -79,6 +79,14 @@ MidiMonitorNodeEditor::MidiMonitorNodeEditor (const Node& node) setOpaque (true); logger.reset (new Logger (getNodeObjectOfType())); addAndMakeVisible (logger.get()); + + addAndMakeVisible (clearButton); + clearButton.setButtonText ("Clear"); + clearButton.onClick = [this]() { + if (auto* n = getNodeObjectOfType()) + n->clearMessages(); + }; + setSize (320, 160); } @@ -89,7 +97,11 @@ MidiMonitorNodeEditor::~MidiMonitorNodeEditor() void MidiMonitorNodeEditor::resized () { - logger->setBounds (getLocalBounds().reduced (4)); + auto r1 = getLocalBounds().reduced (4); + clearButton.changeWidthToFitText (24); + clearButton.setBounds (r1.getX(), r1.getY(), clearButton.getWidth(), clearButton.getHeight()); + r1.removeFromTop (24 + 2); + logger->setBounds (r1); } }; diff --git a/src/gui/nodes/MidiMonitorNodeEditor.h b/src/gui/nodes/MidiMonitorNodeEditor.h index f75d82108..831bf6979 100644 --- a/src/gui/nodes/MidiMonitorNodeEditor.h +++ b/src/gui/nodes/MidiMonitorNodeEditor.h @@ -34,6 +34,7 @@ class MidiMonitorNodeEditor : public NodeEditorComponent private: class Logger; std::unique_ptr logger; + TextButton clearButton; }; }