From 44b9eba29a889d9b167d826e3cdc88a43cab3a9e Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 10 Nov 2015 17:22:06 +0000 Subject: [PATCH] Demo App: Added a MIDI output device option to the MIDI i/o page --- examples/Demo/Source/Demos/MidiDemo.cpp | 39 +++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/examples/Demo/Source/Demos/MidiDemo.cpp b/examples/Demo/Source/Demos/MidiDemo.cpp index 6b58a05c9e..fed2a254dc 100644 --- a/examples/Demo/Source/Demos/MidiDemo.cpp +++ b/examples/Demo/Source/Demos/MidiDemo.cpp @@ -105,6 +105,7 @@ public: { setOpaque (true); + // MIDI Inputs addAndMakeVisible (midiInputListLabel); midiInputListLabel.setText ("MIDI Input:", dontSendNotification); midiInputListLabel.attachToComponent (&midiInputList, true); @@ -115,7 +116,7 @@ public: midiInputList.addItemList (midiInputs, 1); midiInputList.addListener (this); - // find the first enabled device and use that bu default + // find the first enabled device and use that by default for (int i = 0; i < midiInputs.size(); ++i) { if (deviceManager.isMidiInputEnabled (midiInputs[i])) @@ -129,6 +130,17 @@ public: if (midiInputList.getSelectedId() == 0) setMidiInput (0); + + // MIDI Outputs + addAndMakeVisible (midiOutputListLabel); + midiOutputListLabel.setText ("MIDI Output:", dontSendNotification); + midiOutputListLabel.attachToComponent (&midiOutputList, true); + + addAndMakeVisible (midiOutputList); + midiOutputList.setTextWhenNoChoicesAvailable ("No MIDI Output Enabled"); + midiOutputList.addItemList (MidiOutput::getDevices(), 1); + midiOutputList.addListener (this); + addAndMakeVisible (keyboardComponent); keyboardState.addListener (this); @@ -154,14 +166,15 @@ public: { Rectangle area (getLocalBounds()); midiInputList.setBounds (area.removeFromTop (36).removeFromRight (getWidth() - 150).reduced (8)); + midiOutputList.setBounds (area.removeFromTop (36).removeFromRight (getWidth() - 150).reduced (8)); keyboardComponent.setBounds (area.removeFromTop (80).reduced(8)); messageListBox.setBounds (area.reduced (8)); } private: AudioDeviceManager& deviceManager; - ComboBox midiInputList; - Label midiInputListLabel; + ComboBox midiInputList, midiOutputList; + Label midiInputListLabel, midiOutputListLabel; int lastInputIndex; bool isAddingFromMidiInput; @@ -171,6 +184,7 @@ private: ListBox messageListBox; Array midiMessageList; MidiLogListBoxModel midiLogListBoxModel; + ScopedPointer currentMidiOutput; //============================================================================== /** Starts listening to a MIDI input device, enabling it if necessary. */ @@ -191,10 +205,22 @@ private: lastInputIndex = index; } + //============================================================================== + void setMidiOutput (int index) + { + currentMidiOutput = nullptr; + + if (MidiOutput::getDevices() [index].isNotEmpty()) + { + currentMidiOutput = MidiOutput::openDevice (index); + jassert (currentMidiOutput); + } + } + void comboBoxChanged (ComboBox* box) override { - if (box == &midiInputList) - setMidiInput (midiInputList.getSelectedItemIndex()); + if (box == &midiInputList) setMidiInput (midiInputList.getSelectedItemIndex()); + if (box == &midiOutputList) setMidiOutput (midiOutputList.getSelectedItemIndex()); } // These methods handle callbacks from the midi device + on-screen keyboard.. @@ -243,6 +269,9 @@ private: void postMessageToList (const MidiMessage& message) { + if (currentMidiOutput != nullptr) + currentMidiOutput->sendMessageNow (message); + (new IncomingMessageCallback (this, message))->post(); }