Canorus  0.0
Public Slots | Signals | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CAPlayback Class Reference

Audio playback of the score. This class creates playback events (usually MIDI events) for the music elements and sends these events to one of the playback devices (usually CAMidiDevice). More...

#include <playback.h>

Inheritance diagram for CAPlayback:
Inheritance graph
[legend]

Public Slots

void stopNow ()
 

Signals

void playbackFinished ()
 

Public Member Functions

 CAPlayback (CASheet *, CAMidiDevice *)
 
 CAPlayback (CAMidiDevice *)
 
 ~CAPlayback ()
 
void run ()
 
void stop ()
 
void playImmediately (QList< CAMusElement * > elts, int port)
 
const int getInitTimeStart ()
 
void setInitTimeStart (int t)
 
CAMidiDevicemidiDevice ()
 
CASheetsheet ()
 
void setSheet (CASheet *s)
 
QList< CAPlayable * > & curPlaying ()
 

Private Member Functions

void initPlayback ()
 
void initStreams (CASheet *sheet)
 
void loopUntilPlayable (int i, bool ignoreRepeats=false)
 
void playSelectionImpl ()
 
void updateSleepFactor (CATempo *t)
 
QList< CAMusElement * > & streamAt (int idx)
 
const QList< QList< CAMusElement * > > & streamList ()
 
int & streamIdx (int i)
 
int & lastRepeatOpenIdx (int i)
 
bool stopLock ()
 
void setStopLock (bool lock)
 
void setMidiDevice (CAMidiDevice *d)
 
void setStop (bool stop)
 

Private Attributes

CASheet_sheet
 
CAMidiDevice_midiDevice
 
bool _stop
 
bool _stopLock
 
bool _playSelectionOnly
 
QList< CAMusElement * > _selection
 
int _initTimeStart
 
float _sleepFactor
 
QList< QList< CAMusElement * > > _streamList
 
QList< CAPlayable * > _curPlaying
 
int * _streamIdx
 
bool _repeating
 
int * _lastRepeatOpenIdx
 
int _curTime
 

Detailed Description

Audio playback of the score. This class creates playback events (usually MIDI events) for the music elements and sends these events to one of the playback devices (usually CAMidiDevice).

Copyright (c) 2006-2007, Matevž Jekovec, Canorus development team All Rights Reserved. See AUTHORS for a complete list of authors.

Licensed under the GNU GENERAL PUBLIC LICENSE. See COPYING for details.

To use the playback capabilities: 1) Create one of the CAMidiDevices (eg. CARtMidiDevice) and configure it (open output/input port). 2) Create CAPlayback object passing it the current score viewport (played notes will be painted red) or only the sheet (usually used in scripting environment) and the midi device. 3) Optionally configure playback (setInitTimeStart() to start playback from the specific time. Default 0). 4) Call myPlaybackObject->run(). This will start playing in a new thread. 5) Call myPlaybackObject->stop() to stop the playback. Playback also stops automatically when finished. 6) Playback is also used for creating the events for midi file export. Therefore the music length time _curTime is also transferred as a paramter in send() and sendMetaEvent() to export the music lengths independent of tempo.

The playbackFinished() signal is emitted once playback has finished or stopped.

If you want to immediately play only given elements (eg. when inserting notes), call playImmediately().

Constructor & Destructor Documentation

◆ CAPlayback() [1/2]

CAPlayback::CAPlayback ( CASheet s,
CAMidiDevice m 
)

References _midiDevice, _playSelectionOnly, _sheet, and initPlayback().

Here is the call graph for this function:

◆ CAPlayback() [2/2]

CAPlayback::CAPlayback ( CAMidiDevice m)

Plays the list of music elements simultaniously. It only takes notes into account.

References _midiDevice, _playSelectionOnly, and initPlayback().

Here is the call graph for this function:

◆ ~CAPlayback()

CAPlayback::~CAPlayback ( )

Destructor deletes the created arrays.

References _lastRepeatOpenIdx, and _streamIdx.

Member Function Documentation

◆ curPlaying()

