mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Improved performance in the MIDI i/o demo app
This commit is contained in:
parent
79221a8418
commit
10d4235aaf
1 changed files with 29 additions and 28 deletions
|
|
@ -59,19 +59,13 @@ struct MidiDeviceListEntry : ReferenceCountedObject
|
|||
using Ptr = ReferenceCountedObjectPtr<MidiDeviceListEntry>;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
struct MidiCallbackMessage : public Message
|
||||
{
|
||||
MidiCallbackMessage (const MidiMessage& msg) : message (msg) {}
|
||||
MidiMessage message;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
class MidiDemo : public Component,
|
||||
private Timer,
|
||||
private MidiKeyboardStateListener,
|
||||
private MidiInputCallback,
|
||||
private MessageListener
|
||||
private AsyncUpdater
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
|
|
@ -152,14 +146,6 @@ public:
|
|||
sendToOutputs (m);
|
||||
}
|
||||
|
||||
void handleMessage (const Message& msg) override
|
||||
{
|
||||
// This is called on the message loop
|
||||
|
||||
auto& mm = dynamic_cast<const MidiCallbackMessage&> (msg).message;
|
||||
midiMonitor.insertTextAtCaret (mm.getDescription() + "\n");
|
||||
}
|
||||
|
||||
void paint (Graphics&) override {}
|
||||
|
||||
void resized() override
|
||||
|
|
@ -253,11 +239,9 @@ public:
|
|||
|
||||
private:
|
||||
//==============================================================================
|
||||
class MidiDeviceListBox : public ListBox,
|
||||
private ListBoxModel
|
||||
struct MidiDeviceListBox : public ListBox,
|
||||
private ListBoxModel
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
MidiDeviceListBox (const String& name,
|
||||
MidiDemo& contentComponent,
|
||||
bool isInputDeviceList)
|
||||
|
|
@ -277,7 +261,6 @@ private:
|
|||
: parent.getNumMidiOutputs();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void paintListBoxItem (int rowNumber, Graphics& g,
|
||||
int width, int height, bool rowIsSelected) override
|
||||
{
|
||||
|
|
@ -352,12 +335,30 @@ private:
|
|||
void handleIncomingMidiMessage (MidiInput* /*source*/, const MidiMessage& message) override
|
||||
{
|
||||
// This is called on the MIDI thread
|
||||
|
||||
if (message.isNoteOnOrOff())
|
||||
postMessage (new MidiCallbackMessage (message));
|
||||
const ScopedLock sl (midiMonitorLock);
|
||||
incomingMessages.add (message);
|
||||
triggerAsyncUpdate();
|
||||
}
|
||||
|
||||
void sendToOutputs(const MidiMessage& msg)
|
||||
void handleAsyncUpdate() override
|
||||
{
|
||||
// This is called on the message loop
|
||||
Array<MidiMessage> messages;
|
||||
|
||||
{
|
||||
const ScopedLock sl (midiMonitorLock);
|
||||
messages.swapWith (incomingMessages);
|
||||
}
|
||||
|
||||
String messageText;
|
||||
|
||||
for (auto& m : messages)
|
||||
messageText << m.getDescription() << "\n";
|
||||
|
||||
midiMonitor.insertTextAtCaret (messageText);
|
||||
}
|
||||
|
||||
void sendToOutputs (const MidiMessage& msg)
|
||||
{
|
||||
for (auto midiOutput : midiOutputs)
|
||||
if (midiOutput->outDevice.get() != nullptr)
|
||||
|
|
@ -469,11 +470,11 @@ private:
|
|||
TextEditor midiMonitor { "MIDI Monitor" };
|
||||
TextButton pairButton { "MIDI Bluetooth devices..." };
|
||||
|
||||
std::unique_ptr<MidiDeviceListBox> midiInputSelector;
|
||||
std::unique_ptr<MidiDeviceListBox> midiOutputSelector;
|
||||
std::unique_ptr<MidiDeviceListBox> midiInputSelector, midiOutputSelector;
|
||||
ReferenceCountedArray<MidiDeviceListEntry> midiInputs, midiOutputs;
|
||||
|
||||
ReferenceCountedArray<MidiDeviceListEntry> midiInputs;
|
||||
ReferenceCountedArray<MidiDeviceListEntry> midiOutputs;
|
||||
CriticalSection midiMonitorLock;
|
||||
Array<MidiMessage> incomingMessages;
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiDemo)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue