20 #include <alsa/asoundlib.h>
24#include <QWriteLocker>
60const int TIMEOUT = 100;
104 while (isRunning()) {
171 unsigned int last_tick;
176 if (last_tick == 0) {
207 qWarning(
"exception in output thread");
223 QThread::start( priority );
Classes managing ALSA Sequencer clients.
Classes managing ALSA Sequencer queues.
The QThread class provides platform-independent threads.
void setTickPosition(snd_seq_tick_time_t pos)
Sets the queue position in musical time (ticks).
void continueRunning()
Start the queue without resetting the last position.
void start()
Start the queue.
void stop()
Stop the queue.
void clear()
Clear the queue, dropping any scheduled events.
Base class for the event's hierarchy.
static bool isConnectionChange(const SequencerEvent *event)
Checks if the event's type is of type connection change.
snd_seq_event_t * getHandle()
Gets the handle of the event.
void scheduleTick(const int queue, const int tick, const bool relative)
Sets the event to be scheduled in musical time (ticks) units.
void setDestination(const unsigned char client, const unsigned char port)
Sets the client:port destination of the event.
void setSource(const unsigned char port)
Sets the event's source port ID.
void playbackStopped()
Signal emitted when the play-back has stopped.
virtual SequencerEvent * nextEvent()=0
Gets the next event in the sequence.
void start(QThread::Priority priority=InheritPriority)
Starts the playback thread.
virtual unsigned int getInitialPosition()
Gets the initial position in ticks of the sequence.
virtual void sendEchoEvent(int tick)
Sends an echo event, with the same PortId as sender and destination.
SequencerOutputThread(MidiClient *seq, int portId)
Constructor.
virtual void syncOutput()
Waits until the ALSA output queue is empty (all the events have been played.)
int m_QueueId
MidiQueue numeric identifier.
MidiClient * m_MidiClient
MidiClient instance pointer.
bool m_Stopped
Stopped status.
void playbackFinished()
Signal emitted when the sequence play-back has finished.
virtual void stop()
Stops playing the current sequence.
virtual void sendSongEvent(SequencerEvent *ev)
Sends a SequencerEvent.
virtual void drainOutput()
Flush the ALSA output buffer.
pollfd * m_pfds
Array of pollfd pointers.
QReadWriteLock m_mutex
Mutex object used for synchronization.
MidiQueue * m_Queue
MidiQueue instance pointer.
virtual bool hasNext()=0
Check if there is one more event in the sequence.
virtual unsigned int getEchoResolution()
Gets the echo event resolution in ticks.
virtual void run() override
Thread process loop.
int m_npfds
Number of pollfd pointers.
int m_PortId
MidiPort numeric identifier.
virtual bool stopRequested()
Checks if stop has been requested.
MidiQueue * getQueue()
Get the MidiQueue instance associated to this client.
snd_seq_t * getHandle()
Returns the sequencer handler managed by ALSA.
int getClientId()
Gets the client ID.
void synchronizeOutput()
Wait until all sent events are processed.