QList<CAPlayable*>& CAPlayback::curPlaying ( )
inline

References _curPlaying.

Referenced by CAMainWin::deleteSelection(), and CAMainWin::onRepaintTimerTimeout().

Here is the caller graph for this function:

◆ getInitTimeStart()

const int CAPlayback::getInitTimeStart ( )
inline

References _initTimeStart.

Referenced by initStreams().

Here is the caller graph for this function:

◆ initPlayback()

void CAPlayback::initPlayback ( )
private

Initializes all basic playback values to zero and connects the signals. Usually called only once from the constructor.

References _curTime, _initTimeStart, _lastRepeatOpenIdx, _midiDevice, _playSelectionOnly, _repeating, _sheet, _sleepFactor, _stop, _stopLock, _streamIdx, and stopNow().

Referenced by CAPlayback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initStreams()

void CAPlayback::initStreams ( CASheet sheet)
private

Generates streams (elements lists) of playable elements (notes, rests) from the given sheet.

References _curTime, _lastRepeatOpenIdx, _repeating, _sheet, _streamIdx, _streamList, CASheet::contextList(), getInitTimeStart(), CASheet::getTempo(), lastRepeatOpenIdx(), loopUntilPlayable(), midiDevice(), CAMidiDevice::send(), sheet(), CAContext::Staff, streamIdx(), streamList(), updateSleepFactor(), and CAStaff::voiceList().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lastRepeatOpenIdx()

int& CAPlayback::lastRepeatOpenIdx ( int  i)
inlineprivate

References _lastRepeatOpenIdx.

Referenced by initStreams(), and loopUntilPlayable().

Here is the caller graph for this function:

◆ loopUntilPlayable()

void CAPlayback::loopUntilPlayable ( int  i,
bool  ignoreRepeats = false 
)
private

Loops from the stream with the given index i until the last element with smaller or equal start time of the current time. This function also remembers any special signs like open repeat barlines.

References _curTime, _repeating, CAMusElement::Barline, CAKeySignature::diatonicKey(), CADiatonicKey::gender(), CANote::isFirstInChord(), CAMusElement::KeySignature, lastRepeatOpenIdx(), CAMidiDevice::Meta_Keysig, CAMidiDevice::Meta_Timesig, midiDevice(), CADiatonicKey::Minor, CAMusElement::Note, CADiatonicKey::numberOfAccs(), CABarline::RepeatClose, CABarline::RepeatOpen, CAMidiDevice::sendMetaEvent(), streamAt(), streamIdx(), streamList(), and CAMusElement::TimeSignature.

