Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Slots | Signals | Public Member Functions | Private Member Functions | Private Attributes
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]

List of all members.

Public Slots

void stopNow ()

Signals

void playbackFinished ()

Public Member Functions

 CAPlayback (CASheet *, CAMidiDevice *)
 CAPlayback (CAMidiDevice *, int port)
 ~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 initStreams (CASheet *sheet)
void loopUntilPlayable (int i, bool ignoreRepeats=false)
void playSelectionImpl ()
QList< CAMusElement * > streamAt (int idx)
int streamCount ()
int & streamIdx (int i)
int & curTime (int i)
int & lastRepeatOpenIdx (int i)
bool & repeating (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
QList< QList< CAMusElement * > > _stream
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.

    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::CAPlayback ( CAMidiDevice m,
int  port 
)

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

References _curTime, _lastRepeatOpenIdx, _playSelectionOnly, _repeating, _stop, _streamIdx, setMidiDevice(), setStopLock(), and stopNow().

Here is the call graph for this function:

Destructor deletes the created arrays.

References _curTime, _lastRepeatOpenIdx, _repeating, and _streamIdx.


Member Function Documentation

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

References _curPlaying.

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

Here is the caller graph for this function:

int& CAPlayback::curTime ( int  i) [inline, private]

References _curTime.

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

Here is the caller graph for this function:

References _initTimeStart.

Referenced by initStreams().

Here is the caller graph for this function:

void CAPlayback::initStreams ( CASheet sheet) [private]

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

References _curTime, _lastRepeatOpenIdx, _repeating, _stream, _streamIdx, CASheet::contextAt(), CASheet::contextCount(), CAContext::contextType(), curTime(), getInitTimeStart(), lastRepeatOpenIdx(), loopUntilPlayable(), CAVoice::midiChannel(), midiDevice(), CAVoice::midiProgram(), CAVoice::musElementList(), repeating(), CAMidiDevice::send(), CAContext::Staff, streamCount(), streamIdx(), CAStaff::voiceAt(), and CAStaff::voiceCount().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

int& CAPlayback::lastRepeatOpenIdx ( int  i) [inline, private]

References _lastRepeatOpenIdx.

Referenced by initStreams(), and loopUntilPlayable().

Here is the caller graph for this function:

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 CAMusElement::Barline, curTime(), lastRepeatOpenIdx(), CAMusElement::Note, CABarline::RepeatClose, repeating(), CABarline::RepeatOpen, streamAt(), and streamIdx().

Referenced by initStreams(), and run().

Here is the call graph for this function:

Here is the caller graph for this function:

References _midiDevice.

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

Here is the caller graph for this function:

void CAPlayback::playbackFinished ( ) [signal]

Referenced by stopNow().

Here is the caller graph for this function:

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:

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, _selection, _stop, curTime(), CANote::diatonicPitch(), CAMidiDevice::diatonicPitchToMidiPitch(), CAVoice::midiChannel(), midiDevice(), 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:

bool& CAPlayback::repeating ( int  i) [inline, private]

References _repeating.

Referenced by initStreams(), and loopUntilPlayable().

Here is the caller graph for this function:

void CAPlayback::run ( )
void CAPlayback::setInitTimeStart ( int  t) [inline]

References _initTimeStart.

Referenced by CAPlayback(), and CAMainWin::on_uiPlayFromSelection_toggled().

Here is the caller graph for this function:

void CAPlayback::setMidiDevice ( CAMidiDevice d) [inline, private]

References _midiDevice.

Referenced by CAPlayback().

Here is the caller graph for this function:

void CAPlayback::setSheet ( CASheet s) [inline]

References _sheet.

Referenced by CAPlayback().

Here is the caller graph for this function:

void CAPlayback::setStop ( bool  stop) [inline, private]

References _stop, and stop().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

void CAPlayback::setStopLock ( bool  lock) [inline, private]

References _stopLock.

Referenced by CAPlayback(), and stopNow().

Here is the caller graph for this function:

CASheet* CAPlayback::sheet ( ) [inline]

References _sheet.

Referenced by run().

Here is the caller graph for this function:

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:

bool CAPlayback::stopLock ( ) [inline, private]

References _stopLock.

Referenced by stopNow().

Here is the caller graph for this function:

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 CAPlayback(), CAMainWin::deleteSelection(), and CAMainWin::stopPlayback().

Here is the call graph for this function:

Here is the caller graph for this function:

QList<CAMusElement*> CAPlayback::streamAt ( int  idx) [inline, private]

References _stream.

Referenced by loopUntilPlayable(), and run().

Here is the caller graph for this function:

int CAPlayback::streamCount ( ) [inline, private]

References _stream.

Referenced by initStreams(), and run().

Here is the caller graph for this function:

int& CAPlayback::streamIdx ( int  i) [inline, private]

References _streamIdx.

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

Here is the caller graph for this function:


Member Data Documentation

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

int* CAPlayback::_curTime [private]

Referenced by midiDevice(), and setMidiDevice().

Referenced by CAPlayback(), and run().

bool* CAPlayback::_repeating [private]

Referenced by setSheet(), and sheet().

bool CAPlayback::_stop [private]
bool CAPlayback::_stopLock [private]

Referenced by setStopLock(), and stopLock().

QList< QList<CAMusElement*> > CAPlayback::_stream [private]

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

int* CAPlayback::_streamIdx [private]

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