From c60e7ba8d1a589e66f4bb9ef4c09726b1d6c594f Mon Sep 17 00:00:00 2001 From: Alexandre Almeida Date: Sun, 20 May 2012 18:23:43 +0200 Subject: [PATCH] Song, SongEditor, BB-Editor, Piano-Roll: correction of play button problems Initial implementation of corrected play buttons in individual editor windows. --- include/AutomationEditor.h | 2 + include/bb_editor.h | 2 + include/engine.h | 2 + include/piano_roll.h | 2 + include/song.h | 28 ++-- include/song_editor.h | 2 + src/core/bb_track_container.cpp | 23 +-- src/core/engine.cpp | 11 ++ src/core/song.cpp | 250 ++++++++++++++------------------ src/gui/AutomationEditor.cpp | 63 ++++---- src/gui/bb_editor.cpp | 49 ++++--- src/gui/piano_roll.cpp | 49 ++++--- src/gui/song_editor.cpp | 33 ++++- 13 files changed, 246 insertions(+), 270 deletions(-) diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index 1a90f2a7f..a7bc0b9dd 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -72,6 +72,8 @@ public: return( "automationeditor" ); } + void updatePlayPauseIcon(); + public slots: void update(); diff --git a/include/bb_editor.h b/include/bb_editor.h index 957058888..b7a91a704 100644 --- a/include/bb_editor.h +++ b/include/bb_editor.h @@ -48,6 +48,8 @@ public: void removeBBView( int _bb ); + void updatePlayPauseIcon(); + public slots: void play(); diff --git a/include/engine.h b/include/engine.h index adbbdc33d..5c0d64199 100644 --- a/include/engine.h +++ b/include/engine.h @@ -147,6 +147,8 @@ public: return s_controllerRackView; } + static void updatePlayPauseIcons(); + static float framesPerTick() { return s_framesPerTick; diff --git a/include/piano_roll.h b/include/piano_roll.h index 3bb1c5d68..0288ce84e 100644 --- a/include/piano_roll.h +++ b/include/piano_roll.h @@ -90,6 +90,8 @@ public: return "pianoroll"; } + void updatePlayPauseIcon(); + protected: virtual void closeEvent( QCloseEvent * _ce ); diff --git a/include/song.h b/include/song.h index 3b129714e..994d70fea 100644 --- a/include/song.h +++ b/include/song.h @@ -54,6 +54,7 @@ class EXPORT song : public trackContainer public: enum PlayModes { + Mode_None, Mode_PlaySong, Mode_PlayTrack, Mode_PlayBB, @@ -104,6 +105,11 @@ public: return m_playing && m_exporting == false; } + inline bool isStopped() const + { + return m_playing == false && m_paused == false; + } + bool isFreezingPattern() const; inline bool isExporting() const @@ -196,15 +202,14 @@ public: public slots: - void play(); + void playSong(); void record(); void playAndRecord(); - void stop(); void playTrack( track * _trackToPlay ); void playBB(); void playPattern( pattern * _patternToPlay, bool _loop = true ); - void pause(); - void resumeFromPause(); + void togglePause(); + void stop(); void importProject(); void exportProject(); @@ -231,7 +236,7 @@ private slots: void masterVolumeChanged(); - void doActions(); + void savePos(); void updateFramesPerTick(); @@ -296,19 +301,6 @@ private: bool m_loopPattern; - enum Actions - { - ActionStop, - ActionPlaySong, - ActionPlayTrack, - ActionPlayBB, - ActionPlayPattern, - ActionPause, - ActionResumeFromPause - } ; - QVector m_actions; - - friend class engine; friend class songEditor; friend class mainWindow; diff --git a/include/song_editor.h b/include/song_editor.h index 82d507065..f69530af3 100644 --- a/include/song_editor.h +++ b/include/song_editor.h @@ -63,6 +63,8 @@ public: public slots: void scrolled( int _new_pos ); + void updatePlayPauseIcon(); + private slots: void setHighQuality( bool ); diff --git a/src/core/bb_track_container.cpp b/src/core/bb_track_container.cpp index f95e8211d..b016ac15f 100644 --- a/src/core/bb_track_container.cpp +++ b/src/core/bb_track_container.cpp @@ -183,27 +183,14 @@ void bbTrackContainer::fixIncorrectPositions() void bbTrackContainer::play() { - if( engine::getSong()->isPlaying() ) - { - if( engine::getSong()->playMode() != song::Mode_PlayBB ) - { - engine::getSong()->stop(); - engine::getSong()->playBB(); - } - else - { - engine::getSong()->pause(); - } - } - else if( engine::getSong()->isPaused() ) - { - engine::getSong()->resumeFromPause(); - } - else + if( engine::getSong()->playMode() != song::Mode_PlayBB ) { engine::getSong()->playBB(); } - + else + { + engine::getSong()->togglePause(); + } } diff --git a/src/core/engine.cpp b/src/core/engine.cpp index 14a586d9d..5dad25e9f 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -148,6 +148,17 @@ void engine::destroy() +void engine::updatePlayPauseIcons() +{ + s_songEditor->updatePlayPauseIcon(); + s_automationEditor->updatePlayPauseIcon(); + s_bbEditor->updatePlayPauseIcon(); + s_pianoRoll->updatePlayPauseIcon(); +} + + + + void engine::updateFramesPerTick() { s_framesPerTick = s_mixer->processingSampleRate() * 60.0f * 4 / diff --git a/src/core/song.cpp b/src/core/song.cpp index 8962e73e7..eb2139de8 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -84,7 +84,7 @@ song::song() : m_playing( false ), m_paused( false ), m_loadingProject( false ), - m_playMode( Mode_PlaySong ), + m_playMode( Mode_None ), m_length( 0 ), m_trackToPlay( NULL ), m_patternToPlay( NULL ), @@ -167,115 +167,14 @@ void song::setTimeSignature() -void song::doActions() +void song::savePos() { - while( !m_actions.empty() ) + timeLine * tl = m_playPos[m_playMode].m_timeLine; + + if( tl != NULL ) { - switch( m_actions.front() ) - { - case ActionStop: - { - timeLine * tl = - m_playPos[m_playMode].m_timeLine; - m_playing = false; - m_recording = true; - if( tl != NULL ) - { - - switch( tl->behaviourAtStop() ) - { - case timeLine::BackToZero: - m_playPos[m_playMode].setTicks( 0 ); - break; - - case timeLine::BackToStart: - if( tl->savedPos() >= 0 ) - { - m_playPos[m_playMode].setTicks( - tl->savedPos().getTicks() ); - tl->savePos( -1 ); - } - break; - - case timeLine::KeepStopPosition: - default: - break; - } - - } - else - { - m_playPos[m_playMode].setTicks( 0 ); - } - - m_playPos[m_playMode].setCurrentFrame( 0 ); - - // remove all note-play-handles that are active - engine::getMixer()->clear(); - - break; - } - - case ActionPlaySong: - m_playMode = Mode_PlaySong; - m_playing = true; - Controller::resetFrameCounter(); - break; - - case ActionPlayTrack: - m_playMode = Mode_PlayTrack; - m_playing = true; - break; - - case ActionPlayBB: - m_playMode = Mode_PlayBB; - m_playing = true; - break; - - case ActionPlayPattern: - m_playMode = Mode_PlayPattern; - m_playing = true; - break; - - case ActionPause: - m_playing = false;// just set the play-flag - m_paused = true; - break; - - case ActionResumeFromPause: - m_playing = true;// just set the play-flag - m_paused = false; - break; - } - - // a second switch for saving pos when starting to play - // anything (need pos for restoring it later in certain - // timeline-modes) - switch( m_actions.front() ) - { - case ActionPlaySong: - case ActionPlayTrack: - case ActionPlayBB: - case ActionPlayPattern: - { - timeLine * tl = - m_playPos[m_playMode].m_timeLine; - if( tl != NULL ) - { - tl->savePos( m_playPos[m_playMode] ); - } - break; - } - - // keep GCC happy... - default: - break; - } - - m_actions.erase( m_actions.begin() ); - + tl->savePos( m_playPos[m_playMode] ); } - } @@ -283,8 +182,6 @@ void song::doActions() void song::processNextBuffer() { - doActions(); - if( m_playing == false ) { return; @@ -488,24 +385,22 @@ bool song::realTimeTask() const -void song::play() +void song::playSong() { m_recording = false; - if( m_playing == true ) + + if( isStopped() == false ) { - if( m_playMode != Mode_PlaySong ) - { - // make sure, bb-editor updates/resets it play-button - engine::getBBTrackContainer()->stop(); - //pianoRoll::inst()->stop(); - } - else - { - pause(); - return; - } + stop(); } - m_actions.push_back( ActionPlaySong ); + + m_playMode = Mode_PlaySong; + m_playing = true; + m_paused = false; + + savePos(); + + engine::updatePlayPauseIcons(); } @@ -522,7 +417,7 @@ void song::record() void song::playAndRecord() { - play(); + playSong(); m_recording = true; } @@ -531,13 +426,19 @@ void song::playAndRecord() void song::playTrack( track * _trackToPlay ) { - if( m_playing == true ) + if( isStopped() == false ) { stop(); } m_trackToPlay = _trackToPlay; - m_actions.push_back( ActionPlayTrack ); + m_playMode = Mode_PlayTrack; + m_playing = true; + m_paused = false; + + savePos(); + + engine::updatePlayPauseIcons(); } @@ -545,11 +446,18 @@ void song::playTrack( track * _trackToPlay ) void song::playBB() { - if( m_playing == true ) + if( isStopped() == false ) { stop(); } - m_actions.push_back( ActionPlayBB ); + + m_playMode = Mode_PlayBB; + m_playing = true; + m_paused = false; + + savePos(); + + engine::updatePlayPauseIcons(); } @@ -557,16 +465,24 @@ void song::playBB() void song::playPattern( pattern * _patternToPlay, bool _loop ) { - if( m_playing == true ) + if( isStopped() == false ) { stop(); } + m_patternToPlay = _patternToPlay; m_loopPattern = _loop; + if( m_patternToPlay != NULL ) { - m_actions.push_back( ActionPlayPattern ); + m_playMode = Mode_PlayPattern; + m_playing = true; + m_paused = false; } + + savePos(); + + engine::updatePlayPauseIcons(); } @@ -602,27 +518,68 @@ void song::setPlayPos( tick_t _ticks, PlayModes _play_mode ) +void song::togglePause() +{ + if( m_paused == true ) + { + m_playing = true; + m_paused = false; + } + else + { + m_playing = false; + m_paused = true; + } + + engine::updatePlayPauseIcons(); +} + + + + void song::stop() { - m_actions.push_back( ActionStop ); -} + timeLine * tl = m_playPos[m_playMode].m_timeLine; + m_playing = false; + m_paused = false; + m_recording = true; + if( tl != NULL ) + { + switch( tl->behaviourAtStop() ) + { + case timeLine::BackToZero: + m_playPos[m_playMode].setTicks( 0 ); + break; + case timeLine::BackToStart: + if( tl->savedPos() >= 0 ) + { + m_playPos[m_playMode].setTicks( + tl->savedPos().getTicks() ); + tl->savePos( -1 ); + } + break; + case timeLine::KeepStopPosition: + default: + break; + } + } + else + { + m_playPos[m_playMode].setTicks( 0 ); + } + m_playPos[m_playMode].setCurrentFrame( 0 ); -void song::pause() -{ - m_actions.push_back( ActionPause ); -} + // remove all note-play-handles that are active + engine::getMixer()->clear(); + m_playMode = Mode_None; - - -void song::resumeFromPause() -{ - m_actions.push_back( ActionResumeFromPause ); + engine::updatePlayPauseIcons(); } @@ -631,10 +588,8 @@ void song::resumeFromPause() void song::startExport() { stop(); - doActions(); - play(); - doActions(); + playSong(); m_exporting = true; } @@ -736,6 +691,12 @@ void song::clearProject() stop(); } + for( int i = 0; i < Mode_Count; i++ ) + { + setPlayPos( 0, ( PlayModes )i ); + } + + engine::getMixer()->lock(); if( engine::getBBEditor() ) { @@ -800,6 +761,7 @@ void song::createNewProject() { QString default_template = configManager::inst()->userProjectsDir() + "templates/default.mpt"; + if( QFile::exists( default_template ) ) { createNewProjectFromTemplate( default_template ); diff --git a/src/gui/AutomationEditor.cpp b/src/gui/AutomationEditor.cpp index 3a597e784..cef8a89c8 100644 --- a/src/gui/AutomationEditor.cpp +++ b/src/gui/AutomationEditor.cpp @@ -413,6 +413,28 @@ void AutomationEditor::loadSettings( const QDomElement & _this ) +void AutomationEditor::updatePlayPauseIcon() +{ + if( engine::getSong()->playMode() != song::Mode_PlayPattern ) + { + m_playButton->setIcon( embed::getIconPixmap( "play" ) ); + } + else + { + if( engine::getSong()->isPlaying() ) + { + m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); + } + else + { + m_playButton->setIcon( embed::getIconPixmap( "play" ) ); + } + } +} + + + + void AutomationEditor::updateAfterPatternChange() { QMutexLocker m( &m_patternMutex ); @@ -1712,59 +1734,30 @@ void AutomationEditor::play() engine::getSong()->stop(); engine::getSong()->playPattern( (pattern *) engine::getPianoRoll()->currentPattern() ); - m_playButton->setIcon( embed::getIconPixmap( - "pause" ) ); } - else if( engine::getSong()->isPlaying() ) + else if( engine::getSong()->isStopped() == false ) { - engine::getSong()->pause(); - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); - } - else if( engine::getSong()->isPaused() ) - { - engine::getSong()->resumeFromPause(); - m_playButton->setIcon( embed::getIconPixmap( - "pause" ) ); + engine::getSong()->togglePause(); } else { - m_playButton->setIcon( embed::getIconPixmap( - "pause" ) ); engine::getSong()->playPattern( (pattern *) engine::getPianoRoll()->currentPattern() ); } } else if( inBBEditor() ) { - if( engine::getSong()->isPlaying() ) - { - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); - } - else - { - m_playButton->setIcon( embed::getIconPixmap( - "pause" ) ); - } engine::getBBTrackContainer()->play(); } else { - if( engine::getSong()->isPlaying() ) + if( engine::getSong()->isStopped() == true ) { - engine::getSong()->pause(); - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); - } - else if( engine::getSong()->isPaused() ) - { - engine::getSong()->resumeFromPause(); - m_playButton->setIcon( embed::getIconPixmap( - "pause" ) ); + engine::getSong()->playSong(); } else { - m_playButton->setIcon( embed::getIconPixmap( - "pause" ) ); - engine::getSong()->play(); + engine::getSong()->togglePause(); } } } @@ -1788,8 +1781,6 @@ void AutomationEditor::stop() { engine::getSong()->stop(); } - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); - m_playButton->update(); m_scrollBack = TRUE; } diff --git a/src/gui/bb_editor.cpp b/src/gui/bb_editor.cpp index 8c127606a..9104e2e94 100644 --- a/src/gui/bb_editor.cpp +++ b/src/gui/bb_editor.cpp @@ -157,35 +157,38 @@ void bbEditor::removeBBView( int _bb ) -void bbEditor::play() +void bbEditor::updatePlayPauseIcon() { - if( engine::getSong()->isPlaying() ) + if( engine::getSong()->playMode() != song::Mode_PlayBB ) { - if( engine::getSong()->playMode() != song::Mode_PlayBB ) - { - engine::getSong()->stop(); - engine::getSong()->playBB(); - m_playButton->setIcon( embed::getIconPixmap( - "pause" ) ); - } - else - { - engine::getSong()->pause(); - m_playButton->setIcon( embed::getIconPixmap( - "play" ) ); - } - } - else if( engine::getSong()->isPaused() ) - { - engine::getSong()->resumeFromPause(); - m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); + m_playButton->setIcon( embed::getIconPixmap( "play" ) ); } else { - m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); + if( engine::getSong()->isPlaying() ) + { + m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); + } + else + { + m_playButton->setIcon( embed::getIconPixmap( "play" ) ); + } + } +} + + + + +void bbEditor::play() +{ + if( engine::getSong()->playMode() != song::Mode_PlayBB ) + { engine::getSong()->playBB(); } - + else + { + engine::getSong()->togglePause(); + } } @@ -194,8 +197,6 @@ void bbEditor::play() void bbEditor::stop() { engine::getSong()->stop(); - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); - m_playButton->update(); } diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index 27c54bffd..13f4753d1 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -776,6 +776,28 @@ void pianoRoll::loadSettings( const QDomElement & _this ) +void pianoRoll::updatePlayPauseIcon() +{ + if( engine::getSong()->playMode() != song::Mode_PlayPattern ) + { + m_playButton->setIcon( embed::getIconPixmap( "play" ) ); + } + else + { + if( engine::getSong()->isPlaying() ) + { + m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); + } + else + { + m_playButton->setIcon( embed::getIconPixmap( "play" ) ); + } + } +} + + + + inline void pianoRoll::drawNoteRect( QPainter & _p, int _x, int _y, int _width, note * _n ) { @@ -3222,30 +3244,13 @@ void pianoRoll::play() return; } - if( engine::getSong()->isPlaying() ) + if( engine::getSong()->playMode() != song::Mode_PlayPattern ) { - if( engine::getSong()->playMode() != song::Mode_PlayPattern ) - { - engine::getSong()->stop(); - engine::getSong()->playPattern( m_pattern ); - m_playButton->setIcon( embed::getIconPixmap( - "pause" ) ); - } - else - { - engine::getSong()->pause(); - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); - } - } - else if( engine::getSong()->isPaused() ) - { - engine::getSong()->resumeFromPause(); - m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); + engine::getSong()->playPattern( m_pattern ); } else { - m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); - engine::getSong()->playPattern( m_pattern ); + engine::getSong()->togglePause(); } } @@ -3286,7 +3291,7 @@ void pianoRoll::recordAccompany() if( m_pattern->getTrack()->getTrackContainer() == engine::getSong() ) { - engine::getSong()->play(); + engine::getSong()->playSong(); } else { @@ -3301,8 +3306,6 @@ void pianoRoll::recordAccompany() void pianoRoll::stop() { engine::getSong()->stop(); - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); - m_playButton->update(); m_recording = false; m_scrollBack = true; } diff --git a/src/gui/song_editor.cpp b/src/gui/song_editor.cpp index cd1bba8cc..492f1e29a 100644 --- a/src/gui/song_editor.cpp +++ b/src/gui/song_editor.cpp @@ -423,17 +423,37 @@ void songEditor::scrolled( int _new_pos ) -void songEditor::play() +void songEditor::updatePlayPauseIcon() { - m_s->play(); - engine::getPianoRoll()->stopRecording(); - if( m_s->playMode() == song::Mode_PlaySong ) + if( engine::getSong()->playMode() != song::Mode_PlaySong ) { - m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); + m_playButton->setIcon( embed::getIconPixmap( "play" ) ); } else { - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); + if( engine::getSong()->isPlaying() ) + { + m_playButton->setIcon( embed::getIconPixmap( "pause" ) ); + } + else + { + m_playButton->setIcon( embed::getIconPixmap( "play" ) ); + } + } +} + + + + +void songEditor::play() +{ + if( engine::getSong()->playMode() != song::Mode_PlaySong ) + { + engine::getSong()->playSong(); + } + else + { + engine::getSong()->togglePause(); } } @@ -460,7 +480,6 @@ void songEditor::stop() { m_s->stop(); engine::getPianoRoll()->stopRecording(); - m_playButton->setIcon( embed::getIconPixmap( "play" ) ); }