Just Intonation  Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
MidiPlayer Class Reference

Midi Player. More...

#include <midiplayer.h>

Inheritance diagram for MidiPlayer:
Inheritance graph
Collaboration diagram for MidiPlayer:
Collaboration graph

Public Slots

void loadFile (QString filename, bool autostart=false)
 Load a midi file (*.mid) from disk. More...
 
void loadUrl (QString url)
 Load a midi file (*.mid) from disk (URL-Version) More...
 
void setTempo (double factor)
 Set tempo scale factor. More...
 
void setMidiProgress (double percent)
 Set progress in pecent manually. More...
 
void rewind ()
 Rewind: Move the iterator of the event list to the beginning. More...
 
void togglePlayPause ()
 Toggle between play and pause. More...
 
void setRepeatMode (bool on)
 Switch repeat mode on and off. More...
 
void play ()
 Start or resume playing. More...
 
void pause ()
 Pause: Interrupt playing. More...
 
void receiveTempoData (bool smpte, double parameter)
 Receive tempo data from the parser. More...
 
void reportError (QString msg)
 Report an error. More...
 

Signals

void signalMidiEvent (QMidiMessage event)
 
void signalPlayingStatusChanged (QVariant playing)
 
void signalProgressInPercent (QVariant percent)
 
void signalError (QVariant msg)
 
void helperSignalToReadMidiFile (QString filename, bool autostart)
 
void setDisplayedMidiFilename (QVariant filename)
 

Public Member Functions

 MidiPlayer ()
 Constructor. More...
 
bool stop ()
 Stop the player. More...
 
bool isPlaying () const
 Find out whether the player is playing. More...
 
void suspend ()
 Suspend (stop playing, thread idle) More...
 
void resume ()
 Resume from suspend mode. More...
 
virtual bool init ()
 Virtual initialization function (no functionality here) More...
 
virtual bool exit ()
 Virtual exit function (no functionality here) More...
 
virtual bool start ()
 Start the thread. More...
 
bool isActive () const
 Return true if thread is running and not suspended. More...
 
void setVerbosity (int verbosity)
 Set verbosity level of messages. More...
 
int getVerbosity ()
 Get verbosity level. More...
 
QString getThreadName () const
 Get thread name. More...
 

Protected Member Functions

virtual void initiallyCalledWorker ()
 Virtual worker function called when the thread is starting. More...
 
virtual void finallyCalledWorker ()
 Virtual worker function called when the thread stops. More...
 
virtual void periodicallyCalledWorker ()
 Virtual worker function called periodically from the timer. More...
 
void setPriority (const QThread::Priority p)
 Set thread priority. More...
 
void setTimerInterval (const int msec, const int firstMsec=0)
 Set timer interval for the periodically called worker. More...
 
void setThreadName (const QString name)
 Set thread name (Linux only) More...
 
bool isInterruptionRequested () const
 Return true if the thread was requested to interrupt or terminate. More...
 

Private Slots

void readAndParseMidiFile (QString filename, bool autostart)
 Read and parse a Midi file. More...
 

Private Member Functions

void allNotesOff ()
 Turn all notes off. More...
 
void setTempoFactor (double tempo)
 Modify the tempo scale factor. More...
 
void midiTimeout ()
 Timer midiTimeout. More...
 

Private Attributes

MidiPlayerEventList mEventList
 
bool mCurrentlyPlaying
 Flag whether player is actually playing. More...
 
bool mRepeatMode
 Mode indicating that file shall be repeated. More...
 
bool mPlayAgainAfterSuspend
 Flag for playing after resume. More...
 
bool mTimerActive
 Flag indicating that player is waiting for timeout. More...
 
double mOverallTempoFactor
 Time scaling factor (1 = 100% = recorded tempo) More...
 
quint64 mDeltaTicks
 Elapsed time units (ticks) since the last event. More...
 
double mMillisecondsPerTick
 Calculated number of milliseconds per tick. More...
 
double mTicksPerQuarterNote
 Calculated number of ticks per quarter note. More...
 
double mAccumulatedTime
 Accumulated time since last progress signal. More...
 

Detailed Description

Midi Player.

The MidiPlayer reads a Midi file, stores it in an event list and transmits them in real time to the synthesizer. This class comprises all functions which are needed to actually play the Midi file in real time. Its main part is the function timeout() which calls itself again and again via timer signals. Whenever timeout() is called it emits the corresponding Midi signals, calculates the timespan between the current and the next event in milliseconds, and restarts the timer. In addition, the class provides a basic control like play() and pause().

Note
This is a standalone module independent of other libraries. It interacts with the outside world only via Qt signals and slots in a thread-safe way.

Definition at line 84 of file midiplayer.h.

Constructor & Destructor Documentation

MidiPlayer::MidiPlayer ( )

Constructor.

