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.

97 lines
4.0KB

  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. #pragma once
  18. #include "JuceHeader.h"
  19. //==============================================================================
  20. class MidiDeviceListBox;
  21. struct MidiDeviceListEntry;
  22. //==============================================================================
  23. class MainContentComponent : public Component,
  24. private Timer,
  25. private MidiKeyboardStateListener,
  26. private MidiInputCallback,
  27. private MessageListener,
  28. private ButtonListener
  29. {
  30. public:
  31. //==============================================================================
  32. MainContentComponent ();
  33. ~MainContentComponent();
  34. //==============================================================================
  35. void timerCallback () override;
  36. void handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override;
  37. void handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override;
  38. void handleMessage (const Message& msg) override;
  39. void paint (Graphics& g) override;
  40. void resized() override;
  41. void buttonClicked (Button* buttonThatWasClicked) override;
  42. void openDevice (bool isInput, int index);
  43. void closeDevice (bool isInput, int index);
  44. int getNumMidiInputs() const noexcept;
  45. int getNumMidiOutputs() const noexcept;
  46. ReferenceCountedObjectPtr<MidiDeviceListEntry> getMidiDevice (int index, bool isInputDevice) const noexcept;
  47. private:
  48. //==============================================================================
  49. void handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message) override;
  50. void sendToOutputs(const MidiMessage& msg);
  51. //==============================================================================
  52. bool hasDeviceListChanged (const StringArray& deviceNames, bool isInputDevice);
  53. ReferenceCountedObjectPtr<MidiDeviceListEntry> findDeviceWithName (const String& name, bool isInputDevice) const;
  54. void closeUnpluggedDevices (StringArray& currentlyPluggedInDevices, bool isInputDevice);
  55. void updateDeviceList (bool isInputDeviceList);
  56. //==============================================================================
  57. void addLabelAndSetStyle (Label& label);
  58. //==============================================================================
  59. Label midiInputLabel;
  60. Label midiOutputLabel;
  61. Label incomingMidiLabel;
  62. Label outgoingMidiLabel;
  63. MidiKeyboardState keyboardState;
  64. MidiKeyboardComponent midiKeyboard;
  65. TextEditor midiMonitor;
  66. TextButton pairButton;
  67. ScopedPointer<MidiDeviceListBox> midiInputSelector;
  68. ScopedPointer<MidiDeviceListBox> midiOutputSelector;
  69. ReferenceCountedArray<MidiDeviceListEntry> midiInputs;
  70. ReferenceCountedArray<MidiDeviceListEntry> midiOutputs;
  71. //==============================================================================
  72. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
  73. };