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_MidiOutput.h 5.3KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_MIDIOUTPUT_H_INCLUDED
  18. #define JUCE_MIDIOUTPUT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Controls a physical MIDI output device.
  22. To create one of these, use the static getDevices() method to get a list of the
  23. available output devices, then use the openDevice() method to try to open one.
  24. @see MidiInput
  25. */
  26. class JUCE_API MidiOutput : private Thread
  27. {
  28. public:
  29. //==============================================================================
  30. /** Returns a list of the available midi output devices.
  31. You can open one of the devices by passing its index into the
  32. openDevice() method.
  33. @see getDefaultDeviceIndex, openDevice
  34. */
  35. static StringArray getDevices();
  36. /** Returns the index of the default midi output device to use.
  37. This refers to the index in the list returned by getDevices().
  38. */
  39. static int getDefaultDeviceIndex();
  40. /** Tries to open one of the midi output devices.
  41. This will return a MidiOutput object if it manages to open it. You can then
  42. send messages to this device, and delete it when no longer needed.
  43. If the device can't be opened, this will return a null pointer.
  44. @param deviceIndex the index of a device from the list returned by getDevices()
  45. @see getDevices
  46. */
  47. static MidiOutput* openDevice (int deviceIndex);
  48. #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
  49. /** This will try to create a new midi output device (Not available on Windows).
  50. This will attempt to create a new midi output device that other apps can connect
  51. to and use as their midi input.
  52. Returns nullptr if a device can't be created.
  53. @param deviceName the name to use for the new device
  54. */
  55. static MidiOutput* createNewDevice (const String& deviceName);
  56. #endif
  57. //==============================================================================
  58. /** Destructor. */
  59. ~MidiOutput();
  60. /** Returns the name of this device. */
  61. const String& getName() const noexcept { return name; }
  62. /** Makes this device output a midi message.
  63. @see MidiMessage
  64. */
  65. void sendMessageNow (const MidiMessage& message);
  66. //==============================================================================
  67. /** This lets you supply a block of messages that will be sent out at some point
  68. in the future.
  69. The MidiOutput class has an internal thread that can send out timestamped
  70. messages - this appends a set of messages to its internal buffer, ready for
  71. sending.
  72. This will only work if you've already started the thread with startBackgroundThread().
  73. A time is specified, at which the block of messages should be sent. This time uses
  74. the same time base as Time::getMillisecondCounter(), and must be in the future.
  75. The samplesPerSecondForBuffer parameter indicates the number of samples per second
  76. used by the MidiBuffer. Each event in a MidiBuffer has a sample position, and the
  77. samplesPerSecondForBuffer value is needed to convert this sample position to a
  78. real time.
  79. */
  80. void sendBlockOfMessages (const MidiBuffer& buffer,
  81. double millisecondCounterToStartAt,
  82. double samplesPerSecondForBuffer);
  83. /** Gets rid of any midi messages that had been added by sendBlockOfMessages(). */
  84. void clearAllPendingMessages();
  85. /** Starts up a background thread so that the device can send blocks of data.
  86. Call this to get the device ready, before using sendBlockOfMessages().
  87. */
  88. void startBackgroundThread();
  89. /** Stops the background thread, and clears any pending midi events.
  90. @see startBackgroundThread
  91. */
  92. void stopBackgroundThread();
  93. private:
  94. //==============================================================================
  95. void* internal;
  96. CriticalSection lock;
  97. struct PendingMessage;
  98. PendingMessage* firstMessage;
  99. String name;
  100. MidiOutput(const String& midiName); // These objects are created with the openDevice() method.
  101. void run() override;
  102. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput)
  103. };
  104. #endif // JUCE_MIDIOUTPUT_H_INCLUDED