Audio plugin host https://kx.studio/carla
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.

juce_MidiInput.h 6.5KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_MIDIINPUT_H_INCLUDED
  18. #define JUCE_MIDIINPUT_H_INCLUDED
  19. class MidiInput;
  20. //==============================================================================
  21. /**
  22. Receives incoming messages from a physical MIDI input device.
  23. This class is overridden to handle incoming midi messages. See the MidiInput
  24. class for more details.
  25. @see MidiInput
  26. */
  27. class JUCE_API MidiInputCallback
  28. {
  29. public:
  30. /** Destructor. */
  31. virtual ~MidiInputCallback() {}
  32. /** Receives an incoming message.
  33. A MidiInput object will call this method when a midi event arrives. It'll be
  34. called on a high-priority system thread, so avoid doing anything time-consuming
  35. in here, and avoid making any UI calls. You might find the MidiBuffer class helpful
  36. for queueing incoming messages for use later.
  37. @param source the MidiInput object that generated the message
  38. @param message the incoming message. The message's timestamp is set to a value
  39. equivalent to (Time::getMillisecondCounter() / 1000.0) to specify the
  40. time when the message arrived.
  41. */
  42. virtual void handleIncomingMidiMessage (MidiInput* source,
  43. const MidiMessage& message) = 0;
  44. /** Notification sent each time a packet of a multi-packet sysex message arrives.
  45. If a long sysex message is broken up into multiple packets, this callback is made
  46. for each packet that arrives until the message is finished, at which point
  47. the normal handleIncomingMidiMessage() callback will be made with the entire
  48. message.
  49. The message passed in will contain the start of a sysex, but won't be finished
  50. with the terminating 0xf7 byte.
  51. */
  52. virtual void handlePartialSysexMessage (MidiInput* source,
  53. const uint8* messageData,
  54. int numBytesSoFar,
  55. double timestamp)
  56. {
  57. // (this bit is just to avoid compiler warnings about unused variables)
  58. (void) source; (void) messageData; (void) numBytesSoFar; (void) timestamp;
  59. }
  60. };
  61. //==============================================================================
  62. /**
  63. Represents a midi input device.
  64. To create one of these, use the static getDevices() method to find out what inputs are
  65. available, and then use the openDevice() method to try to open one.
  66. @see MidiOutput
  67. */
  68. class JUCE_API MidiInput
  69. {
  70. public:
  71. //==============================================================================
  72. /** Returns a list of the available midi input devices.
  73. You can open one of the devices by passing its index into the
  74. openDevice() method.
  75. @see getDefaultDeviceIndex, openDevice
  76. */
  77. static StringArray getDevices();
  78. /** Returns the index of the default midi input device to use.
  79. This refers to the index in the list returned by getDevices().
  80. */
  81. static int getDefaultDeviceIndex();
  82. /** Tries to open one of the midi input devices.
  83. This will return a MidiInput object if it manages to open it. You can then
  84. call start() and stop() on this device, and delete it when no longer needed.
  85. If the device can't be opened, this will return a null pointer.
  86. @param deviceIndex the index of a device from the list returned by getDevices()
  87. @param callback the object that will receive the midi messages from this device.
  88. @see MidiInputCallback, getDevices
  89. */
  90. static MidiInput* openDevice (int deviceIndex,
  91. MidiInputCallback* callback);
  92. #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
  93. /** This will try to create a new midi input device (Not available on Windows).
  94. This will attempt to create a new midi input device with the specified name,
  95. for other apps to connect to.
  96. Returns nullptr if a device can't be created.
  97. @param deviceName the name to use for the new device
  98. @param callback the object that will receive the midi messages from this device.
  99. */
  100. static MidiInput* createNewDevice (const String& deviceName,
  101. MidiInputCallback* callback);
  102. #endif
  103. //==============================================================================
  104. /** Destructor. */
  105. ~MidiInput();
  106. /** Returns the name of this device. */
  107. const String& getName() const noexcept { return name; }
  108. /** Allows you to set a custom name for the device, in case you don't like the name
  109. it was given when created.
  110. */
  111. void setName (const String& newName) noexcept { name = newName; }
  112. //==============================================================================
  113. /** Starts the device running.
  114. After calling this, the device will start sending midi messages to the
  115. MidiInputCallback object that was specified when the openDevice() method
  116. was called.
  117. @see stop
  118. */
  119. void start();
  120. /** Stops the device running.
  121. @see start
  122. */
  123. void stop();
  124. private:
  125. //==============================================================================
  126. String name;
  127. void* internal;
  128. // The input objects are created with the openDevice() method.
  129. explicit MidiInput (const String&);
  130. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiInput)
  131. };
  132. #endif // JUCE_MIDIINPUT_H_INCLUDED