From 2c5cda563b4985659a7408008915f0e4e0f85edb Mon Sep 17 00:00:00 2001 From: DomClark Date: Tue, 14 Aug 2018 21:37:22 +0100 Subject: [PATCH] Fix kVstTransportChanged flag usage in VST sync Changed according to feedback from AudioBlast. The flag used to be set most of the time, now it is only set when playback starts/stops, looping is toggled, or playback jumps around. --- include/Song.h | 9 +++++++++ include/VstSyncController.h | 6 ++++++ include/VstSyncData.h | 1 + plugins/vst_base/RemoteVstPlugin.cpp | 12 +++++++++++- src/core/Song.cpp | 24 +++++++++++++++++++++--- src/gui/TimeLineWidget.cpp | 1 + 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/include/Song.h b/include/Song.h index 0ba8a3503..08c99af47 100644 --- a/include/Song.h +++ b/include/Song.h @@ -87,10 +87,19 @@ public: { return m_currentFrame; } + inline void setJumped( const bool jumped ) + { + m_jumped = jumped; + } + inline bool jumped() const + { + return m_jumped; + } TimeLineWidget * m_timeLine; private: float m_currentFrame; + bool m_jumped; } ; diff --git a/include/VstSyncController.h b/include/VstSyncController.h index b969ebbbe..e858f5545 100644 --- a/include/VstSyncController.h +++ b/include/VstSyncController.h @@ -61,6 +61,11 @@ public: m_syncData->isCycle = false; } + void setPlaybackJumped( bool jumped ) + { + m_syncData->m_playbackJumped = jumped; + } + void update(); @@ -79,6 +84,7 @@ private: bool hasSHM; float cycleStart; float cycleEnd; + bool m_playbackJumped; int m_bufferSize; int m_sampleRate; int m_bpm; diff --git a/include/VstSyncData.h b/include/VstSyncData.h index a4c5db80b..d8694f1b2 100644 --- a/include/VstSyncData.h +++ b/include/VstSyncData.h @@ -49,6 +49,7 @@ struct VstSyncData bool hasSHM; float cycleStart; float cycleEnd; + bool m_playbackJumped; int m_bufferSize; int m_sampleRate; int m_bpm; diff --git a/plugins/vst_base/RemoteVstPlugin.cpp b/plugins/vst_base/RemoteVstPlugin.cpp index e0b51381e..1e810f0b7 100644 --- a/plugins/vst_base/RemoteVstPlugin.cpp +++ b/plugins/vst_base/RemoteVstPlugin.cpp @@ -396,6 +396,7 @@ private: { float lastppqPos; float m_Timestamp; + int32_t m_lastFlags; } ; in * m_in; @@ -478,12 +479,14 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) : m_vstSyncData->ppqPos = 0; m_vstSyncData->isCycle = false; m_vstSyncData->hasSHM = false; + m_vstSyncData->m_playbackJumped = false; m_vstSyncData->m_sampleRate = sampleRate(); } m_in = ( in* ) new char[ sizeof( in ) ]; m_in->lastppqPos = 0; m_in->m_Timestamp = -1; + m_in->m_lastFlags = 0; // process until we have loaded the plugin while( 1 ) @@ -1588,7 +1591,6 @@ intptr_t RemoteVstPlugin::hostCallback( AEffect * _effect, int32_t _opcode, __plugin->m_in->m_Timestamp ) { _timeInfo.ppqPos = __plugin->m_vstSyncData->ppqPos; - _timeInfo.flags |= kVstTransportChanged; __plugin->m_in->lastppqPos = __plugin->m_vstSyncData->ppqPos; __plugin->m_in->m_Timestamp = __plugin->m_vstSyncData->ppqPos; } @@ -1615,6 +1617,14 @@ intptr_t RemoteVstPlugin::hostCallback( AEffect * _effect, int32_t _opcode, _timeInfo.flags |= kVstBarsValid; + if( ( _timeInfo.flags & ( kVstTransportPlaying | kVstTransportCycleActive ) ) != + ( __plugin->m_in->m_lastFlags & ( kVstTransportPlaying | kVstTransportCycleActive ) ) + || __plugin->m_vstSyncData->m_playbackJumped ) + { + _timeInfo.flags |= kVstTransportChanged; + } + __plugin->m_in->m_lastFlags = _timeInfo.flags; + #ifdef LMMS_BUILD_WIN64 return (long long) &_timeInfo; #else diff --git a/src/core/Song.cpp b/src/core/Song.cpp index be0c7dddc..217a8752e 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -193,6 +193,8 @@ void Song::savePos() void Song::processNextBuffer() { + m_vstSyncController.setPlaybackJumped( false ); + // if not playing, nothing to do if( m_playing == false ) { @@ -262,10 +264,21 @@ void Song::processNextBuffer() ( tl->loopBegin().getTicks() * 60 * 1000 / 48 ) / getTempo(); m_playPos[m_playMode].setTicks( tl->loopBegin().getTicks() ); + + m_vstSyncController.setAbsolutePosition( + tl->loopBegin().getTicks() ); + m_vstSyncController.setPlaybackJumped( true ); + emit updateSampleTracks(); } } + if( m_playPos[m_playMode].jumped() ) + { + m_vstSyncController.setPlaybackJumped( true ); + m_playPos[m_playMode].setJumped( false ); + } + f_cnt_t framesPlayed = 0; const float framesPerTick = Engine::framesPerTick(); @@ -320,6 +333,7 @@ void Song::processNextBuffer() ( ticks * 60 * 1000 / 48 ) / getTempo(); m_vstSyncController.setAbsolutePosition( ticks ); + m_vstSyncController.setPlaybackJumped( true ); } } m_playPos[m_playMode].setTicks( ticks ); @@ -334,11 +348,14 @@ void Song::processNextBuffer() // beginning of the range if( m_playPos[m_playMode] >= tl->loopEnd() ) { - m_playPos[m_playMode].setTicks( tl->loopBegin().getTicks() ); + ticks = tl->loopBegin().getTicks(); + m_playPos[m_playMode].setTicks( ticks ); m_elapsedMilliSeconds = - ( ( tl->loopBegin().getTicks() ) * 60 * 1000 / 48 ) / - getTempo(); + ( ticks * 60 * 1000 / 48 ) / getTempo(); + + m_vstSyncController.setAbsolutePosition( ticks ); + m_vstSyncController.setPlaybackJumped( true ); } else if( m_playPos[m_playMode] == tl->loopEnd() - 1 ) { @@ -609,6 +626,7 @@ void Song::setPlayPos( tick_t ticks, PlayModes playMode ) getTempo() ); m_playPos[playMode].setTicks( ticks ); m_playPos[playMode].setCurrentFrame( 0.0f ); + m_playPos[playMode].setJumped( true ); // send a signal if playposition changes during playback if( isPlaying() ) diff --git a/src/gui/TimeLineWidget.cpp b/src/gui/TimeLineWidget.cpp index 06b32ff7f..47d9db95e 100644 --- a/src/gui/TimeLineWidget.cpp +++ b/src/gui/TimeLineWidget.cpp @@ -375,6 +375,7 @@ void TimeLineWidget::mouseMoveEvent( QMouseEvent* event ) ( 60 * 1000 / 48 ) ) / Engine::getSong()->getTempo() ); m_pos.setCurrentFrame( 0 ); + m_pos.setJumped( true ); updatePosition(); positionMarkerMoved(); break;