#include <playthread.h>
Public Slots | |
void | start (Priority priority=InheritPriority) |
Starts the playback thread. | |
Signals | |
void | finished () |
Signal emitted when the sequence play-back has finished. | |
void | stopped () |
Signal emitted when the play-back has stopped. | |
Public Member Functions | |
SequencerOutputThread (MidiClient *seq, int portId) | |
Constructor. | |
virtual void | run () |
Thread process loop. | |
virtual unsigned int | getInitialPosition () |
Gets the initial position in ticks of the sequence. | |
virtual unsigned int | getEchoResolution () |
Gets the echo event resolution in ticks. | |
virtual bool | hasNext ()=0 |
Check if there is one more event in the sequence. | |
virtual SequencerEvent * | nextEvent ()=0 |
Gets the next event in the sequence. | |
virtual void | stop () |
Stops playing the current sequence. | |
Protected Member Functions | |
virtual void | sendEchoEvent (int tick) |
Sends an echo event, with the same PortId as sender and destination. | |
virtual void | sendSongEvent (SequencerEvent *ev) |
Sends a SequencerEvent. | |
virtual void | drainOutput () |
Flush the ALSA output buffer. | |
virtual void | syncOutput () |
Waits until the ALSA output queue is empty (all the events have been played. | |
virtual bool | stopRequested () |
Checks if stop has been requested. | |
Protected Attributes | |
MidiClient * | m_MidiClient |
MidiClient instance pointer. | |
MidiQueue * | m_Queue |
MidiQueue instance pointer. | |
int | m_PortId |
MidiPort numeric identifier. | |
bool | m_Stopped |
Stopped status. | |
int | m_QueueId |
MidiQueue numeric identifier. | |
int | m_npfds |
Number of pollfd pointers. | |
pollfd * | m_pfds |
Array of pollfd pointers. | |
QReadWriteLock | m_mutex |
Mutex object used for synchronization. |
This class is used to implement an asynchronous sequence player using ALSA sequencer scheduling
Examples: guiplayer.cpp and playsmf.cpp
Definition at line 47 of file playthread.h.
SequencerOutputThread | ( | MidiClient * | seq, | |
int | portId | |||
) |
Constructor.
seq | Existing MidiClient object pointer | |
portId | Numeric input/output port identifier |
Definition at line 63 of file playthread.cpp.
References MidiQueue::getId(), MidiClient::getQueue(), SequencerOutputThread::m_MidiClient, SequencerOutputThread::m_Queue, and SequencerOutputThread::m_QueueId.
void drainOutput | ( | ) | [protected, virtual] |
Flush the ALSA output buffer.
Definition at line 138 of file playthread.cpp.
References MidiClient::getHandle(), SequencerOutputThread::m_MidiClient, SequencerOutputThread::m_npfds, SequencerOutputThread::m_pfds, and SequencerOutputThread::stopRequested().
Referenced by SequencerOutputThread::run().
void finished | ( | ) | [signal] |
Signal emitted when the sequence play-back has finished.
Referenced by SequencerOutputThread::run().
virtual unsigned int getEchoResolution | ( | ) | [inline, virtual] |
Gets the echo event resolution in ticks.
This is the time between echo events interleaved with the MIDI sequence. The default value zero means that not echo events are sent at all.
Definition at line 65 of file playthread.h.
Referenced by SequencerOutputThread::run().
virtual unsigned int getInitialPosition | ( | ) | [inline, virtual] |
Gets the initial position in ticks of the sequence.
Definition at line 58 of file playthread.h.
Referenced by SequencerOutputThread::run().
virtual bool hasNext | ( | ) | [pure virtual] |
Check if there is one more event in the sequence.
This is a pure virtual method that must be overridden in the derived class.
Referenced by SequencerOutputThread::run().
virtual SequencerEvent* nextEvent | ( | ) | [pure virtual] |
Gets the next event in the sequence.
This is a pure virtual function that must be overridden in the derived class.
Referenced by SequencerOutputThread::run().
void run | ( | ) | [virtual] |
Thread process loop.
Definition at line 165 of file playthread.cpp.
References MidiQueue::clear(), MidiQueue::continueRunning(), SequencerOutputThread::drainOutput(), SequencerOutputThread::finished(), SequencerOutputThread::getEchoResolution(), MidiClient::getHandle(), SequencerOutputThread::getInitialPosition(), SequencerOutputThread::hasNext(), SequencerEvent::isConnectionChange(), SequencerOutputThread::m_MidiClient, SequencerOutputThread::m_npfds, SequencerOutputThread::m_pfds, SequencerOutputThread::m_Queue, SequencerOutputThread::nextEvent(), SequencerOutputThread::sendEchoEvent(), SequencerOutputThread::sendSongEvent(), MidiQueue::setTickPosition(), MidiQueue::start(), MidiQueue::stop(), SequencerOutputThread::stopped(), SequencerOutputThread::stopRequested(), and SequencerOutputThread::syncOutput().
void sendEchoEvent | ( | int | tick | ) | [protected, virtual] |
Sends an echo event, with the same PortId as sender and destination.
tick | Event schedule time in ticks. |
Definition at line 109 of file playthread.cpp.
References MidiClient::getClientId(), SequencerOutputThread::m_MidiClient, SequencerOutputThread::m_PortId, SequencerOutputThread::m_QueueId, SequencerEvent::scheduleTick(), SequencerOutputThread::sendSongEvent(), SequencerEvent::setDestination(), SequencerEvent::setSource(), and SequencerOutputThread::stopRequested().
Referenced by SequencerOutputThread::run().
void sendSongEvent | ( | SequencerEvent * | ev | ) | [protected, virtual] |
Sends a SequencerEvent.
ev | SequencerEvent object pointer |
Definition at line 125 of file playthread.cpp.
References SequencerEvent::getHandle(), MidiClient::getHandle(), SequencerOutputThread::m_MidiClient, SequencerOutputThread::m_npfds, SequencerOutputThread::m_pfds, and SequencerOutputThread::stopRequested().
Referenced by SequencerOutputThread::run(), and SequencerOutputThread::sendEchoEvent().
void start | ( | Priority | priority = InheritPriority |
) | [slot] |
Starts the playback thread.
priority | Thread priority, default is InheritPriority |
Definition at line 215 of file playthread.cpp.
References SequencerOutputThread::m_mutex, and SequencerOutputThread::m_Stopped.
void stop | ( | ) | [virtual] |
Stops playing the current sequence.
Stops the playback task.
Definition at line 95 of file playthread.cpp.
References SequencerOutputThread::m_mutex, and SequencerOutputThread::m_Stopped.
void stopped | ( | ) | [signal] |
Signal emitted when the play-back has stopped.
Referenced by SequencerOutputThread::run().
bool stopRequested | ( | ) | [protected, virtual] |
Checks if stop has been requested.
Definition at line 85 of file playthread.cpp.
References SequencerOutputThread::m_mutex, and SequencerOutputThread::m_Stopped.
Referenced by SequencerOutputThread::drainOutput(), SequencerOutputThread::run(), SequencerOutputThread::sendEchoEvent(), SequencerOutputThread::sendSongEvent(), and SequencerOutputThread::syncOutput().
void syncOutput | ( | ) | [protected, virtual] |
Waits until the ALSA output queue is empty (all the events have been played.
)
Definition at line 151 of file playthread.cpp.
References QueueStatus::getEvents(), MidiQueue::getStatus(), SequencerOutputThread::m_MidiClient, SequencerOutputThread::m_Queue, and SequencerOutputThread::stopRequested().
Referenced by SequencerOutputThread::run().
MidiClient* m_MidiClient [protected] |
MidiClient instance pointer.
Definition at line 108 of file playthread.h.
Referenced by SequencerOutputThread::drainOutput(), SequencerOutputThread::run(), SequencerOutputThread::sendEchoEvent(), SequencerOutputThread::sendSongEvent(), SequencerOutputThread::SequencerOutputThread(), and SequencerOutputThread::syncOutput().
QReadWriteLock m_mutex [protected] |
Mutex object used for synchronization.
Definition at line 115 of file playthread.h.
Referenced by SequencerOutputThread::start(), SequencerOutputThread::stop(), and SequencerOutputThread::stopRequested().
int m_npfds [protected] |
Number of pollfd pointers.
Definition at line 113 of file playthread.h.
Referenced by SequencerOutputThread::drainOutput(), SequencerOutputThread::run(), and SequencerOutputThread::sendSongEvent().
pollfd* m_pfds [protected] |
Array of pollfd pointers.
Definition at line 114 of file playthread.h.
Referenced by SequencerOutputThread::drainOutput(), SequencerOutputThread::run(), and SequencerOutputThread::sendSongEvent().
int m_PortId [protected] |
MidiPort numeric identifier.
Definition at line 110 of file playthread.h.
Referenced by SequencerOutputThread::sendEchoEvent().
MidiQueue instance pointer.
Definition at line 109 of file playthread.h.
Referenced by SequencerOutputThread::run(), SequencerOutputThread::SequencerOutputThread(), and SequencerOutputThread::syncOutput().
int m_QueueId [protected] |
MidiQueue numeric identifier.
Definition at line 112 of file playthread.h.
Referenced by SequencerOutputThread::sendEchoEvent(), and SequencerOutputThread::SequencerOutputThread().
bool m_Stopped [protected] |
Stopped status.
Definition at line 111 of file playthread.h.
Referenced by SequencerOutputThread::start(), SequencerOutputThread::stop(), and SequencerOutputThread::stopRequested().