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.
This commit is contained in:
Tobias Doerffel
2014-09-30 22:34:01 +02:00
parent 53f240852d
commit fab7f8fea8
4 changed files with 29 additions and 14 deletions

View File

@@ -164,6 +164,9 @@ protected slots:
void changeNoteEditMode( int i );
void markSemiTone( int i );
void hidePattern( pattern* p );
signals:
void currentPatternChanged();
void semiToneMarkerMenuScaleSetEnabled(bool);

View File

@@ -140,6 +140,10 @@ private:
friend class patternView;
friend class bbEditor;
signals:
void destroyedPattern( pattern* );
} ;

View File

@@ -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 )
{

View File

@@ -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 );
}
}
}