The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

149 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_MIDIOUTPUT_JUCEHEADER__
  19. #define __JUCE_MIDIOUTPUT_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Controls a physical MIDI output device.
  23. To create one of these, use the static getDevices() method to get a list of the
  24. available output devices, then use the openDevice() method to try to open one.
  25. @see MidiInput
  26. */
  27. class JUCE_API MidiOutput : private Thread
  28. {
  29. public:
  30. //==============================================================================
  31. /** Returns a list of the available midi output devices.
  32. You can open one of the devices by passing its index into the
  33. openDevice() method.
  34. @see getDefaultDeviceIndex, openDevice
  35. */
  36. static StringArray getDevices();
  37. /** Returns the index of the default midi output device to use.
  38. This refers to the index in the list returned by getDevices().
  39. */
  40. static int getDefaultDeviceIndex();
  41. /** Tries to open one of the midi output devices.
  42. This will return a MidiOutput object if it manages to open it. You can then
  43. send messages to this device, and delete it when no longer needed.
  44. If the device can't be opened, this will return a null pointer.
  45. @param deviceIndex the index of a device from the list returned by getDevices()
  46. @see getDevices
  47. */
  48. static MidiOutput* openDevice (int deviceIndex);
  49. #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
  50. /** This will try to create a new midi output device (Not available on Windows).
  51. This will attempt to create a new midi output device that other apps can connect
  52. to and use as their midi input.
  53. Returns 0 if a device can't be created.
  54. @param deviceName the name to use for the new device
  55. */
  56. static MidiOutput* createNewDevice (const String& deviceName);
  57. #endif
  58. //==============================================================================
  59. /** Destructor. */
  60. virtual ~MidiOutput();
  61. /** Makes this device output a midi message.
  62. @see MidiMessage
  63. */
  64. virtual void sendMessageNow (const MidiMessage& message);
  65. //==============================================================================
  66. /** This lets you supply a block of messages that will be sent out at some point
  67. in the future.
  68. The MidiOutput class has an internal thread that can send out timestamped
  69. messages - this appends a set of messages to its internal buffer, ready for
  70. sending.
  71. This will only work if you've already started the thread with startBackgroundThread().
  72. A time is supplied, at which the block of messages should be sent. This time uses
  73. the same time base as Time::getMillisecondCounter(), and must be in the future.
  74. The samplesPerSecondForBuffer parameter indicates the number of samples per second
  75. used by the MidiBuffer. Each event in a MidiBuffer has a sample position, and the
  76. samplesPerSecondForBuffer value is needed to convert this sample position to a
  77. real time.
  78. */
  79. virtual void sendBlockOfMessages (const MidiBuffer& buffer,
  80. double millisecondCounterToStartAt,
  81. double samplesPerSecondForBuffer);
  82. /** Gets rid of any midi messages that had been added by sendBlockOfMessages().
  83. */
  84. virtual 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. virtual void startBackgroundThread();
  89. /** Stops the background thread, and clears any pending midi events.
  90. @see startBackgroundThread
  91. */
  92. virtual void stopBackgroundThread();
  93. protected:
  94. //==============================================================================
  95. void* internal;
  96. CriticalSection lock;
  97. struct PendingMessage;
  98. PendingMessage* firstMessage;
  99. MidiOutput();
  100. void run();
  101. private:
  102. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput)
  103. };
  104. #endif // __JUCE_MIDIOUTPUT_JUCEHEADER__