Referenced by initStreams(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ midiDevice()

CAMidiDevice* CAPlayback::midiDevice ( )
inline

References _midiDevice.

Referenced by initStreams(), loopUntilPlayable(), playImmediately(), playSelectionImpl(), and run().

Here is the caller graph for this function:

◆ playbackFinished

void CAPlayback::playbackFinished ( )
signal

Referenced by stopNow().

Here is the caller graph for this function:

◆ playImmediately()

void CAPlayback::playImmediately ( QList< CAMusElement * >  elts,
int  port 
)

Immediately plays the given elts.

References _selection, midiDevice(), and CAMidiDevice::openOutputPort().

Referenced by CAMainWin::playImmediately().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playSelectionImpl()

void CAPlayback::playSelectionImpl ( )
private

Private function for immediately playing the music elements in _selection. This function ends when all the notes in _selection queue are played. _selection queue might be refilled during the playback by calling playImmediately().

This function is usually called when inserting new notes. If the first note is still playing, the second note is played simultaniously - thus having two notes in _selection for eg.

References _curPlaying, _curTime, _selection, _stop, CANote::diatonicPitch(), CADiatonicPitch::diatonicPitchToMidiPitch(), CAVoice::midiChannel(), midiDevice(), CAVoice::midiPitchOffset(), CAVoice::midiProgram(), CAMusElement::Note, CAMidiDevice::send(), stop(), CAMusElement::timeLength(), and CAPlayable::voice().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

void CAPlayback::run ( )

◆ setInitTimeStart()

void CAPlayback::setInitTimeStart ( int  t)
inline

References _initTimeStart.

Referenced by CAMainWin::on_uiPlayFromSelection_toggled().

Here is the caller graph for this function:

◆ setMidiDevice()

void CAPlayback::setMidiDevice ( CAMidiDevice d)
inlineprivate

References _midiDevice.

◆ setSheet()

void CAPlayback::setSheet ( CASheet s)
inline

References _sheet.

◆ setStop()

void CAPlayback::setStop ( bool  stop)
inlineprivate

References _stop, and stop().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setStopLock()

void CAPlayback::setStopLock ( bool  lock)
inlineprivate

References _stopLock.

Referenced by stopNow().

Here is the caller graph for this function:

◆ sheet()

CASheet* CAPlayback::sheet ( )
inline

References _sheet.

Referenced by initStreams(), and run().

Here is the caller graph for this function:

◆ stop()

void CAPlayback::stop ( )

The nice and the right way to stop the playback. Returns immediately.

See also
stopNow()

References _stop.

Referenced by CAMainWin::on_uiPlayFromSelection_toggled(), playSelectionImpl(), run(), setStop(), and stopNow().

Here is the caller graph for this function:

◆ stopLock()

bool CAPlayback::stopLock ( )
inlineprivate

References _stopLock.

Referenced by stopNow().

Here is the caller graph for this function:

◆ stopNow

void CAPlayback::stopNow ( )
slot

Stop playback and clean up. Blocks until all cleanups are done.

See also
stop()

References playbackFinished(), setStopLock(), stop(), and stopLock().

Referenced by CAMainWin::deleteSelection(), initPlayback(), and CAMainWin::stopPlayback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ streamAt()

QList<CAMusElement*>& CAPlayback::streamAt ( int  idx)
inlineprivate

References _streamList.

Referenced by loopUntilPlayable(), and run().

Here is the caller graph for this function:

◆ streamIdx()

int& CAPlayback::streamIdx ( int  i)
inlineprivate

References _streamIdx.

Referenced by initStreams(), loopUntilPlayable(), and run().

Here is the caller graph for this function:

◆ streamList()

const QList< QList<CAMusElement*> >& CAPlayback::streamList ( )
inlineprivate

References _streamList.

Referenced by initStreams(), loopUntilPlayable(), and run().

Here is the caller graph for this function:

◆ updateSleepFactor()

void CAPlayback::updateSleepFactor ( CATempo t)
private

Calculates the sleep factor for the given tempo t. If t is null, it does nothing.

References _sleepFactor, CATempo::beat(), CATempo::bpm(), and CAPlayableLength::playableLengthToTimeLength().

Referenced by initStreams(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _curPlaying

QList<CAPlayable*> CAPlayback::_curPlaying
private

Referenced by curPlaying(), playSelectionImpl(), and run().

◆ _curTime

int CAPlayback::_curTime
private

◆ _initTimeStart

int CAPlayback::_initTimeStart
private

◆ _lastRepeatOpenIdx

int* CAPlayback::_lastRepeatOpenIdx
private

◆ _midiDevice

CAMidiDevice* CAPlayback::_midiDevice
private

◆ _playSelectionOnly

bool CAPlayback::_playSelectionOnly
private

Referenced by CAPlayback(), initPlayback(), and run().

◆ _repeating

bool CAPlayback::_repeating
private

◆ _selection

QList<CAMusElement*> CAPlayback::_selection
private

◆ _sheet

CASheet* CAPlayback::_sheet
private

◆ _sleepFactor

float CAPlayback::_sleepFactor
private

◆ _stop

bool CAPlayback::_stop
private

◆ _stopLock

bool CAPlayback::_stopLock
private

Referenced by initPlayback(), setStopLock(), and stopLock().

◆ _streamIdx

int* CAPlayback::_streamIdx
private

◆ _streamList

QList< QList<CAMusElement*> > CAPlayback::_streamList
private

Referenced by initStreams(), streamAt(), and streamList().


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