OpenShot Library | libopenshot-audio 0.2.0
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
27namespace 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*/
42{
43public:
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 */
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 */
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 */
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,
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
135private:
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/** @}*/
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:60
Holds a sequence of time-stamped midi events.
Encapsulates a MIDI message.
Controls a physical MIDI output device.
const String & getName() const noexcept
Returns the name of this device.
static MidiOutput * openDevice(int deviceIndex)
Tries to open one of the midi output devices.
static int getDefaultDeviceIndex()
Returns the index of the default midi output device to use.
static MidiOutput * createNewDevice(const String &deviceName)
This will try to create a new midi output device (Not available on Windows).
void sendMessageNow(const MidiMessage &message)
Sends out a MIDI message immediately.
static StringArray getDevices()
Returns a list of the available midi output devices.
~MidiOutput() override
Destructor.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:43
Encapsulates a thread.
Definition juce_Thread.h:47
#define JUCE_API
This macro is added to all JUCE public class declarations.