Definition at line 35 of file midiplayer.cpp.

Here is the call graph for this function:

Member Function Documentation

void MidiPlayer::allNotesOff ( )
private

Turn all notes off.

Definition at line 244 of file midiplayer.cpp.

virtual bool ThreadBase::exit ( )
inlinevirtualinherited

Virtual exit function (no functionality here)

Reimplemented in AudioOutput.

Definition at line 71 of file threadbase.h.

Here is the call graph for this function:

virtual void ThreadBase::finallyCalledWorker ( )
inlineprotectedvirtualinherited

Virtual worker function called when the thread stops.

Reimplemented in Tuner, and AudioOutput.

Definition at line 87 of file threadbase.h.

QString ThreadBase::getThreadName ( ) const
inherited

Get thread name.

Definition at line 132 of file threadbase.cpp.

Here is the call graph for this function:

int ThreadBase::getVerbosity ( )
inlineinherited

Get verbosity level.

Definition at line 80 of file threadbase.h.

Here is the call graph for this function:

void MidiPlayer::helperSignalToReadMidiFile ( QString  filename,
bool  autostart 
)
signal
virtual bool ThreadBase::init ( )
inlinevirtualinherited

Virtual initialization function (no functionality here)

Reimplemented in Tuner, AudioOutput, and SoundGenerator.

Definition at line 70 of file threadbase.h.

virtual void ThreadBase::initiallyCalledWorker ( )
inlineprotectedvirtualinherited

Virtual worker function called when the thread is starting.

Reimplemented in Tuner, and AudioOutput.

Definition at line 85 of file threadbase.h.

bool ThreadBase::isActive ( ) const
inherited

Return true if thread is running and not suspended.

Definition at line 136 of file threadbase.cpp.

bool ThreadBase::isInterruptionRequested ( ) const
protectedinherited

Return true if the thread was requested to interrupt or terminate.

Definition at line 128 of file threadbase.cpp.

bool MidiPlayer::isPlaying ( ) const

Find out whether the player is playing.

Returns
True if playing

Definition at line 263 of file midiplayer.cpp.

void MidiPlayer::loadFile ( QString  filename,
bool  autostart = false 
)
slot

Load a midi file (*.mid) from disk.

This function requests the MidiPlayer to load a file. The loading process is carried out in the independent thread, meaning that this function returns immediately.

Parameters
filename: Name of the file (including path)
autostart: Flag indicating that Midi player should start after loading

Definition at line 88 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::loadUrl ( QString  url)
slot

Load a midi file (*.mid) from disk (URL-Version)

This function requests the MidiPlayer to load a file. The loading process is carried out in the independent thread, meaning that this function returns immediately.

