VstBase: initial support for saving/restoring chunks
Some VST plugins save their state as chunks rather than parameters. According code to save/restore those chunks has been taken from FST 1.9. However restore currently is disabled as it mostly fails for whatever reason.
This commit is contained in:
@@ -38,6 +38,10 @@
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#ifdef LMMS_HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef LMMS_BUILD_LINUX
|
||||
|
||||
#ifdef LMMS_HAVE_SCHED_H
|
||||
@@ -184,6 +188,12 @@ public:
|
||||
// post properties of specified parameter
|
||||
void getParameterProperties( const int _idx );
|
||||
|
||||
// save settings chunk of plugin into file
|
||||
void saveChunkToFile( const std::string & _file );
|
||||
|
||||
// restore settings chunk of plugin from file
|
||||
void loadChunkFromFile( const std::string & _file, int _len );
|
||||
|
||||
// number of inputs
|
||||
virtual int inputCount( void ) const
|
||||
{
|
||||
@@ -350,6 +360,16 @@ bool remoteVstPlugin::processMessage( const message & _m )
|
||||
getParameterProperties( _m.getInt() );
|
||||
break;
|
||||
|
||||
case IdSaveSettingsToFile:
|
||||
saveChunkToFile( _m.getString() );
|
||||
sendMessage( IdSaveSettingsToFile );
|
||||
break;
|
||||
|
||||
case IdLoadSettingsFromFile:
|
||||
loadChunkFromFile( _m.getString( 0 ), _m.getInt( 1 ) );
|
||||
sendMessage( IdLoadSettingsFromFile );
|
||||
break;
|
||||
|
||||
default:
|
||||
return remotePluginClient::processMessage( _m );
|
||||
}
|
||||
@@ -799,6 +819,40 @@ void remoteVstPlugin::getParameterProperties( const int _idx )
|
||||
|
||||
|
||||
|
||||
void remoteVstPlugin::saveChunkToFile( const std::string & _file )
|
||||
{
|
||||
if( m_plugin->flags & 32 )
|
||||
{
|
||||
void * chunk = NULL;
|
||||
int len = m_plugin->dispatcher( m_plugin, 23, 0, 0, &chunk, 0 );
|
||||
if( len > 0 )
|
||||
{
|
||||
int fd = open( _file.c_str(), O_WRONLY );
|
||||
write( fd, chunk, len );
|
||||
close( fd );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void remoteVstPlugin::loadChunkFromFile( const std::string & _file, int _len )
|
||||
{
|
||||
char * buf = new char[_len];
|
||||
|
||||
const int fd = open( _file.c_str(), O_RDONLY );
|
||||
read( fd, buf, _len );
|
||||
close( fd );
|
||||
|
||||
// doesn't work for various plugins for some reason :-(
|
||||
// m_plugin->dispatcher( m_plugin, 24, 0, _len, buf, 0 );
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void remoteVstPlugin::updateInOutCount( void )
|
||||
{
|
||||
delete[] m_inputs;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QLocale>
|
||||
#include <QtCore/QTemporaryFile>
|
||||
#include <QtGui/QCloseEvent>
|
||||
#include <QtGui/QMdiArea>
|
||||
#include <QtGui/QMdiSubWindow>
|
||||
@@ -250,6 +251,12 @@ void vstPlugin::loadSettings( const QDomElement & _this )
|
||||
}
|
||||
setParameterDump( dump );
|
||||
}
|
||||
|
||||
if( _this.hasAttribute( "chunk" ) )
|
||||
{
|
||||
loadChunk( QByteArray::fromBase64(
|
||||
_this.attribute( "chunk" ).toAscii() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -268,6 +275,11 @@ void vstPlugin::saveSettings( QDomDocument & _doc, QDomElement & _this )
|
||||
{
|
||||
_this.setAttribute( it.key(), it.value() );
|
||||
}
|
||||
QByteArray chunk = saveChunk();
|
||||
if( !chunk.isEmpty() )
|
||||
{
|
||||
_this.setAttribute( "chunk", QString( chunk.toBase64() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -393,5 +405,44 @@ bool vstPlugin::processMessage( const message & _m )
|
||||
|
||||
|
||||
|
||||
|
||||
void vstPlugin::loadChunk( const QByteArray & _chunk )
|
||||
{
|
||||
QTemporaryFile tf;
|
||||
if( tf.open() )
|
||||
{
|
||||
tf.write( _chunk );
|
||||
lock();
|
||||
sendMessage( message( IdLoadSettingsFromFile ).
|
||||
addString( QDir::toNativeSeparators(
|
||||
tf.fileName() ).toStdString() ).
|
||||
addInt( _chunk.size() ) );
|
||||
waitForMessage( IdLoadSettingsFromFile );
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QByteArray vstPlugin::saveChunk( void )
|
||||
{
|
||||
QByteArray a;
|
||||
QTemporaryFile tf;
|
||||
if( tf.open() )
|
||||
{
|
||||
lock();
|
||||
sendMessage( message( IdSaveSettingsToFile ).
|
||||
addString( QDir::toNativeSeparators(
|
||||
tf.fileName() ).toStdString() ) );
|
||||
waitForMessage( IdSaveSettingsToFile );
|
||||
unlock();
|
||||
a = tf.readAll();
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
#include "moc_vst_plugin.cxx"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* vst_plugin.h - declaration of vstPlugin class
|
||||
*
|
||||
* Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -101,6 +101,9 @@ public slots:
|
||||
|
||||
|
||||
private:
|
||||
void loadChunk( const QByteArray & _chunk );
|
||||
QByteArray saveChunk( void );
|
||||
|
||||
QString m_plugin;
|
||||
QWidget * m_pluginWidget;
|
||||
int m_pluginWindowID;
|
||||
|
||||
Reference in New Issue
Block a user