Moved VST sync functionality into new VstSyncController class

First attempt to clean up the mess in the Song class by moving the VST sync
functionality into its own class and just calling a few functions from it.
This commit is contained in:
Tobias Doerffel
2014-02-03 19:41:54 +01:00
parent 5e6066e6b6
commit 5a9e0bdcef
7 changed files with 392 additions and 226 deletions

View File

@@ -27,7 +27,7 @@
#include "export.h"
#include "MidiEvent.h"
#include "VST_sync_shm.h"
#include "VstSyncData.h"
#include <vector>
#include <cstdio>
@@ -813,7 +813,7 @@ public:
RemotePluginClient( key_t _shm_in, key_t _shm_out );
virtual ~RemotePluginClient();
#ifdef USE_QT_SHMEM
sncVST * getQtVSTshm();
VstSyncData * getQtVSTshm();
#endif
virtual bool processMessage( const message & _m );
@@ -883,7 +883,7 @@ private:
QSharedMemory m_shmObj;
QSharedMemory m_shmQtID;
#endif
sncVST * m_SncVSTplug;
VstSyncData * m_vstSyncData;
float * m_shm;
int m_inputCount;
@@ -1013,7 +1013,7 @@ RemotePluginClient::RemotePluginClient( key_t _shm_in, key_t _shm_out ) :
m_shmObj(),
m_shmQtID( "/usr/bin/lmms" ),
#endif
m_SncVSTplug( NULL ),
m_vstSyncData( NULL ),
m_shm( NULL ),
m_inputCount( 0 ),
m_outputCount( 0 ),
@@ -1023,9 +1023,9 @@ RemotePluginClient::RemotePluginClient( key_t _shm_in, key_t _shm_out ) :
#ifdef USE_QT_SHMEM
if( m_shmQtID.attach( QSharedMemory::ReadOnly ) )
{
m_SncVSTplug = (sncVST *) m_shmQtID.data();
m_bufferSize = m_SncVSTplug->m_bufferSize;
m_sampleRate = m_SncVSTplug->m_sampleRate;
m_vstSyncData = (VstSyncData *) m_shmQtID.data();
m_bufferSize = m_vstSyncData->m_bufferSize;
m_sampleRate = m_vstSyncData->m_sampleRate;
return;
}
#else
@@ -1044,18 +1044,18 @@ RemotePluginClient::RemotePluginClient( key_t _shm_in, key_t _shm_out ) :
}
else
{ // attach segment
m_SncVSTplug = (sncVST *)shmat(m_shmID, 0, 0);
if( m_SncVSTplug == (sncVST *)( -1 ) )
m_vstSyncData = (VstSyncData *)shmat(m_shmID, 0, 0);
if( m_vstSyncData == (VstSyncData *)( -1 ) )
{
perror( "RemotePluginClient::shmat" );
}
else
{
m_bufferSize = m_SncVSTplug->m_bufferSize;
m_sampleRate = m_SncVSTplug->m_sampleRate;
m_bufferSize = m_vstSyncData->m_bufferSize;
m_sampleRate = m_vstSyncData->m_sampleRate;
// detach segment
if( shmdt(m_SncVSTplug) == -1 )
if( shmdt(m_vstSyncData) == -1 )
{
perror("RemotePluginClient::shmdt");
}
@@ -1087,9 +1087,9 @@ RemotePluginClient::~RemotePluginClient()
#ifdef USE_QT_SHMEM
sncVST * RemotePluginClient::getQtVSTshm()
VstSyncData * RemotePluginClient::getQtVSTshm()
{
return m_SncVSTplug;
return m_vstSyncData;
}
#endif

View File

@@ -0,0 +1,99 @@
/*
* VstSyncController.h - type declarations needed for VST to lmms host sync
*
* Copyright (c) 2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2013 Mike Choi <rdavidian71/at/gmail/dot/com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef VST_SYNC_CONTROLLER_H
#define VST_SYNC_CONTROLLER_H
#include <QtCore/QObject>
#include <QtCore/QSharedMemory>
#include "VstSyncData.h"
class VstSyncController : public QObject
{
Q_OBJECT
public:
VstSyncController();
~VstSyncController();
void setAbsolutePosition( int ticks );
void setPlaybackState( bool enabled )
{
m_syncData->isPlaying = enabled;
}
void setTempo( int newTempo );
void setTimeSignature( int num, int denom )
{
m_syncData->timeSigNumer = num;
m_syncData->timeSigDenom = denom;
}
void startCycle( int startTick, int endTick );
void stopCycle()
{
m_syncData->isCycle = false;
}
void update();
private slots:
void updateSampleRate();
private:
struct VstSyncData
{
bool isPlaying;
float ppqPos;
int timeSigNumer;
int timeSigDenom;
bool isCycle;
bool hasSHM;
float cycleStart;
float cycleEnd;
int m_bufferSize;
int m_sampleRate;
int m_bpm;
#ifdef VST_SNC_LATENCY
float m_latency;
#endif
} ;
VstSyncData* m_syncData;
int m_shmID;
QSharedMemory m_shm;
};
#endif

View File

@@ -1,8 +1,9 @@
/*
* VST_sync_shm.h - type declarations needed for VST to lmms host sync
* VstSyncData.h - type declarations needed for VST to lmms host sync
*
* Copyright (c) 2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2013 Mike Choi <rdavidian71/at/gmail/dot/com>
*
* Copyright (c) 2004-2013 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
@@ -22,8 +23,8 @@
*
*/
#ifndef _VST_SYNC_SHM_H
#define _VST_SYNC_SHM_H
#ifndef VST_SYNC_DATA_H
#define VST_SYNC_DATA_H
// VST sync frequency (in ms), how often will be VST plugin synced
// keep it power of two if possible (not used by now)
@@ -36,9 +37,11 @@
#define VST_SNC_SHM_KEY_FILE "/dev/null"
//#define VST_SNC_SHM_RND_KEY 3561653564469
struct sncVST
struct VstSyncData
{
bool isPlayin;
bool isPlaying;
float ppqPos;
int timeSigNumer;
int timeSigDenom;

View File

@@ -32,7 +32,7 @@
#include "AutomatableModel.h"
#include "Controller.h"
#include "MeterModel.h"
#include "VST_sync_shm.h"
#include "VstSyncController.h"
class AutomationTrack;
class pattern;
@@ -296,8 +296,6 @@ private slots:
void updateFramesPerTick();
void updateSampleRateSHM();
private:
@@ -368,9 +366,8 @@ private:
} ;
QVector<Actions> m_actions;
int m_shmID;
sncVST * m_SncVSTplug;
QSharedMemory m_shmQtID;
VstSyncController m_vstSyncController;
friend class engine;
friend class songEditor;