Parameters
url: URL of the file ( file//:...)

Definition at line 108 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::midiTimeout ( )
private

Timer midiTimeout.

This is the heart of the Midi player. It reads an event from the EventList and transmits it by a signal to the Midi device. The time difference between the current and the next event is calculated. If this difference is zero, the function repeats itself recursively, handling the next event in the queue. If the difference is non-zero, a QTimer is started in the one-shot mode, returning to this function on midiTimeout.

Definition at line 404 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::pause ( )
slot

Pause: Interrupt playing.

This function interrupts the playing loop without resetting the iterator. In order to switch off all notes, the corresponding codes are sent directly to the Midi device.

Definition at line 228 of file midiplayer.cpp.

Here is the call graph for this function:

virtual void ThreadBase::periodicallyCalledWorker ( )
inlineprotectedvirtualinherited

Virtual worker function called periodically from the timer.

Reimplemented in Tuner, and AudioDeviceGuard.

Definition at line 89 of file threadbase.h.

Here is the call graph for this function:

void MidiPlayer::play ( )
slot

Start or resume playing.

This function starts the timer to begin playback after 20 msec. Reading continues at the last position, e.g. after calling pause().

Definition at line 203 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::readAndParseMidiFile ( QString  filename,
bool  autostart 
)
privateslot

Read and parse a Midi file.

This function reads a Midi file (*.mid) from the device, parses its content and stores the extracted events in a time-ordered EventList.

Parameters
filename: Name of the file
autostart: Flag for immediate playback after loading

Definition at line 339 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::receiveTempoData ( bool  smpte,
double  parameter 
)
slot

Receive tempo data from the parser.

Most Midi files contain meta information about the tempo. When the parser finds this information the present function is called. It informs the MidiPlayer aboout the timing mode. In the Midi norm there are two timing norms, an absolute so-called SMPTE timing and a quarter-note varying timing. In both cases the transmitted parameter has a different meaning.

Parameters
smpte: True if SMPTE timing, false otherwise
parameter: For SMPTE milliseconds per ticks, otherwise ticks per quarter note.

Definition at line 384 of file midiplayer.cpp.

void MidiPlayer::reportError ( QString  msg)
slot

Report an error.

If the verbosity level is nonzero the error is written to qCritical(). Moreover, the function calls the signal sendError(msg) in the MidiPlayer.

Parameters
msg: Error string

Definition at line 321 of file midiplayer.cpp.

void MidiPlayer::resume ( )
virtual

Resume from suspend mode.

Reimplemented from ThreadBase.

Definition at line 290 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::rewind ( )
slot

Rewind: Move the iterator of the event list to the beginning.

Definition at line 158 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::setDisplayedMidiFilename ( QVariant  filename)
signal
void MidiPlayer::setMidiProgress ( double  percent)
slot

Set progress in pecent manually.

Parameters
percent

Definition at line 143 of file midiplayer.cpp.

Here is the call graph for this function:

void ThreadBase::setPriority ( const QThread::Priority  p)
protectedinherited

Set thread priority.

Definition at line 109 of file threadbase.cpp.

Here is the call graph for this function:

void MidiPlayer::setRepeatMode ( bool  on)
slot

Switch repeat mode on and off.

Definition at line 187 of file midiplayer.cpp.

void MidiPlayer::setTempo ( double  factor)
slot

Set tempo scale factor.

Parameters
factor: Scale factor (1 = 100% = neutral)

Definition at line 128 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::setTempoFactor ( double  factor)
private

Modify the tempo scale factor.

Parameters
factor: Scale factor (1 = 100%)

Definition at line 306 of file midiplayer.cpp.

void ThreadBase::setThreadName ( const QString  name)
protectedinherited

Set thread name (Linux only)

Definition at line 121 of file threadbase.cpp.

Here is the call graph for this function:

void ThreadBase::setTimerInterval ( const int  msec,
const int  firstMsec = 0 
)
protectedinherited

Set timer interval for the periodically called worker.

Definition at line 117 of file threadbase.cpp.

Here is the call graph for this function:

void ThreadBase::setVerbosity ( int  verbosity)
inherited

Set verbosity level of messages.

Definition at line 113 of file threadbase.cpp.

Here is the call graph for this function:

void MidiPlayer::signalError ( QVariant  msg)
signal
void MidiPlayer::signalMidiEvent ( QMidiMessage  event)
signal
void MidiPlayer::signalPlayingStatusChanged ( QVariant  playing)
signal
void MidiPlayer::signalProgressInPercent ( QVariant  percent)
signal
bool ThreadBase::start ( )
virtualinherited

Start the thread.

Starts the thread. If the thread is suspended it will resume. If the thread is already started the function does nothing.

Returns
True on succes

Reimplemented in Tuner, and AudioOutput.

Definition at line 64 of file threadbase.cpp.

Here is the call graph for this function:

bool MidiPlayer::stop ( )
virtual

Stop the player.

This function stops the player so that it is no longer playing or listening to its slots. Loaded MIDI data is not cancelled so that the same music can be played again after restarting the player.

Returns
true if thread stopped normally

Reimplemented from ThreadBase.

Definition at line 68 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::suspend ( )
virtual

Suspend (stop playing, thread idle)

Reimplemented from ThreadBase.

Definition at line 275 of file midiplayer.cpp.

Here is the call graph for this function:

void MidiPlayer::togglePlayPause ( )
slot

Toggle between play and pause.

Definition at line 173 of file midiplayer.cpp.

Here is the call graph for this function:

Member Data Documentation

double MidiPlayer::mAccumulatedTime
private

Accumulated time since last progress signal.

Definition at line 134 of file midiplayer.h.

bool MidiPlayer::mCurrentlyPlaying
private

Flag whether player is actually playing.

Definition at line 126 of file midiplayer.h.

quint64 MidiPlayer::mDeltaTicks
private

Elapsed time units (ticks) since the last event.

Definition at line 131 of file midiplayer.h.

MidiPlayerEventList MidiPlayer::mEventList
private

Definition at line 125 of file midiplayer.h.

double MidiPlayer::mMillisecondsPerTick
private

Calculated number of milliseconds per tick.

Definition at line 132 of file midiplayer.h.

double MidiPlayer::mOverallTempoFactor
private

Time scaling factor (1 = 100% = recorded tempo)

Definition at line 130 of file midiplayer.h.

bool MidiPlayer::mPlayAgainAfterSuspend
private

Flag for playing after resume.

Definition at line 128 of file midiplayer.h.

bool MidiPlayer::mRepeatMode
private

Mode indicating that file shall be repeated.

Definition at line 127 of file midiplayer.h.

double MidiPlayer::mTicksPerQuarterNote
private

Calculated number of ticks per quarter note.

Definition at line 133 of file midiplayer.h.

bool MidiPlayer::mTimerActive
private

Flag indicating that player is waiting for timeout.

Definition at line 129 of file midiplayer.h.


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