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.

154 lines
5.8KB

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