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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. virtual ~MidiOutput();
  60. /** Makes this device output a midi message.
  61. @see MidiMessage
  62. */
  63. virtual void sendMessageNow (const MidiMessage& message);
  64. //==============================================================================
  65. /** This lets you supply a block of messages that will be sent out at some point
  66. in the future.
  67. The MidiOutput class has an internal thread that can send out timestamped
  68. messages - this appends a set of messages to its internal buffer, ready for
  69. sending.
  70. This will only work if you've already started the thread with startBackgroundThread().
  71. A time is supplied, at which the block of messages should be sent. This time uses
  72. the same time base as Time::getMillisecondCounter(), and must be in the future.
  73. The samplesPerSecondForBuffer parameter indicates the number of samples per second
  74. used by the MidiBuffer. Each event in a MidiBuffer has a sample position, and the
  75. samplesPerSecondForBuffer value is needed to convert this sample position to a
  76. real time.
  77. */
  78. virtual void sendBlockOfMessages (const MidiBuffer& buffer,
  79. double millisecondCounterToStartAt,
  80. double samplesPerSecondForBuffer);
  81. /** Gets rid of any midi messages that had been added by sendBlockOfMessages().
  82. */
  83. virtual void clearAllPendingMessages();
  84. /** Starts up a background thread so that the device can send blocks of data.
  85. Call this to get the device ready, before using sendBlockOfMessages().
  86. */
  87. virtual void startBackgroundThread();
  88. /** Stops the background thread, and clears any pending midi events.
  89. @see startBackgroundThread
  90. */
  91. virtual void stopBackgroundThread();
  92. protected:
  93. //==============================================================================
  94. void* internal;
  95. CriticalSection lock;
  96. struct PendingMessage;
  97. PendingMessage* firstMessage;
  98. MidiOutput();
  99. void run() override;
  100. private:
  101. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput)
  102. };
  103. #endif // JUCE_MIDIOUTPUT_H_INCLUDED