JUCE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
MidiOutput Class Reference

Controls a physical MIDI output device. More...

Inherits Thread.

Public Member Functions

virtual ~MidiOutput ()
 Destructor.
 
virtual void sendMessageNow (const MidiMessage &message)
 Makes this device output a midi message.
 
virtual void sendBlockOfMessages (const MidiBuffer &buffer, double millisecondCounterToStartAt, double samplesPerSecondForBuffer)
 This lets you supply a block of messages that will be sent out at some point in the future.
 
virtual void clearAllPendingMessages ()
 Gets rid of any midi messages that had been added by sendBlockOfMessages().
 
virtual void startBackgroundThread ()
 Starts up a background thread so that the device can send blocks of data.
 
virtual void stopBackgroundThread ()
 Stops the background thread, and clears any pending midi events.
 

Static Public Member Functions

static StringArray getDevices ()
 Returns a list of the available midi output devices.
 
static int getDefaultDeviceIndex ()
 Returns the index of the default midi output device to use.
 
static MidiOutputopenDevice (int deviceIndex)
 Tries to open one of the midi output devices.
 
static MidiOutputcreateNewDevice (const String &deviceName)
 This will try to create a new midi output device (Not available on Windows).
 

Protected Member Functions

 MidiOutput ()
 
void run () override
 Must be implemented to perform the thread's actual code.
 

Protected Attributes

void * internal
 
CriticalSection lock
 
PendingMessage * firstMessage
 

Additional Inherited Members

- Private Types inherited from Thread
typedef void * ThreadID
 A value type used for thread IDs.
 
- Private Member Functions inherited from Thread
 Thread (const String &threadName)
 Creates a thread.
 
virtual ~Thread ()
 Destructor.
 
void startThread ()
 Starts the thread running.
 
void startThread (int priority)
 Starts the thread with a given priority.
 
bool stopThread (int timeOutMilliseconds)
 Attempts to stop the thread running.
 
bool isThreadRunning () const
 Returns true if the thread is currently active.
 
void signalThreadShouldExit ()
 Sets a flag to tell the thread it should stop.
 
bool threadShouldExit () const
 Checks whether the thread has been told to stop running.
 
bool waitForThreadToExit (int timeOutMilliseconds) const
 Waits for the thread to stop.
 
bool setPriority (int priority)
 Changes the thread's priority.
 
void setAffinityMask (uint32 affinityMask)
 Sets the affinity mask for the thread.
 
bool wait (int timeOutMilliseconds) const
 Makes the thread wait for a notification.
 
void notify () const
 Wakes up the thread.
 
ThreadID getThreadId () const noexcept
 Returns the ID of this thread.
 
const StringgetThreadName () const
 Returns the name of the thread.
 
- Static Private Member Functions inherited from Thread
static bool setCurrentThreadPriority (int priority)
 Changes the priority of the caller thread.
 
static void JUCE_CALLTYPE setCurrentThreadAffinityMask (uint32 affinityMask)
 Changes the affinity mask for the caller thread.
 
static void JUCE_CALLTYPE sleep (int milliseconds)
 
static void JUCE_CALLTYPE yield ()
 Yields the calling thread's current time-slot.
 
static ThreadID JUCE_CALLTYPE getCurrentThreadId ()
 Returns an id that identifies the caller thread.
 
static Thread *JUCE_CALLTYPE getCurrentThread ()
 Finds the thread object that is currently running.
 
static void JUCE_CALLTYPE setCurrentThreadName (const String &newThreadName)
 Changes the name of the caller thread.
 

Detailed Description

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 Also
MidiInput

Constructor & Destructor Documentation

virtual MidiOutput::~MidiOutput ( )
virtual

Destructor.

MidiOutput::MidiOutput ( )
protected

Member Function Documentation

static StringArray MidiOutput::getDevices ( )
static

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 Also
getDefaultDeviceIndex, openDevice
static int MidiOutput::getDefaultDeviceIndex ( )
static

Returns the index of the default midi output device to use.

This refers to the index in the list returned by getDevices().

static MidiOutput* MidiOutput::openDevice ( int  deviceIndex)
static

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.

Parameters
deviceIndexthe index of a device from the list returned by getDevices()
See Also
getDevices
static MidiOutput* MidiOutput::createNewDevice ( const String deviceName)
static

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.

Parameters
deviceNamethe name to use for the new device
virtual void MidiOutput::sendMessageNow ( const MidiMessage message)
virtual

Makes this device output a midi message.

See Also
MidiMessage
virtual void MidiOutput::sendBlockOfMessages ( const MidiBuffer buffer,
double  millisecondCounterToStartAt,
double  samplesPerSecondForBuffer 
)
virtual

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 MidiOutput::clearAllPendingMessages ( )
virtual

Gets rid of any midi messages that had been added by sendBlockOfMessages().

virtual void MidiOutput::startBackgroundThread ( )
virtual

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 MidiOutput::stopBackgroundThread ( )
virtual

Stops the background thread, and clears any pending midi events.

See Also
startBackgroundThread
void MidiOutput::run ( )
overrideprotectedvirtual

Must be implemented to perform the thread's actual code.

Remember that the thread must regularly check the threadShouldExit() method whilst running, and if this returns true it should return from the run() method as soon as possible to avoid being forcibly killed.

See Also
threadShouldExit, startThread

Implements Thread.

Member Data Documentation

void* MidiOutput::internal
protected
CriticalSection MidiOutput::lock
protected
PendingMessage* MidiOutput::firstMessage
protected

The documentation for this class was generated from the following file: