- initial version
git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@14 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef JUCE_MIDIINPUT_H_INCLUDED
|
||||
#define JUCE_MIDIINPUT_H_INCLUDED
|
||||
|
||||
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
|
||||
*/
|
||||
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)
|
||||
{
|
||||
// (this bit is just to avoid compiler warnings about unused variables)
|
||||
(void) source; (void) messageData; (void) numBytesSoFar; (void) 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
|
||||
*/
|
||||
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. */
|
||||
virtual ~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
|
||||
*/
|
||||
virtual void start();
|
||||
|
||||
/** Stops the device running.
|
||||
|
||||
@see start
|
||||
*/
|
||||
virtual void stop();
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
String name;
|
||||
void* internal;
|
||||
|
||||
explicit MidiInput (const String& name);
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiInput)
|
||||
};
|
||||
|
||||
|
||||
#endif // JUCE_MIDIINPUT_H_INCLUDED
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
MidiMessageCollector::MidiMessageCollector()
|
||||
: lastCallbackTime (0),
|
||||
sampleRate (44100.0001)
|
||||
{
|
||||
}
|
||||
|
||||
MidiMessageCollector::~MidiMessageCollector()
|
||||
{
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void MidiMessageCollector::reset (const double sampleRate_)
|
||||
{
|
||||
jassert (sampleRate_ > 0);
|
||||
|
||||
const ScopedLock sl (midiCallbackLock);
|
||||
sampleRate = sampleRate_;
|
||||
incomingMessages.clear();
|
||||
lastCallbackTime = Time::getMillisecondCounterHiRes();
|
||||
}
|
||||
|
||||
void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
|
||||
{
|
||||
// you need to call reset() to set the correct sample rate before using this object
|
||||
jassert (sampleRate != 44100.0001);
|
||||
|
||||
// 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);
|
||||
|
||||
const int 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)
|
||||
{
|
||||
// you need to call reset() to set the correct sample rate before using this object
|
||||
jassert (sampleRate != 44100.0001);
|
||||
jassert (numSamples > 0);
|
||||
|
||||
const double timeNow = Time::getMillisecondCounterHiRes();
|
||||
const double 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)
|
||||
{
|
||||
MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
|
||||
m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
|
||||
|
||||
addMessageToQueue (m);
|
||||
}
|
||||
|
||||
void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
|
||||
{
|
||||
addMessageToQueue (message);
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef JUCE_MIDIMESSAGECOLLECTOR_H_INCLUDED
|
||||
#define JUCE_MIDIMESSAGECOLLECTOR_H_INCLUDED
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
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
|
||||
*/
|
||||
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) override;
|
||||
/** @internal */
|
||||
void handleIncomingMidiMessage (MidiInput*, const MidiMessage&) override;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
double lastCallbackTime;
|
||||
CriticalSection midiCallbackLock;
|
||||
MidiBuffer incomingMessages;
|
||||
double sampleRate;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiMessageCollector)
|
||||
};
|
||||
|
||||
|
||||
#endif // JUCE_MIDIMESSAGECOLLECTOR_H_INCLUDED
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
struct MidiOutput::PendingMessage
|
||||
{
|
||||
PendingMessage (const void* const data, const int len, const double timeStamp)
|
||||
: message (data, len, timeStamp)
|
||||
{}
|
||||
|
||||
MidiMessage message;
|
||||
PendingMessage* next;
|
||||
};
|
||||
|
||||
MidiOutput::MidiOutput()
|
||||
: Thread ("midi out"),
|
||||
internal (nullptr),
|
||||
firstMessage (nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
|
||||
const 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);
|
||||
|
||||
const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
|
||||
|
||||
MidiBuffer::Iterator i (buffer);
|
||||
|
||||
const uint8* data;
|
||||
int len, time;
|
||||
|
||||
while (i.getNextEvent (data, len, time))
|
||||
{
|
||||
const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
|
||||
|
||||
PendingMessage* const m = new PendingMessage (data, len, eventTime);
|
||||
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
if (firstMessage == nullptr || firstMessage->message.getTimeStamp() > eventTime)
|
||||
{
|
||||
m->next = firstMessage;
|
||||
firstMessage = m;
|
||||
}
|
||||
else
|
||||
{
|
||||
PendingMessage* 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)
|
||||
{
|
||||
PendingMessage* const 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)
|
||||
{
|
||||
const ScopedPointer<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();
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
|
||||
Permission is granted to use this software under the terms of either:
|
||||
a) the GPL v2 (or any later version)
|
||||
b) the Affero GPL v3
|
||||
|
||||
Details of these licenses can be found at: www.gnu.org/licenses
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.juce.com for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef JUCE_MIDIOUTPUT_H_INCLUDED
|
||||
#define JUCE_MIDIOUTPUT_H_INCLUDED
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
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
|
||||
*/
|
||||
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. */
|
||||
virtual ~MidiOutput();
|
||||
|
||||
/** Makes this device output a midi message.
|
||||
|
||||
@see MidiMessage
|
||||
*/
|
||||
virtual void sendMessageNow (const MidiMessage& message);
|
||||
|
||||
//==============================================================================
|
||||
/** 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 supplied, 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.
|
||||
*/
|
||||
virtual void sendBlockOfMessages (const MidiBuffer& buffer,
|
||||
double millisecondCounterToStartAt,
|
||||
double samplesPerSecondForBuffer);
|
||||
|
||||
/** Gets rid of any midi messages that had been added by sendBlockOfMessages().
|
||||
*/
|
||||
virtual 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().
|
||||
*/
|
||||
virtual void startBackgroundThread();
|
||||
|
||||
/** Stops the background thread, and clears any pending midi events.
|
||||
|
||||
@see startBackgroundThread
|
||||
*/
|
||||
virtual void stopBackgroundThread();
|
||||
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
void* internal;
|
||||
CriticalSection lock;
|
||||
struct PendingMessage;
|
||||
PendingMessage* firstMessage;
|
||||
|
||||
MidiOutput();
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput)
|
||||
};
|
||||
|
||||
|
||||
#endif // JUCE_MIDIOUTPUT_H_INCLUDED
|
||||
Reference in New Issue
Block a user