The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_MIDITEST_MAINCOMPONENT_H
  18. #define JUCE_MIDITEST_MAINCOMPONENT_H
  19. #include "JuceHeader.h"
  20. //==============================================================================
  21. class MidiDeviceListBox;
  22. struct MidiDeviceListEntry;
  23. //==============================================================================
  24. class MainContentComponent : public Component,
  25. private Timer,
  26. private MidiKeyboardStateListener,
  27. private MidiInputCallback,
  28. private MessageListener,
  29. private ButtonListener
  30. {
  31. public:
  32. //==============================================================================
  33. MainContentComponent ();
  34. ~MainContentComponent();
  35. //==============================================================================
  36. void timerCallback () override;
  37. void handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override;
  38. void handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override;
  39. void handleMessage (const Message& msg) override;
  40. void paint (Graphics& g) override;
  41. void resized() override;
  42. void buttonClicked (Button* buttonThatWasClicked) override;
  43. void openDevice (bool isInput, int index);
  44. void closeDevice (bool isInput, int index);
  45. int getNumMidiInputs() const noexcept;
  46. int getNumMidiOutputs() const noexcept;
  47. ReferenceCountedObjectPtr<MidiDeviceListEntry> getMidiDevice (int index, bool isInputDevice) const noexcept;
  48. private:
  49. //==============================================================================
  50. void handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message) override;
  51. void sendToOutputs(const MidiMessage& msg);
  52. //==============================================================================
  53. bool hasDeviceListChanged (const StringArray& deviceNames, bool isInputDevice);
  54. ReferenceCountedObjectPtr<MidiDeviceListEntry> findDeviceWithName (const String& name, bool isInputDevice) const;
  55. void closeUnpluggedDevices (StringArray& currentlyPluggedInDevices, bool isInputDevice);
  56. void updateDeviceList (bool isInputDeviceList);
  57. //==============================================================================
  58. void addLabelAndSetStyle (Label& label);
  59. //==============================================================================
  60. Label midiInputLabel;
  61. Label midiOutputLabel;
  62. Label incomingMidiLabel;
  63. Label outgoingMidiLabel;
  64. MidiKeyboardState keyboardState;
  65. MidiKeyboardComponent midiKeyboard;
  66. TextEditor midiMonitor;
  67. TextButton pairButton;
  68. ScopedPointer<MidiDeviceListBox> midiInputSelector;
  69. ScopedPointer<MidiDeviceListBox> midiOutputSelector;
  70. ReferenceCountedArray<MidiDeviceListEntry> midiInputs;
  71. ReferenceCountedArray<MidiDeviceListEntry> midiOutputs;
  72. //==============================================================================
  73. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
  74. };
  75. #endif // JUCE_MIDITEST_MAINCOMPONENT_H