JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_MidiDevices.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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
26class MidiDeviceListConnectionBroadcaster;
27
50{
51public:
52 using Key = uint64_t;
53
57
60 : broadcaster (std::exchange (other.broadcaster, nullptr)),
61 key (std::exchange (other.key, Key{}))
62 {
63 }
64
65 MidiDeviceListConnection& operator= (const MidiDeviceListConnection&) = delete;
67 {
68 MidiDeviceListConnection (std::move (other)).swap (*this);
69 return *this;
70 }
71
72 ~MidiDeviceListConnection() noexcept;
73
79 void reset() noexcept
80 {
81 MidiDeviceListConnection().swap (*this);
82 }
83
91
92private:
94 : broadcaster (b), key (k) {}
95
96 void swap (MidiDeviceListConnection& other) noexcept
97 {
98 std::swap (other.broadcaster, broadcaster);
99 std::swap (other.key, key);
100 }
101
102 MidiDeviceListConnectionBroadcaster* broadcaster = nullptr;
103 Key key = {};
104};
105
106//==============================================================================
118{
119 MidiDeviceInfo() = default;
120
121 MidiDeviceInfo (const String& deviceName, const String& deviceIdentifier)
122 : name (deviceName), identifier (deviceIdentifier)
123 {
124 }
125
136
143
144 //==============================================================================
145 auto tie() const { return std::tie (name, identifier); }
146 bool operator== (const MidiDeviceInfo& other) const noexcept { return tie() == other.tie(); }
147 bool operator!= (const MidiDeviceInfo& other) const noexcept { return tie() != other.tie(); }
148};
149
150class MidiInputCallback;
151
152//==============================================================================
163class JUCE_API MidiInput final
164{
165public:
166 //==============================================================================
173 static Array<MidiDeviceInfo> getAvailableDevices();
174
176 static MidiDeviceInfo getDefaultDevice();
177
191 static std::unique_ptr<MidiInput> openDevice (const String& deviceIdentifier, MidiInputCallback* callback);
192
193 #if JUCE_LINUX || JUCE_BSD || JUCE_MAC || JUCE_IOS || DOXYGEN
207 static std::unique_ptr<MidiInput> createNewDevice (const String& deviceName, MidiInputCallback* callback);
208 #endif
209
210 //==============================================================================
212 ~MidiInput();
213
221 void start();
222
227 void stop();
228
230 MidiDeviceInfo getDeviceInfo() const noexcept { return deviceInfo; }
231
233 String getIdentifier() const noexcept { return deviceInfo.identifier; }
234
236 String getName() const noexcept { return deviceInfo.name; }
237
239 void setName (const String& newName) noexcept { deviceInfo.name = newName; }
240
241 //==============================================================================
242 #ifndef DOXYGEN
243 [[deprecated ("Use getAvailableDevices instead.")]]
244 static StringArray getDevices();
245 [[deprecated ("Use getDefaultDevice instead.")]]
246 static int getDefaultDeviceIndex();
247 [[deprecated ("Use openDevice that takes a device identifier instead.")]]
248 static std::unique_ptr<MidiInput> openDevice (int, MidiInputCallback*);
249 #endif
250
252 class Pimpl;
253
254private:
255 //==============================================================================
256 explicit MidiInput (const String&, const String&);
257
258 MidiDeviceInfo deviceInfo;
259
260 std::unique_ptr<Pimpl> internal;
261
263};
264
265//==============================================================================
276class JUCE_API MidiInputCallback
277{
278public:
280 virtual ~MidiInputCallback() = default;
281
295 const MidiMessage& message) = 0;
296
307 virtual void handlePartialSysexMessage (MidiInput* source,
308 const uint8* messageData,
309 int numBytesSoFar,
310 double timestamp);
311};
312
313//==============================================================================
324class JUCE_API MidiOutput final : private Thread
325{
326public:
327 //==============================================================================
334 static Array<MidiDeviceInfo> getAvailableDevices();
335
337 static MidiDeviceInfo getDefaultDevice();
338
350 static std::unique_ptr<MidiOutput> openDevice (const String& deviceIdentifier);
351
352 #if JUCE_LINUX || JUCE_BSD || JUCE_MAC || JUCE_IOS || DOXYGEN
365 static std::unique_ptr<MidiOutput> createNewDevice (const String& deviceName);
366 #endif
367
368 //==============================================================================
370 ~MidiOutput() override;
371
373 MidiDeviceInfo getDeviceInfo() const noexcept { return deviceInfo; }
374
376 String getIdentifier() const noexcept { return deviceInfo.identifier; }
377
379 String getName() const noexcept { return deviceInfo.name; }
380
382 void setName (const String& newName) noexcept { deviceInfo.name = newName; }
383
384 //==============================================================================
386 void sendMessageNow (const MidiMessage& message);
387
389 void sendBlockOfMessagesNow (const MidiBuffer& buffer);
390
408 void sendBlockOfMessages (const MidiBuffer& buffer,
409 double millisecondCounterToStartAt,
410 double samplesPerSecondForBuffer);
411
413 void clearAllPendingMessages();
414
418 void startBackgroundThread();
419
423 void stopBackgroundThread();
424
428 bool isBackgroundThreadRunning() const noexcept { return isThreadRunning(); }
429
430 //==============================================================================
431 #ifndef DOXYGEN
432 [[deprecated ("Use getAvailableDevices instead.")]]
433 static StringArray getDevices();
434 [[deprecated ("Use getDefaultDevice instead.")]]
435 static int getDefaultDeviceIndex();
436 [[deprecated ("Use openDevice that takes a device identifier instead.")]]
437 static std::unique_ptr<MidiOutput> openDevice (int);
438 #endif
439
441 class Pimpl;
442
443private:
444 //==============================================================================
445 struct PendingMessage
446 {
447 PendingMessage (const void* data, int len, double timeStamp)
448 : message (data, len, timeStamp)
449 {
450 }
451
452 MidiMessage message;
453 PendingMessage* next;
454 };
455
456 //==============================================================================
457 explicit MidiOutput (const String&, const String&);
458 void run() override;
459
460 MidiDeviceInfo deviceInfo;
461
463
464 CriticalSection lock;
465 PendingMessage* firstMessage = nullptr;
466
468};
469
470} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
Holds a sequence of time-stamped midi events.
To find out when the available MIDI devices change, call MidiDeviceListConnection::make(),...
static MidiDeviceListConnection make(std::function< void()>)
Registers a function to be called whenever the midi device list changes.
MidiDeviceListConnection()=default
Constructs an inactive connection.
void reset() noexcept
Clears this connection.
Receives incoming messages from a physical MIDI input device.
virtual ~MidiInputCallback()=default
Destructor.
virtual void handleIncomingMidiMessage(MidiInput *source, const MidiMessage &message)=0
Receives an incoming message.
Represents a midi input device.
void setName(const String &newName) noexcept
Sets a custom name for the device.
String getName() const noexcept
Returns the name of this device.
MidiDeviceInfo getDeviceInfo() const noexcept
Returns the MidiDeviceInfo struct containing some information about this device.
String getIdentifier() const noexcept
Returns the identifier of this device.
Encapsulates a MIDI message.
Represents a midi output device.
String getName() const noexcept
Returns the name of this device.
void setName(const String &newName) noexcept
Sets a custom name for the device.
String getIdentifier() const noexcept
Returns the identifier of this device.
MidiDeviceInfo getDeviceInfo() const noexcept
Returns the MidiDeviceInfo struct containing some information about this device.
bool isBackgroundThreadRunning() const noexcept
Returns true if the background thread used to send blocks of data is running.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
Encapsulates a thread.
Definition juce_Thread.h:43
T exchange(T... args)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
T internal(T... args)
T lock(T... args)
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
typedef uint64_t
This struct contains information about a MIDI input or output device.
String name
The name of this device.
String identifier
The identifier for this device.
T swap(T... args)
T tie(T... args)