OpenShot Library | libopenshot-audio 0.2.0
juce_MidiInput.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
30class MidiInput;
31
32
33//==============================================================================
34/**
35 Receives incoming messages from a physical MIDI input device.
36
37 This class is overridden to handle incoming midi messages. See the MidiInput
38 class for more details.
39
40 @see MidiInput
41
42 @tags{Audio}
43*/
45{
46public:
47 /** Destructor. */
48 virtual ~MidiInputCallback() = default;
49
50
51 /** Receives an incoming message.
52
53 A MidiInput object will call this method when a midi event arrives. It'll be
54 called on a high-priority system thread, so avoid doing anything time-consuming
55 in here, and avoid making any UI calls. You might find the MidiBuffer class helpful
56 for queueing incoming messages for use later.
57
58 @param source the MidiInput object that generated the message
59 @param message the incoming message. The message's timestamp is set to a value
60 equivalent to (Time::getMillisecondCounter() / 1000.0) to specify the
61 time when the message arrived.
62 */
63 virtual void handleIncomingMidiMessage (MidiInput* source,
64 const MidiMessage& message) = 0;
65
66 /** Notification sent each time a packet of a multi-packet sysex message arrives.
67
68 If a long sysex message is broken up into multiple packets, this callback is made
69 for each packet that arrives until the message is finished, at which point
70 the normal handleIncomingMidiMessage() callback will be made with the entire
71 message.
72
73 The message passed in will contain the start of a sysex, but won't be finished
74 with the terminating 0xf7 byte.
75 */
76 virtual void handlePartialSysexMessage (MidiInput* source,
77 const uint8* messageData,
78 int numBytesSoFar,
79 double timestamp)
80 {
81 ignoreUnused (source, messageData, numBytesSoFar, timestamp);
82 }
83};
84
85//==============================================================================
86/**
87 Represents a midi input device.
88
89 To create one of these, use the static getDevices() method to find out what inputs are
90 available, and then use the openDevice() method to try to open one.
91
92 @see MidiOutput
93
94 @tags{Audio}
95*/
97{
98public:
99 //==============================================================================
100 /** Returns a list of the available midi input devices.
101
102 You can open one of the devices by passing its index into the
103 openDevice() method.
104
105 @see getDefaultDeviceIndex, openDevice
106 */
108
109 /** Returns the index of the default midi input device to use.
110
111 This refers to the index in the list returned by getDevices().
112 */
114
115 /** Tries to open one of the midi input devices.
116
117 This will return a MidiInput object if it manages to open it. You can then
118 call start() and stop() on this device, and delete it when no longer needed.
119
120 If the device can't be opened, this will return a null pointer.
121
122 @param deviceIndex the index of a device from the list returned by getDevices()
123 @param callback the object that will receive the midi messages from this device.
124
125 @see MidiInputCallback, getDevices
126 */
127 static MidiInput* openDevice (int deviceIndex,
128 MidiInputCallback* callback);
129
130 #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
131 /** This will try to create a new midi input device (Not available on Windows).
132
133 This will attempt to create a new midi input device with the specified name,
134 for other apps to connect to.
135
136 Returns nullptr if a device can't be created.
137
138 @param deviceName the name to use for the new device
139 @param callback the object that will receive the midi messages from this device.
140 */
141 static MidiInput* createNewDevice (const String& deviceName,
142 MidiInputCallback* callback);
143 #endif
144
145 //==============================================================================
146 /** Destructor. */
148
149 /** Returns the name of this device. */
150 const String& getName() const noexcept { return name; }
151
152 /** Allows you to set a custom name for the device, in case you don't like the name
153 it was given when created.
154 */
155 void setName (const String& newName) noexcept { name = newName; }
156
157 //==============================================================================
158 /** Starts the device running.
159
160 After calling this, the device will start sending midi messages to the
161 MidiInputCallback object that was specified when the openDevice() method
162 was called.
163
164 @see stop
165 */
166 void start();
167
168 /** Stops the device running.
169 @see start
170 */
171 void stop();
172
173private:
174 //==============================================================================
175 String name;
176 void* internal = nullptr;
177
178 // The input objects are created with the openDevice() method.
179 explicit MidiInput (const String&);
180
181 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiInput)
182};
183
184} // namespace juce
185
186/** @}*/
Receives incoming messages from a physical MIDI input device.
virtual ~MidiInputCallback()=default
Destructor.
virtual void handlePartialSysexMessage(MidiInput *source, const uint8 *messageData, int numBytesSoFar, double timestamp)
Notification sent each time a packet of a multi-packet sysex message arrives.
virtual void handleIncomingMidiMessage(MidiInput *source, const MidiMessage &message)=0
Receives an incoming message.
Represents a midi input device.
void setName(const String &newName) noexcept
Allows you to set a custom name for the device, in case you don't like the name it was given when cre...
static StringArray getDevices()
Returns a list of the available midi input devices.
static MidiInput * openDevice(int deviceIndex, MidiInputCallback *callback)
Tries to open one of the midi input devices.
~MidiInput()
Destructor.
void stop()
Stops the device running.
const String & getName() const noexcept
Returns the name of this device.
static MidiInput * createNewDevice(const String &deviceName, MidiInputCallback *callback)
This will try to create a new midi input device (Not available on Windows).
static int getDefaultDeviceIndex()
Returns the index of the default midi input device to use.
void start()
Starts the device running.
Encapsulates a MIDI message.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:43
#define JUCE_API
This macro is added to all JUCE public class declarations.