OpenShot Library | libopenshot-audio  0.1.9
juce_MidiOutput.h
1 
2 /** @weakgroup juce_audio_devices-midi_io
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  Controls a physical MIDI output device.
33 
34  To create one of these, use the static getDevices() method to get a list of the
35  available output devices, then use the openDevice() method to try to open one.
36 
37  @see MidiInput
38 
39  @tags{Audio}
40 */
41 class JUCE_API MidiOutput final : private Thread
42 {
43 public:
44  //==============================================================================
45  /** Returns a list of the available midi output devices.
46 
47  You can open one of the devices by passing its index into the
48  openDevice() method.
49 
50  @see getDefaultDeviceIndex, openDevice
51  */
52  static StringArray getDevices();
53 
54  /** Returns the index of the default midi output device to use.
55 
56  This refers to the index in the list returned by getDevices().
57  */
58  static int getDefaultDeviceIndex();
59 
60  /** Tries to open one of the midi output devices.
61 
62  This will return a MidiOutput object if it manages to open it. You can then
63  send messages to this device, and delete it when no longer needed.
64 
65  If the device can't be opened, this will return a null pointer.
66 
67  @param deviceIndex the index of a device from the list returned by getDevices()
68  @see getDevices
69  */
70  static MidiOutput* openDevice (int deviceIndex);
71 
72 
73  #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
74  /** This will try to create a new midi output device (Not available on Windows).
75 
76  This will attempt to create a new midi output device that other apps can connect
77  to and use as their midi input.
78 
79  Returns nullptr if a device can't be created.
80 
81  @param deviceName the name to use for the new device
82  */
83  static MidiOutput* createNewDevice (const String& deviceName);
84  #endif
85 
86  //==============================================================================
87  /** Destructor. */
88  ~MidiOutput() override;
89 
90  /** Returns the name of this device. */
91  const String& getName() const noexcept { return name; }
92 
93  /** Sends out a MIDI message immediately. */
94  void sendMessageNow (const MidiMessage& message);
95 
96  /** Sends out a sequence of MIDI messages immediately. */
97  void sendBlockOfMessagesNow (const MidiBuffer& buffer);
98 
99  //==============================================================================
100  /** This lets you supply a block of messages that will be sent out at some point
101  in the future.
102 
103  The MidiOutput class has an internal thread that can send out timestamped
104  messages - this appends a set of messages to its internal buffer, ready for
105  sending.
106 
107  This will only work if you've already started the thread with startBackgroundThread().
108 
109  A time is specified, at which the block of messages should be sent. This time uses
110  the same time base as Time::getMillisecondCounter(), and must be in the future.
111 
112  The samplesPerSecondForBuffer parameter indicates the number of samples per second
113  used by the MidiBuffer. Each event in a MidiBuffer has a sample position, and the
114  samplesPerSecondForBuffer value is needed to convert this sample position to a
115  real time.
116  */
117  void sendBlockOfMessages (const MidiBuffer& buffer,
118  double millisecondCounterToStartAt,
119  double samplesPerSecondForBuffer);
120 
121  /** Gets rid of any midi messages that had been added by sendBlockOfMessages(). */
122  void clearAllPendingMessages();
123 
124  /** Starts up a background thread so that the device can send blocks of data.
125  Call this to get the device ready, before using sendBlockOfMessages().
126  */
127  void startBackgroundThread();
128 
129  /** Stops the background thread, and clears any pending midi events.
130  @see startBackgroundThread
131  */
132  void stopBackgroundThread();
133 
134 
135 private:
136  //==============================================================================
137  void* internal = nullptr;
138  CriticalSection lock;
139  struct PendingMessage;
140  PendingMessage* firstMessage = nullptr;
141  String name;
142 
143  MidiOutput (const String& midiName); // These objects are created with the openDevice() method.
144  void run() override;
145 
146  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput)
147 };
148 
149 } // namespace juce
150 
151 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
Encapsulates a MIDI message.
A special array for holding a list of strings.
The JUCE String class!
Definition: juce_String.h:42
Encapsulates a thread.
Definition: juce_Thread.h:46
const String & getName() const noexcept
Returns the name of this device.
Holds a sequence of time-stamped midi events.
A re-entrant mutex.
Controls a physical MIDI output device.