OpenShot Library | libopenshot-audio
0.2.0
|
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;
123 PendingMessage* message;
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);
void notify() const
Wakes up the thread.
void startThread()
Starts the thread running.
void sendBlockOfMessagesNow(const MidiBuffer &buffer)
Sends out a sequence of MIDI messages immediately.
Used to iterate through the events in a MidiBuffer.
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
bool threadShouldExit() const
Checks whether the thread has been told to stop running.
static void waitForMillisecondCounter(uint32 targetTime) noexcept
Waits until the getMillisecondCounter() reaches a given value.
bool isThreadRunning() const
Returns true if the thread is currently active.
Holds a sequence of time-stamped midi events.
bool getNextEvent(MidiMessage &result, int &samplePosition) noexcept
Retrieves a copy of the next event from the buffer.
Encapsulates a MIDI message.
bool wait(int timeOutMilliseconds) const
Suspends the execution of this thread until either the specified timeout period has elapsed,...
bool stopThread(int timeOutMilliseconds)
Attempts to stop the thread running.
Automatically locks and unlocks a mutex object.
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.
double getTimeStamp() const noexcept
Returns the timestamp associated with this message.
void clearAllPendingMessages()
Gets rid of any midi messages that had been added by sendBlockOfMessages().
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.