From fab7f8fea8cceac7ea6f7015ffb7cd8b9a51cefd Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Tue, 30 Sep 2014 22:34:01 +0200 Subject: [PATCH] PianoRoll, Pattern: manage reset of currently edited pattern more reliably Introduce one central signal in the pattern class which is emitted before the pattern object is being destroyed. This way we can easily and more reliably hide this pattern in the PianoRoll without any race conditions or other glitches. Closes #1089. --- include/PianoRoll.h | 3 +++ include/pattern.h | 4 ++++ src/gui/PianoRoll.cpp | 20 ++++++++++++++++++++ src/tracks/pattern.cpp | 16 ++-------------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/include/PianoRoll.h b/include/PianoRoll.h index 157f3b051..ea9aa0387 100644 --- a/include/PianoRoll.h +++ b/include/PianoRoll.h @@ -164,6 +164,9 @@ protected slots: void changeNoteEditMode( int i ); void markSemiTone( int i ); + void hidePattern( pattern* p ); + + signals: void currentPatternChanged(); void semiToneMarkerMenuScaleSetEnabled(bool); diff --git a/include/pattern.h b/include/pattern.h index 2fff9697e..8db698370 100644 --- a/include/pattern.h +++ b/include/pattern.h @@ -140,6 +140,10 @@ private: friend class patternView; friend class bbEditor; + +signals: + void destroyedPattern( pattern* ); + } ; diff --git a/src/gui/PianoRoll.cpp b/src/gui/PianoRoll.cpp index 3fb1c64e6..abccc5e87 100644 --- a/src/gui/PianoRoll.cpp +++ b/src/gui/PianoRoll.cpp @@ -794,6 +794,14 @@ void PianoRoll::setCurrentPattern( pattern * _new_pattern ) m_pattern->instrumentTrack()->disconnect( this ); } + // force the song-editor to stop playing if it played pattern before + if( engine::getSong()->isPlaying() && + engine::getSong()->playMode() == song::Mode_PlayPattern ) + { + engine::getSong()->playPattern( NULL ); + } + + // set new data m_pattern = _new_pattern; m_currentPosition = 0; m_currentNote = NULL; @@ -840,6 +848,9 @@ void PianoRoll::setCurrentPattern( pattern * _new_pattern ) // of start-notes and so on...) resizeEvent( NULL ); + // make sure to always get informed about the pattern being destroyed + connect( m_pattern, SIGNAL( destroyedPattern( pattern* ) ), this, SLOT( hidePattern( pattern* ) ) ); + connect( m_pattern->instrumentTrack(), SIGNAL( midiNoteOn( const note& ) ), this, SLOT( startRecordNote( const note& ) ) ); connect( m_pattern->instrumentTrack(), SIGNAL( midiNoteOff( const note& ) ), this, SLOT( finishRecordNote( const note& ) ) ); connect( m_pattern->instrumentTrack()->pianoModel(), SIGNAL( dataChanged() ), this, SLOT( update() ) ); @@ -852,6 +863,15 @@ void PianoRoll::setCurrentPattern( pattern * _new_pattern ) +void PianoRoll::hidePattern( pattern* p ) +{ + if( m_pattern == p ) + { + setCurrentPattern( NULL ); + } +} + + void PianoRoll::saveSettings( QDomDocument & _doc, QDomElement & _this ) { diff --git a/src/tracks/pattern.cpp b/src/tracks/pattern.cpp index ae38f9651..fe74d1872 100644 --- a/src/tracks/pattern.cpp +++ b/src/tracks/pattern.cpp @@ -89,6 +89,8 @@ pattern::pattern( const pattern & _pat_to_copy ) : pattern::~pattern() { + emit destroyedPattern( this ); + for( NoteVector::Iterator it = m_notes.begin(); it != m_notes.end(); ++it ) { @@ -649,20 +651,6 @@ patternView::patternView( pattern * _pattern, trackView * _parent ) : patternView::~patternView() { - if( engine::pianoRoll()->currentPattern() == m_pat ) - { - engine::pianoRoll()->disconnect( this ); - - engine::pianoRoll()->setCurrentPattern( NULL ); - // we have to have the song-editor to stop playing if it played - // us before - if( engine::getSong()->isPlaying() && - engine::getSong()->playMode() == - song::Mode_PlayPattern ) - { - engine::getSong()->playPattern( NULL ); - } - } }