diff --git a/include/FadeButton.h b/include/FadeButton.h index 4cd45893a..54703d194 100644 --- a/include/FadeButton.h +++ b/include/FadeButton.h @@ -46,8 +46,8 @@ public: public slots: void activate(); + void activateOnce(); void noteEnd(); - void notPlaying(); protected: diff --git a/include/SampleTrack.h b/include/SampleTrack.h index 4624e2a39..47cc0df39 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -162,19 +162,19 @@ public: return "sampletrack"; } - bool wasPlaying() + bool isPlaying() { - return m_wasPlaying; + return m_isPlaying; } - void setWasPlaying(bool wasPlaying) + void setPlaying(bool playing) { - m_wasPlaying = wasPlaying; + if (m_isPlaying != playing) { emit playingChanged(); } + m_isPlaying = playing; } signals: - void playing(); - void notPlaying(); + void playingChanged(); public slots: void updateTcos(); @@ -186,7 +186,7 @@ private: FloatModel m_panningModel; IntModel m_effectChannelModel; AudioPort m_audioPort; - bool m_wasPlaying; + bool m_isPlaying; @@ -225,7 +225,7 @@ public: public slots: void showEffects(); - void stopPlaying(); + void updateIndicator(); protected: diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 95b8bbeb6..43f806144 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -75,6 +75,14 @@ void FadeButton::activate() +void FadeButton::activateOnce() +{ + if (activeNotes == 0) { activate(); } +} + + + + void FadeButton::noteEnd() { if (activeNotes <= 0) @@ -92,29 +100,12 @@ void FadeButton::noteEnd() m_releaseTimer.restart(); } - signalUpdate(); -} - - - - -void FadeButton::notPlaying() -{ - activeNotes = 0; - m_releaseTimer.restart(); - signalUpdate(); -} - - - - -void FadeButton::customEvent(QEvent *) -{ update(); } + void FadeButton::paintEvent(QPaintEvent * _pe) { QColor col = m_normalColor; diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 7d3bdb581..f4dbedda2 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -593,7 +593,7 @@ SampleTrack::SampleTrack( TrackContainer* tc ) : this, tr( "Panning" ) ), m_effectChannelModel( 0, 0, 0, this, tr( "FX channel" ) ), m_audioPort( tr( "Sample track" ), true, &m_volumeModel, &m_panningModel, &m_mutedModel ), - m_wasPlaying(false) + m_isPlaying(false) { setName( tr( "Sample track" ) ); m_panningModel.setCenterValue( DefaultPanning ); @@ -618,27 +618,26 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, { m_audioPort.effects()->startRunning(); bool played_a_note = false; // will be return variable - bool is_playing = false; + bool nowPlaying = false; tcoVector tcos; ::BBTrack * bb_track = NULL; if( _tco_num >= 0 ) { - if (m_wasPlaying && _start > getTCO(_tco_num)->length()) + if (_start > getTCO(_tco_num)->length()) { - m_wasPlaying = false; - emit notPlaying(); + nowPlaying = false; } if( _start != 0 ) { + nowPlaying = false; return false; } tcos.push_back( getTCO( _tco_num ) ); if (trackContainer() == (TrackContainer*)Engine::getBBTrackContainer()) { bb_track = BBTrack::findBBTrack( _tco_num ); - m_wasPlaying = true; - emit playing(); + nowPlaying = true; } } else @@ -650,10 +649,6 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, if( _start >= sTco->startPosition() && _start < sTco->endPosition() ) { - if (sTco->isPlaying()) - { - is_playing = true; - } if( sTco->isPlaying() == false && _start > sTco->startPosition() + sTco->startTimeOffset() ) { auto bufferFramesPerTick = Engine::framesPerTick (sTco->sampleBuffer ()->sampleRate ()); @@ -670,7 +665,7 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, sTco->setSamplePlayLength( samplePlayLength ); tcos.push_back( sTco ); sTco->setIsPlaying( true ); - is_playing = true; + nowPlaying = true; } } } @@ -678,20 +673,10 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, { sTco->setIsPlaying( false ); } + nowPlaying = nowPlaying || sTco->isPlaying(); } - - if (is_playing && !m_wasPlaying) - { - m_wasPlaying = true; - emit playing(); - } - else if (!is_playing && m_wasPlaying) - { - m_wasPlaying = false; - emit notPlaying(); - } - } + setPlaying(nowPlaying); for( tcoVector::Iterator it = tcos.begin(); it != tcos.end(); ++it ) { @@ -861,10 +846,7 @@ SampleTrackView::SampleTrackView( SampleTrack * _t, TrackContainerView* tcv ) : getTrackSettingsWidget()); m_activityIndicator->setGeometry(settingsWidgetWidth-2*24-11, 2, 8, 28); m_activityIndicator->show(); - connect(_t, SIGNAL(playing()), - m_activityIndicator, SLOT(activate())); - connect(_t, SIGNAL(notPlaying()), - m_activityIndicator, SLOT(notPlaying())); + connect(_t, SIGNAL(playingChanged()), this, SLOT(updateIndicator())); connect(Engine::getSong(), SIGNAL(stopped()), this, SLOT(stopPlaying())); @@ -877,6 +859,15 @@ SampleTrackView::SampleTrackView( SampleTrack * _t, TrackContainerView* tcv ) : +void SampleTrackView::updateIndicator() +{ + if (model()->isPlaying()) m_activityIndicator->activateOnce(); + else { m_activityIndicator->noteEnd(); } +} + + + + SampleTrackView::~SampleTrackView() { if(m_window != NULL) @@ -982,18 +973,6 @@ void SampleTrackView::dropEvent(QDropEvent *de) -void SampleTrackView::stopPlaying() -{ - SampleTrack * smpltrck = dynamic_cast(getTrack()); - if (smpltrck->wasPlaying()) - { - m_activityIndicator->notPlaying(); - smpltrck->setWasPlaying(false); - } -} - - - SampleTrackWindow::SampleTrackWindow(SampleTrackView * tv) : QWidget(),