fix macOS build (following Projucer changes made in Windows, which removed /Applications/JUCE/modules from its headers). move JUCE headers under source control, so that Windows and macOS can both build against same version of JUCE. remove AUv3 target (I think it's an iOS thing, so it will never work with this macOS fluidsynth dylib).
This commit is contained in:
180
modules/juce_audio_devices/midi_io/juce_MidiInput.h
Normal file
180
modules/juce_audio_devices/midi_io/juce_MidiInput.h
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
The code included in this file is provided under the terms of the ISC license
|
||||
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
|
||||
To use, copy, modify, and/or distribute this software for any purpose with or
|
||||
without fee is hereby granted provided that the above copyright notice and
|
||||
this permission notice appear in all copies.
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
class MidiInput;
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Receives incoming messages from a physical MIDI input device.
|
||||
|
||||
This class is overridden to handle incoming midi messages. See the MidiInput
|
||||
class for more details.
|
||||
|
||||
@see MidiInput
|
||||
|
||||
@tags{Audio}
|
||||
*/
|
||||
class JUCE_API MidiInputCallback
|
||||
{
|
||||
public:
|
||||
/** Destructor. */
|
||||
virtual ~MidiInputCallback() {}
|
||||
|
||||
|
||||
/** Receives an incoming message.
|
||||
|
||||
A MidiInput object will call this method when a midi event arrives. It'll be
|
||||
called on a high-priority system thread, so avoid doing anything time-consuming
|
||||
in here, and avoid making any UI calls. You might find the MidiBuffer class helpful
|
||||
for queueing incoming messages for use later.
|
||||
|
||||
@param source the MidiInput object that generated the message
|
||||
@param message the incoming message. The message's timestamp is set to a value
|
||||
equivalent to (Time::getMillisecondCounter() / 1000.0) to specify the
|
||||
time when the message arrived.
|
||||
*/
|
||||
virtual void handleIncomingMidiMessage (MidiInput* source,
|
||||
const MidiMessage& message) = 0;
|
||||
|
||||
/** Notification sent each time a packet of a multi-packet sysex message arrives.
|
||||
|
||||
If a long sysex message is broken up into multiple packets, this callback is made
|
||||
for each packet that arrives until the message is finished, at which point
|
||||
the normal handleIncomingMidiMessage() callback will be made with the entire
|
||||
message.
|
||||
|
||||
The message passed in will contain the start of a sysex, but won't be finished
|
||||
with the terminating 0xf7 byte.
|
||||
*/
|
||||
virtual void handlePartialSysexMessage (MidiInput* source,
|
||||
const uint8* messageData,
|
||||
int numBytesSoFar,
|
||||
double timestamp)
|
||||
{
|
||||
ignoreUnused (source, messageData, numBytesSoFar, timestamp);
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Represents a midi input device.
|
||||
|
||||
To create one of these, use the static getDevices() method to find out what inputs are
|
||||
available, and then use the openDevice() method to try to open one.
|
||||
|
||||
@see MidiOutput
|
||||
|
||||
@tags{Audio}
|
||||
*/
|
||||
class JUCE_API MidiInput
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Returns a list of the available midi input devices.
|
||||
|
||||
You can open one of the devices by passing its index into the
|
||||
openDevice() method.
|
||||
|
||||
@see getDefaultDeviceIndex, openDevice
|
||||
*/
|
||||
static StringArray getDevices();
|
||||
|
||||
/** Returns the index of the default midi input device to use.
|
||||
|
||||
This refers to the index in the list returned by getDevices().
|
||||
*/
|
||||
static int getDefaultDeviceIndex();
|
||||
|
||||
/** Tries to open one of the midi input devices.
|
||||
|
||||
This will return a MidiInput object if it manages to open it. You can then
|
||||
call start() and stop() on this device, and delete it when no longer needed.
|
||||
|
||||
If the device can't be opened, this will return a null pointer.
|
||||
|
||||
@param deviceIndex the index of a device from the list returned by getDevices()
|
||||
@param callback the object that will receive the midi messages from this device.
|
||||
|
||||
@see MidiInputCallback, getDevices
|
||||
*/
|
||||
static MidiInput* openDevice (int deviceIndex,
|
||||
MidiInputCallback* callback);
|
||||
|
||||
#if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
|
||||
/** This will try to create a new midi input device (Not available on Windows).
|
||||
|
||||
This will attempt to create a new midi input device with the specified name,
|
||||
for other apps to connect to.
|
||||
|
||||
Returns nullptr if a device can't be created.
|
||||
|
||||
@param deviceName the name to use for the new device
|
||||
@param callback the object that will receive the midi messages from this device.
|
||||
*/
|
||||
static MidiInput* createNewDevice (const String& deviceName,
|
||||
MidiInputCallback* callback);
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
/** Destructor. */
|
||||
~MidiInput();
|
||||
|
||||
/** Returns the name of this device. */
|
||||
const String& getName() const noexcept { return name; }
|
||||
|
||||
/** Allows you to set a custom name for the device, in case you don't like the name
|
||||
it was given when created.
|
||||
*/
|
||||
void setName (const String& newName) noexcept { name = newName; }
|
||||
|
||||
//==============================================================================
|
||||
/** Starts the device running.
|
||||
|
||||
After calling this, the device will start sending midi messages to the
|
||||
MidiInputCallback object that was specified when the openDevice() method
|
||||
was called.
|
||||
|
||||
@see stop
|
||||
*/
|
||||
void start();
|
||||
|
||||
/** Stops the device running.
|
||||
@see start
|
||||
*/
|
||||
void stop();
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
String name;
|
||||
void* internal = nullptr;
|
||||
|
||||
// The input objects are created with the openDevice() method.
|
||||
explicit MidiInput (const String&);
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiInput)
|
||||
};
|
||||
|
||||
} // namespace juce
|
158
modules/juce_audio_devices/midi_io/juce_MidiMessageCollector.cpp
Normal file
158
modules/juce_audio_devices/midi_io/juce_MidiMessageCollector.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
The code included in this file is provided under the terms of the ISC license
|
||||
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
|
||||
To use, copy, modify, and/or distribute this software for any purpose with or
|
||||
without fee is hereby granted provided that the above copyright notice and
|
||||
this permission notice appear in all copies.
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
MidiMessageCollector::MidiMessageCollector()
|
||||
{
|
||||
}
|
||||
|
||||
MidiMessageCollector::~MidiMessageCollector()
|
||||
{
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void MidiMessageCollector::reset (const double newSampleRate)
|
||||
{
|
||||
jassert (newSampleRate > 0);
|
||||
|
||||
const ScopedLock sl (midiCallbackLock);
|
||||
#if JUCE_DEBUG
|
||||
hasCalledReset = true;
|
||||
#endif
|
||||
sampleRate = newSampleRate;
|
||||
incomingMessages.clear();
|
||||
lastCallbackTime = Time::getMillisecondCounterHiRes();
|
||||
}
|
||||
|
||||
void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
|
||||
{
|
||||
#if JUCE_DEBUG
|
||||
jassert (hasCalledReset); // you need to call reset() to set the correct sample rate before using this object
|
||||
#endif
|
||||
|
||||
// the messages that come in here need to be time-stamped correctly - see MidiInput
|
||||
// for details of what the number should be.
|
||||
jassert (message.getTimeStamp() != 0);
|
||||
|
||||
const ScopedLock sl (midiCallbackLock);
|
||||
|
||||
auto sampleNumber = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
|
||||
|
||||
incomingMessages.addEvent (message, sampleNumber);
|
||||
|
||||
// if the messages don't get used for over a second, we'd better
|
||||
// get rid of any old ones to avoid the queue getting too big
|
||||
if (sampleNumber > sampleRate)
|
||||
incomingMessages.clear (0, sampleNumber - (int) sampleRate);
|
||||
}
|
||||
|
||||
void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
|
||||
const int numSamples)
|
||||
{
|
||||
#if JUCE_DEBUG
|
||||
jassert (hasCalledReset); // you need to call reset() to set the correct sample rate before using this object
|
||||
#endif
|
||||
|
||||
jassert (numSamples > 0);
|
||||
|
||||
auto timeNow = Time::getMillisecondCounterHiRes();
|
||||
auto msElapsed = timeNow - lastCallbackTime;
|
||||
|
||||
const ScopedLock sl (midiCallbackLock);
|
||||
lastCallbackTime = timeNow;
|
||||
|
||||
if (! incomingMessages.isEmpty())
|
||||
{
|
||||
int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
|
||||
int startSample = 0;
|
||||
int scale = 1 << 16;
|
||||
|
||||
const uint8* midiData;
|
||||
int numBytes, samplePosition;
|
||||
|
||||
MidiBuffer::Iterator iter (incomingMessages);
|
||||
|
||||
if (numSourceSamples > numSamples)
|
||||
{
|
||||
// if our list of events is longer than the buffer we're being
|
||||
// asked for, scale them down to squeeze them all in..
|
||||
const int maxBlockLengthToUse = numSamples << 5;
|
||||
|
||||
if (numSourceSamples > maxBlockLengthToUse)
|
||||
{
|
||||
startSample = numSourceSamples - maxBlockLengthToUse;
|
||||
numSourceSamples = maxBlockLengthToUse;
|
||||
iter.setNextSamplePosition (startSample);
|
||||
}
|
||||
|
||||
scale = (numSamples << 10) / numSourceSamples;
|
||||
|
||||
while (iter.getNextEvent (midiData, numBytes, samplePosition))
|
||||
{
|
||||
samplePosition = ((samplePosition - startSample) * scale) >> 10;
|
||||
|
||||
destBuffer.addEvent (midiData, numBytes,
|
||||
jlimit (0, numSamples - 1, samplePosition));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if our event list is shorter than the number we need, put them
|
||||
// towards the end of the buffer
|
||||
startSample = numSamples - numSourceSamples;
|
||||
|
||||
while (iter.getNextEvent (midiData, numBytes, samplePosition))
|
||||
{
|
||||
destBuffer.addEvent (midiData, numBytes,
|
||||
jlimit (0, numSamples - 1, samplePosition + startSample));
|
||||
}
|
||||
}
|
||||
|
||||
incomingMessages.clear();
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
|
||||
{
|
||||
MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
|
||||
m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
|
||||
|
||||
addMessageToQueue (m);
|
||||
}
|
||||
|
||||
void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
|
||||
{
|
||||
MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber, velocity));
|
||||
m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
|
||||
|
||||
addMessageToQueue (m);
|
||||
}
|
||||
|
||||
void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
|
||||
{
|
||||
addMessageToQueue (message);
|
||||
}
|
||||
|
||||
} // namespace juce
|
105
modules/juce_audio_devices/midi_io/juce_MidiMessageCollector.h
Normal file
105
modules/juce_audio_devices/midi_io/juce_MidiMessageCollector.h
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
The code included in this file is provided under the terms of the ISC license
|
||||
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
|
||||
To use, copy, modify, and/or distribute this software for any purpose with or
|
||||
without fee is hereby granted provided that the above copyright notice and
|
||||
this permission notice appear in all copies.
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Collects incoming realtime MIDI messages and turns them into blocks suitable for
|
||||
processing by a block-based audio callback.
|
||||
|
||||
The class can also be used as either a MidiKeyboardStateListener or a MidiInputCallback
|
||||
so it can easily use a midi input or keyboard component as its source.
|
||||
|
||||
@see MidiMessage, MidiInput
|
||||
|
||||
@tags{Audio}
|
||||
*/
|
||||
class JUCE_API MidiMessageCollector : public MidiKeyboardStateListener,
|
||||
public MidiInputCallback
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Creates a MidiMessageCollector. */
|
||||
MidiMessageCollector();
|
||||
|
||||
/** Destructor. */
|
||||
~MidiMessageCollector();
|
||||
|
||||
//==============================================================================
|
||||
/** Clears any messages from the queue.
|
||||
|
||||
You need to call this method before starting to use the collector, so that
|
||||
it knows the correct sample rate to use.
|
||||
*/
|
||||
void reset (double sampleRate);
|
||||
|
||||
/** Takes an incoming real-time message and adds it to the queue.
|
||||
|
||||
The message's timestamp is taken, and it will be ready for retrieval as part
|
||||
of the block returned by the next call to removeNextBlockOfMessages().
|
||||
|
||||
This method is fully thread-safe when overlapping calls are made with
|
||||
removeNextBlockOfMessages().
|
||||
*/
|
||||
void addMessageToQueue (const MidiMessage& message);
|
||||
|
||||
/** Removes all the pending messages from the queue as a buffer.
|
||||
|
||||
This will also correct the messages' timestamps to make sure they're in
|
||||
the range 0 to numSamples - 1.
|
||||
|
||||
This call should be made regularly by something like an audio processing
|
||||
callback, because the time that it happens is used in calculating the
|
||||
midi event positions.
|
||||
|
||||
This method is fully thread-safe when overlapping calls are made with
|
||||
addMessageToQueue().
|
||||
|
||||
Precondition: numSamples must be greater than 0.
|
||||
*/
|
||||
void removeNextBlockOfMessages (MidiBuffer& destBuffer, int numSamples);
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/** @internal */
|
||||
void handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override;
|
||||
/** @internal */
|
||||
void handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override;
|
||||
/** @internal */
|
||||
void handleIncomingMidiMessage (MidiInput*, const MidiMessage&) override;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
double lastCallbackTime = 0;
|
||||
CriticalSection midiCallbackLock;
|
||||
MidiBuffer incomingMessages;
|
||||
double sampleRate = 44100.0;
|
||||
#if JUCE_DEBUG
|
||||
bool hasCalledReset = false;
|
||||
#endif
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiMessageCollector)
|
||||
};
|
||||
|
||||
} // namespace juce
|
170
modules/juce_audio_devices/midi_io/juce_MidiOutput.cpp
Normal file
170
modules/juce_audio_devices/midi_io/juce_MidiOutput.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
The code included in this file is provided under the terms of the ISC license
|
||||
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
|
||||
To use, copy, modify, and/or distribute this software for any purpose with or
|
||||
without fee is hereby granted provided that the above copyright notice and
|
||||
this permission notice appear in all copies.
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
struct MidiOutput::PendingMessage
|
||||
{
|
||||
PendingMessage (const void* data, int len, double timeStamp)
|
||||
: message (data, len, timeStamp)
|
||||
{}
|
||||
|
||||
MidiMessage message;
|
||||
PendingMessage* next;
|
||||
};
|
||||
|
||||
MidiOutput::MidiOutput (const String& deviceName)
|
||||
: Thread ("midi out"), name (deviceName)
|
||||
{
|
||||
}
|
||||
|
||||
void MidiOutput::sendBlockOfMessagesNow (const MidiBuffer& buffer)
|
||||
{
|
||||
MidiBuffer::Iterator i (buffer);
|
||||
MidiMessage message;
|
||||
int samplePosition; // Note: not actually used, so no need to initialise.
|
||||
|
||||
while (i.getNextEvent (message, samplePosition))
|
||||
sendMessageNow (message);
|
||||
}
|
||||
|
||||
void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
|
||||
double millisecondCounterToStartAt,
|
||||
double samplesPerSecondForBuffer)
|
||||
{
|
||||
// You've got to call startBackgroundThread() for this to actually work..
|
||||
jassert (isThreadRunning());
|
||||
|
||||
// this needs to be a value in the future - RTFM for this method!
|
||||
jassert (millisecondCounterToStartAt > 0);
|
||||
|
||||
auto timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
|
||||
|
||||
const uint8* data;
|
||||
int len, time;
|
||||
|
||||
for (MidiBuffer::Iterator i (buffer); i.getNextEvent (data, len, time);)
|
||||
{
|
||||
auto eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
|
||||
auto* m = new PendingMessage (data, len, eventTime);
|
||||
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
if (firstMessage == nullptr || firstMessage->message.getTimeStamp() > eventTime)
|
||||
{
|
||||
m->next = firstMessage;
|
||||
firstMessage = m;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto* mm = firstMessage;
|
||||
|
||||
while (mm->next != nullptr && mm->next->message.getTimeStamp() <= eventTime)
|
||||
mm = mm->next;
|
||||
|
||||
m->next = mm->next;
|
||||
mm->next = m;
|
||||
}
|
||||
}
|
||||
|
||||
notify();
|
||||
}
|
||||
|
||||
void MidiOutput::clearAllPendingMessages()
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
while (firstMessage != nullptr)
|
||||
{
|
||||
auto* m = firstMessage;
|
||||
firstMessage = firstMessage->next;
|
||||
delete m;
|
||||
}
|
||||
}
|
||||
|
||||
void MidiOutput::startBackgroundThread()
|
||||
{
|
||||
startThread (9);
|
||||
}
|
||||
|
||||
void MidiOutput::stopBackgroundThread()
|
||||
{
|
||||
stopThread (5000);
|
||||
}
|
||||
|
||||
void MidiOutput::run()
|
||||
{
|
||||
while (! threadShouldExit())
|
||||
{
|
||||
uint32 now = Time::getMillisecondCounter();
|
||||
uint32 eventTime = 0;
|
||||
uint32 timeToWait = 500;
|
||||
|
||||
PendingMessage* message;
|
||||
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
message = firstMessage;
|
||||
|
||||
if (message != nullptr)
|
||||
{
|
||||
eventTime = (uint32) roundToInt (message->message.getTimeStamp());
|
||||
|
||||
if (eventTime > now + 20)
|
||||
{
|
||||
timeToWait = eventTime - (now + 20);
|
||||
message = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstMessage = message->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (message != nullptr)
|
||||
{
|
||||
std::unique_ptr<PendingMessage> messageDeleter (message);
|
||||
|
||||
if (eventTime > now)
|
||||
{
|
||||
Time::waitForMillisecondCounter (eventTime);
|
||||
|
||||
if (threadShouldExit())
|
||||
break;
|
||||
}
|
||||
|
||||
if (eventTime > now - 200)
|
||||
sendMessageNow (message->message);
|
||||
}
|
||||
else
|
||||
{
|
||||
jassert (timeToWait < 1000 * 30);
|
||||
wait ((int) timeToWait);
|
||||
}
|
||||
}
|
||||
|
||||
clearAllPendingMessages();
|
||||
}
|
||||
|
||||
} // namespace juce
|
145
modules/juce_audio_devices/midi_io/juce_MidiOutput.h
Normal file
145
modules/juce_audio_devices/midi_io/juce_MidiOutput.h
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
The code included in this file is provided under the terms of the ISC license
|
||||
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
|
||||
To use, copy, modify, and/or distribute this software for any purpose with or
|
||||
without fee is hereby granted provided that the above copyright notice and
|
||||
this permission notice appear in all copies.
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Controls a physical MIDI output device.
|
||||
|
||||
To create one of these, use the static getDevices() method to get a list of the
|
||||
available output devices, then use the openDevice() method to try to open one.
|
||||
|
||||
@see MidiInput
|
||||
|
||||
@tags{Audio}
|
||||
*/
|
||||
class JUCE_API MidiOutput : private Thread
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Returns a list of the available midi output devices.
|
||||
|
||||
You can open one of the devices by passing its index into the
|
||||
openDevice() method.
|
||||
|
||||
@see getDefaultDeviceIndex, openDevice
|
||||
*/
|
||||
static StringArray getDevices();
|
||||
|
||||
/** Returns the index of the default midi output device to use.
|
||||
|
||||
This refers to the index in the list returned by getDevices().
|
||||
*/
|
||||
static int getDefaultDeviceIndex();
|
||||
|
||||
/** Tries to open one of the midi output devices.
|
||||
|
||||
This will return a MidiOutput object if it manages to open it. You can then
|
||||
send messages to this device, and delete it when no longer needed.
|
||||
|
||||
If the device can't be opened, this will return a null pointer.
|
||||
|
||||
@param deviceIndex the index of a device from the list returned by getDevices()
|
||||
@see getDevices
|
||||
*/
|
||||
static MidiOutput* openDevice (int deviceIndex);
|
||||
|
||||
|
||||
#if JUCE_LINUX || JUCE_MAC || JUCE_IOS || DOXYGEN
|
||||
/** This will try to create a new midi output device (Not available on Windows).
|
||||
|
||||
This will attempt to create a new midi output device that other apps can connect
|
||||
to and use as their midi input.
|
||||
|
||||
Returns nullptr if a device can't be created.
|
||||
|
||||
@param deviceName the name to use for the new device
|
||||
*/
|
||||
static MidiOutput* createNewDevice (const String& deviceName);
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
/** Destructor. */
|
||||
~MidiOutput();
|
||||
|
||||
/** Returns the name of this device. */
|
||||
const String& getName() const noexcept { return name; }
|
||||
|
||||
/** Sends out a MIDI message immediately. */
|
||||
void sendMessageNow (const MidiMessage& message);
|
||||
|
||||
/** Sends out a sequence of MIDI messages immediately. */
|
||||
void sendBlockOfMessagesNow (const MidiBuffer& buffer);
|
||||
|
||||
//==============================================================================
|
||||
/** This lets you supply a block of messages that will be sent out at some point
|
||||
in the future.
|
||||
|
||||
The MidiOutput class has an internal thread that can send out timestamped
|
||||
messages - this appends a set of messages to its internal buffer, ready for
|
||||
sending.
|
||||
|
||||
This will only work if you've already started the thread with startBackgroundThread().
|
||||
|
||||
A time is specified, at which the block of messages should be sent. This time uses
|
||||
the same time base as Time::getMillisecondCounter(), and must be in the future.
|
||||
|
||||
The samplesPerSecondForBuffer parameter indicates the number of samples per second
|
||||
used by the MidiBuffer. Each event in a MidiBuffer has a sample position, and the
|
||||
samplesPerSecondForBuffer value is needed to convert this sample position to a
|
||||
real time.
|
||||
*/
|
||||
void sendBlockOfMessages (const MidiBuffer& buffer,
|
||||
double millisecondCounterToStartAt,
|
||||
double samplesPerSecondForBuffer);
|
||||
|
||||
/** Gets rid of any midi messages that had been added by sendBlockOfMessages(). */
|
||||
void clearAllPendingMessages();
|
||||
|
||||
/** Starts up a background thread so that the device can send blocks of data.
|
||||
Call this to get the device ready, before using sendBlockOfMessages().
|
||||
*/
|
||||
void startBackgroundThread();
|
||||
|
||||
/** Stops the background thread, and clears any pending midi events.
|
||||
@see startBackgroundThread
|
||||
*/
|
||||
void stopBackgroundThread();
|
||||
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
void* internal = nullptr;
|
||||
CriticalSection lock;
|
||||
struct PendingMessage;
|
||||
PendingMessage* firstMessage = nullptr;
|
||||
String name;
|
||||
|
||||
MidiOutput (const String& midiName); // These objects are created with the openDevice() method.
|
||||
void run() override;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput)
|
||||
};
|
||||
|
||||
} // namespace juce
|
Reference in New Issue
Block a user