|
Canorus
0.0
|
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>

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) |
| CAMidiDevice * | midiDevice () |
| CASheet * | sheet () |
| 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 |
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().
| CAPlayback::CAPlayback | ( | CASheet * | s, |
| CAMidiDevice * | m | ||
| ) |
References _midiDevice, _playSelectionOnly, _sheet, and initPlayback().

| CAPlayback::CAPlayback | ( | CAMidiDevice * | m | ) |
Plays the list of music elements simultaniously. It only takes notes into account.
References _midiDevice, _playSelectionOnly, and initPlayback().

| CAPlayback::~CAPlayback | ( | ) |
Destructor deletes the created arrays.
References _lastRepeatOpenIdx, and _streamIdx.
|
inline |
References _curPlaying.
Referenced by CAMainWin::deleteSelection(), and CAMainWin::onRepaintTimerTimeout().

|
inline |
|
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().


|
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().


|
inlineprivate |
References _lastRepeatOpenIdx.
Referenced by initStreams(), and loopUntilPlayable().

|
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().


|
inline |
References _midiDevice.
Referenced by initStreams(), loopUntilPlayable(), playImmediately(), playSelectionImpl(), and run().

|
signal |
| void CAPlayback::playImmediately | ( | QList< CAMusElement * > | elts, |
| int | port | ||
| ) |
Immediately plays the given elts.
References _selection, midiDevice(), and CAMidiDevice::openOutputPort().
Referenced by CAMainWin::playImmediately().


|
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().


| void CAPlayback::run | ( | ) |
References _curPlaying, _curTime, _playSelectionOnly, _sleepFactor, _stop, CATempo::bpm(), CANote::diatonicPitch(), CADiatonicPitch::diatonicPitchToMidiPitch(), CAMark::Dynamic, initStreams(), CAInstrumentChange::instrument(), CAMark::InstrumentChange, loopUntilPlayable(), CAMusElement::markList(), CAMidiDevice::Meta_Tempo, CAMidiDevice::Midi_Ctl_Volume, CAVoice::midiChannel(), midiDevice(), CAVoice::midiPitchOffset(), CAMusElement::musElementType(), CASlur::noteEnd(), playSelectionImpl(), CAMusElement::Rest, CAMidiDevice::send(), CAMidiDevice::sendMetaEvent(), setStop(), sheet(), stop(), streamAt(), streamIdx(), streamList(), CAMark::Tempo, CANote::tieEnd(), CANote::tieStart(), updateSleepFactor(), and CAPlayable::voice().
Referenced by CAMidiExport::exportDocumentImpl(), and CAMidiExport::exportSheetImpl().


|
inline |
References _initTimeStart.
Referenced by CAMainWin::on_uiPlayFromSelection_toggled().

|
inlineprivate |
References _midiDevice.
|
inlineprivate |
|
inlineprivate |
|
inline |
References _sheet.
Referenced by initStreams(), and run().

| void CAPlayback::stop | ( | ) |
The nice and the right way to stop the playback. Returns immediately.
References _stop.
Referenced by CAMainWin::on_uiPlayFromSelection_toggled(), playSelectionImpl(), run(), setStop(), and stopNow().

|
inlineprivate |
|
slot |
Stop playback and clean up. Blocks until all cleanups are done.
References playbackFinished(), setStopLock(), stop(), and stopLock().
Referenced by CAMainWin::deleteSelection(), initPlayback(), and CAMainWin::stopPlayback().


|
inlineprivate |
References _streamList.
Referenced by loopUntilPlayable(), and run().

|
inlineprivate |
References _streamIdx.
Referenced by initStreams(), loopUntilPlayable(), and run().

|
inlineprivate |
References _streamList.
Referenced by initStreams(), loopUntilPlayable(), and run().

|
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().


|
private |
Referenced by curPlaying(), playSelectionImpl(), and run().
|
private |
Referenced by initPlayback(), initStreams(), loopUntilPlayable(), playSelectionImpl(), and run().
|
private |
Referenced by getInitTimeStart(), initPlayback(), and setInitTimeStart().
|
private |
Referenced by initPlayback(), initStreams(), lastRepeatOpenIdx(), and ~CAPlayback().
|
private |
Referenced by CAPlayback(), initPlayback(), midiDevice(), and setMidiDevice().
|
private |
Referenced by CAPlayback(), initPlayback(), and run().
|
private |
Referenced by initPlayback(), initStreams(), and loopUntilPlayable().
|
private |
Referenced by playImmediately(), and playSelectionImpl().
|
private |
Referenced by CAPlayback(), initPlayback(), initStreams(), setSheet(), and sheet().
|
private |
Referenced by initPlayback(), run(), and updateSleepFactor().
|
private |
Referenced by initPlayback(), playSelectionImpl(), run(), setStop(), and stop().
|
private |
Referenced by initPlayback(), setStopLock(), and stopLock().
|
private |
Referenced by initPlayback(), initStreams(), streamIdx(), and ~CAPlayback().
|
private |
Referenced by initStreams(), streamAt(), and streamList().