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.

186 lines
6.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_MIDIINPUT_H_INCLUDED
  24. #define JUCE_MIDIINPUT_H_INCLUDED
  25. class MidiInput;
  26. //==============================================================================
  27. /**
  28. Receives incoming messages from a physical MIDI input device.
  29. This class is overridden to handle incoming midi messages. See the MidiInput
  30. class for more details.
  31. @see MidiInput
  32. */
  33. class JUCE_API MidiInputCallback
  34. {
  35. public:
  36. /** Destructor. */
  37. virtual ~MidiInputCallback() {}
  38. /** Receives an incoming message.
  39. A MidiInput object will call this method when a midi event arrives. It'll be
  40. called on a high-priority system thread, so avoid doing anything time-consuming
  41. in here, and avoid making any UI calls. You might find the MidiBuffer class helpful
  42. for queueing incoming messages for use later.
  43. @param source the MidiInput object that generated the message
  44. @param message the incoming message. The message's timestamp is set to a value
  45. equivalent to (Time::getMillisecondCounter() / 1000.0) to specify the
  46. time when the message arrived.
  47. */
  48. virtual void handleIncomingMidiMessage (MidiInput* source,
  49. const MidiMessage& message) = 0;
  50. /** Notification sent each time a packet of a multi-packet sysex message arrives.
  51. If a long sysex message is broken up into multiple packets, this callback is made
  52. for each packet that arrives until the message is finished, at which point
  53. the normal handleIncomingMidiMessage() callback will be made with the entire
  54. message.
  55. The message passed in will contain the start of a sysex, but won't be finished
  56. with the terminating 0xf7 byte.
  57. */
  58. virtual void handlePartialSysexMessage (MidiInput* source,
  59. const uint8* messageData,
  60. int numBytesSoFar,
  61. double timestamp)
  62. {
  63. ignoreUnused (source, messageData, numBytesSoFar, timestamp);
  64. }
  65. };
  66. //==============================================================================
  67. /**
  68. Represents a midi input device.
  69. To create one of these, use the static getDevices() method to find out what inputs are
  70. available, and then use the openDevice() method to try to open one.
  71. @see MidiOutput
  72. */
  73. class JUCE_API MidiInput
  74. {
  75. public:
  76. //==============================================================================
  77. /** Returns a list of the available midi input devices.
  78. You can open one of the devices by passing its index into the
  79. openDevice() method.
  80. @see getDefaultDeviceIndex, openDevice
  81. */
  82. static StringArray getDevices();
  83. /** Returns the index of the default midi input device to use.
  84. This refers to the index in the list returned by getDevices().
  85. */
  86. static int getDefaultDeviceIndex();
  87. /** Tries to open one of the midi input devices.
  88. This will return a MidiInput object if it manages to open it. You can then
  89. call start() and stop() on this device, and delete it when no longer needed.
  90. If the device can't be opened, this will return a null pointer.
  91. @param deviceIndex the index of a device from the list returned by getDevices()
  92. @param callback the object that will receive the midi messages from this device.
  93. @see MidiInputCallback, getDevices
  94. */
  95. static MidiInput* openDevice (int deviceIndex,
  96. MidiInputCallback* callback);
  97. #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
  98. /** This will try to create a new midi input device (Not available on Windows).
  99. This will attempt to create a new midi input device with the specified name,
  100. for other apps to connect to.
  101. Returns nullptr if a device can't be created.
  102. @param deviceName the name to use for the new device
  103. @param callback the object that will receive the midi messages from this device.
  104. */
  105. static MidiInput* createNewDevice (const String& deviceName,
  106. MidiInputCallback* callback);
  107. #endif
  108. //==============================================================================
  109. /** Destructor. */
  110. ~MidiInput();
  111. /** Returns the name of this device. */
  112. const String& getName() const noexcept { return name; }
  113. /** Allows you to set a custom name for the device, in case you don't like the name
  114. it was given when created.
  115. */
  116. void setName (const String& newName) noexcept { name = newName; }
  117. //==============================================================================
  118. /** Starts the device running.
  119. After calling this, the device will start sending midi messages to the
  120. MidiInputCallback object that was specified when the openDevice() method
  121. was called.
  122. @see stop
  123. */
  124. void start();
  125. /** Stops the device running.
  126. @see start
  127. */
  128. void stop();
  129. private:
  130. //==============================================================================
  131. String name;
  132. void* internal;
  133. // The input objects are created with the openDevice() method.
  134. explicit MidiInput (const String&);
  135. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiInput)
  136. };
  137. #endif // JUCE_MIDIINPUT_H_INCLUDED