OpenShot Audio Library | OpenShotAudio: juce_MidiDevices.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.0

Loading...
Searching...
No Matches
juce_MidiDevices.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25//==============================================================================
36 struct MidiDeviceInfo
37{
38 MidiDeviceInfo() = default;
39
40 MidiDeviceInfo (const String& deviceName, const String& deviceIdentifier)
41 : name (deviceName), identifier (deviceIdentifier)
42 {
43 }
44
54 String name;
55
61 String identifier;
62
63 //==============================================================================
64 bool operator== (const MidiDeviceInfo& other) const noexcept { return name == other.name && identifier == other.identifier; }
65 bool operator!= (const MidiDeviceInfo& other) const noexcept { return ! operator== (other); }
66};
67
68class MidiInputCallback;
69
70//==============================================================================
81 class JUCE_API MidiInput final
82{
83public:
84 //==============================================================================
91 static Array<MidiDeviceInfo> getAvailableDevices();
92
94 static MidiDeviceInfo getDefaultDevice();
95
109 static std::unique_ptr<MidiInput> openDevice (const String& deviceIdentifier, MidiInputCallback* callback);
110
111 #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
125 static std::unique_ptr<MidiInput> createNewDevice (const String& deviceName, MidiInputCallback* callback);
126 #endif
127
128 //==============================================================================
130 ~MidiInput();
131
139 void start();
140
145 void stop();
146
148 MidiDeviceInfo getDeviceInfo() const noexcept { return deviceInfo; }
149
151 String getIdentifier() const noexcept { return deviceInfo.identifier; }
152
154 String getName() const noexcept { return deviceInfo.name; }
155
157 void setName (const String& newName) noexcept { deviceInfo.name = newName; }
158
159 //==============================================================================
161 static StringArray getDevices();
163 static int getDefaultDeviceIndex();
165 static std::unique_ptr<MidiInput> openDevice (int, MidiInputCallback*);
166
167private:
168 //==============================================================================
169 explicit MidiInput (const String&, const String&);
170
171 MidiDeviceInfo deviceInfo;
172 void* internal = nullptr;
173
174 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiInput)
175};
176
177//==============================================================================
188 class JUCE_API MidiInputCallback
189{
190public:
192 virtual ~MidiInputCallback() = default;
193
206 virtual void handleIncomingMidiMessage (MidiInput* source,
207 const MidiMessage& message) = 0;
208
219 virtual void handlePartialSysexMessage (MidiInput* source,
220 const uint8* messageData,
221 int numBytesSoFar,
222 double timestamp)
223 {
224 ignoreUnused (source, messageData, numBytesSoFar, timestamp);
225 }
226};
227
228//==============================================================================
239 class JUCE_API MidiOutput final : private Thread
240{
241public:
242 //==============================================================================
249 static Array<MidiDeviceInfo> getAvailableDevices();
250
252 static MidiDeviceInfo getDefaultDevice();
253
265 static std::unique_ptr<MidiOutput> openDevice (const String& deviceIdentifier);
266
267 #if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
280 static std::unique_ptr<MidiOutput> createNewDevice (const String& deviceName);
281 #endif
282
283 //==============================================================================
285 ~MidiOutput() override;
286
288 MidiDeviceInfo getDeviceInfo() const noexcept { return deviceInfo; }
289
291 String getIdentifier() const noexcept { return deviceInfo.identifier; }
292
294 String getName() const noexcept { return deviceInfo.name; }
295
297 void setName (const String& newName) noexcept { deviceInfo.name = newName; }
298
299 //==============================================================================
301 void sendMessageNow (const MidiMessage& message);
302
304 void sendBlockOfMessagesNow (const MidiBuffer& buffer);
305
323 void sendBlockOfMessages (const MidiBuffer& buffer,
324 double millisecondCounterToStartAt,
325 double samplesPerSecondForBuffer);
326
328 void clearAllPendingMessages();
329
333 void startBackgroundThread();
334
338 void stopBackgroundThread();
339
340 //==============================================================================
342 static StringArray getDevices();
344 static int getDefaultDeviceIndex();
346 static std::unique_ptr<MidiOutput> openDevice (int);
347
348private:
349 //==============================================================================
350 struct PendingMessage
351 {
352 PendingMessage (const void* data, int len, double timeStamp)
353 : message (data, len, timeStamp)
354 {
355 }
356
357 MidiMessage message;
358 PendingMessage* next;
359 };
360
361 //==============================================================================
362 explicit MidiOutput (const String&, const String&);
363 void run() override;
364
365 MidiDeviceInfo deviceInfo;
366 void* internal = nullptr;
367 CriticalSection lock;
368 PendingMessage* firstMessage = nullptr;
369
370 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput)
371};
372
373} // namespace juce
juce::Array
Definition: juce_Array.h:56
juce::MidiBuffer
Definition: juce_MidiBuffer.h:43
juce::MidiInputCallback
Definition: juce_MidiDevices.h:189
juce::MidiInputCallback::~MidiInputCallback
virtual ~MidiInputCallback()=default
juce::MidiInputCallback::handlePartialSysexMessage
virtual void handlePartialSysexMessage(MidiInput *source, const uint8 *messageData, int numBytesSoFar, double timestamp)
Definition: juce_MidiDevices.h:219
juce::MidiInputCallback::handleIncomingMidiMessage
virtual void handleIncomingMidiMessage(MidiInput *source, const MidiMessage &message)=0
juce::MidiInput
Definition: juce_MidiDevices.h:82
juce::MidiInput::setName
void setName(const String &newName) noexcept
Definition: juce_MidiDevices.h:157
juce::MidiInput::getDevices
static StringArray getDevices()
juce::MidiInput::openDevice
static std::unique_ptr< MidiInput > openDevice(int, MidiInputCallback *)
juce::MidiInput::~MidiInput
~MidiInput()
juce::MidiInput::getAvailableDevices
static Array< MidiDeviceInfo > getAvailableDevices()
juce::MidiInput::openDevice
static std::unique_ptr< MidiInput > openDevice(const String &deviceIdentifier, MidiInputCallback *callback)
juce::MidiInput::stop
void stop()
juce::MidiInput::getName
String getName() const noexcept
Definition: juce_MidiDevices.h:154
juce::MidiInput::getDeviceInfo
MidiDeviceInfo getDeviceInfo() const noexcept
Definition: juce_MidiDevices.h:148
juce::MidiInput::getDefaultDevice
static MidiDeviceInfo getDefaultDevice()
juce::MidiInput::getDefaultDeviceIndex
static int getDefaultDeviceIndex()
juce::MidiInput::start
void start()
juce::MidiInput::getIdentifier
String getIdentifier() const noexcept
Definition: juce_MidiDevices.h:151
juce::MidiMessage
Definition: juce_MidiMessage.h:35
juce::MidiOutput
Definition: juce_MidiDevices.h:240
juce::MidiOutput::getDefaultDevice
static MidiDeviceInfo getDefaultDevice()
juce::MidiOutput::getName
String getName() const noexcept
Definition: juce_MidiDevices.h:294
juce::MidiOutput::getDefaultDeviceIndex
static int getDefaultDeviceIndex()
juce::MidiOutput::openDevice
static std::unique_ptr< MidiOutput > openDevice(int)
juce::MidiOutput::setName
void setName(const String &newName) noexcept
Definition: juce_MidiDevices.h:297
juce::MidiOutput::getIdentifier
String getIdentifier() const noexcept
Definition: juce_MidiDevices.h:291
juce::MidiOutput::openDevice
static std::unique_ptr< MidiOutput > openDevice(const String &deviceIdentifier)
juce::MidiOutput::getDeviceInfo
MidiDeviceInfo getDeviceInfo() const noexcept
Definition: juce_MidiDevices.h:288
juce::MidiOutput::sendMessageNow
void sendMessageNow(const MidiMessage &message)
juce::MidiOutput::getDevices
static StringArray getDevices()
juce::MidiOutput::~MidiOutput
~MidiOutput() override
juce::MidiOutput::getAvailableDevices
static Array< MidiDeviceInfo > getAvailableDevices()
juce::StringArray
Definition: juce_StringArray.h:35
juce::String
Definition: juce_String.h:39
juce::Thread
Definition: juce_Thread.h:43
juce::MidiDeviceInfo
Definition: juce_MidiDevices.h:37
juce::MidiDeviceInfo::name
String name
Definition: juce_MidiDevices.h:54
juce::MidiDeviceInfo::identifier
String identifier
Definition: juce_MidiDevices.h:61