29 : message (data, len, timeStamp)
36 MidiOutput::MidiOutput (
const String& deviceName)
37 :
Thread (
"midi out"), name (deviceName)
52 double millisecondCounterToStartAt,
53 double samplesPerSecondForBuffer)
59 jassert (millisecondCounterToStartAt > 0);
61 auto timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
68 auto eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
73 if (firstMessage ==
nullptr || firstMessage->message.getTimeStamp() > eventTime)
75 m->next = firstMessage;
80 auto* mm = firstMessage;
82 while (mm->next !=
nullptr && mm->next->message.getTimeStamp() <= eventTime)
97 while (firstMessage !=
nullptr)
99 auto* m = firstMessage;
100 firstMessage = firstMessage->next;
115 void MidiOutput::run()
120 uint32 eventTime = 0;
121 uint32 timeToWait = 500;
127 message = firstMessage;
129 if (message !=
nullptr)
131 eventTime = (uint32) roundToInt (message->message.
getTimeStamp());
133 if (eventTime > now + 20)
135 timeToWait = eventTime - (now + 20);
140 firstMessage = message->next;
145 if (message !=
nullptr)
147 std::unique_ptr<PendingMessage> messageDeleter (message);
157 if (eventTime > now - 200)
162 jassert (timeToWait < 1000 * 30);
163 wait ((
int) timeToWait);
static void waitForMillisecondCounter(uint32 targetTime) noexcept
Waits until the getMillisecondCounter() reaches a given value.
bool stopThread(int timeOutMilliseconds)
Attempts to stop the thread running.
Encapsulates a MIDI message.
bool getNextEvent(MidiMessage &result, int &samplePosition) noexcept
Retrieves a copy of the next event from the buffer.
Thread(const String &threadName, size_t threadStackSize=0)
Creates a thread.
void notify() const
Wakes up the thread.
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...
void stopBackgroundThread()
Stops the background thread, and clears any pending midi events.
void startBackgroundThread()
Starts up a background thread so that the device can send blocks of data.
void sendMessageNow(const MidiMessage &message)
Sends out a MIDI message immediately.
void clearAllPendingMessages()
Gets rid of any midi messages that had been added by sendBlockOfMessages().
bool threadShouldExit() const
Checks whether the thread has been told to stop running.
Holds a sequence of time-stamped midi events.
bool isThreadRunning() const
Returns true if the thread is currently active.
double getTimeStamp() const noexcept
Returns the timestamp associated with this message.
Used to iterate through the events in a MidiBuffer.
Automatically locks and unlocks a mutex object.
bool wait(int timeOutMilliseconds) const
Suspends the execution of this thread until either the specified timeout period has elapsed...
void startThread()
Starts the thread running.
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
void sendBlockOfMessagesNow(const MidiBuffer &buffer)
Sends out a sequence of MIDI messages immediately.