From 6bb836464a49588534c1f6dae1b69fe4e4fe5adf Mon Sep 17 00:00:00 2001 From: Paul Giblock Date: Sun, 25 May 2008 05:28:15 +0000 Subject: [PATCH] Load and save controllers to project git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1015 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 14 +++++++ include/controller.h | 43 +++++++++++++++++++- include/embed.h | 4 ++ include/lfo_controller.h | 3 ++ include/song.h | 4 ++ src/core/controller.cpp | 80 ++++++++++++++++++++++++++++++++++++- src/core/lfo_controller.cpp | 38 +++++++++++++++++- 7 files changed, 180 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2336e6a71..8faa6fd78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-05-25 Paul Giblock + + * include/embed.h: + Fix missing distructor warning + + * include/controller.h: + * include/song.h: + * include/lfo_controller.h: + * src/core/song.cpp: + * src/core/controller.cpp: + * src/core/lfo_controller.cpp: + Save and load controllers to project files. Doesn't clear them on + load/new yet though + 2008-05-24 Tobias Doerffel * include/song.h: diff --git a/include/controller.h b/include/controller.h index 38a3a4d8b..088e96ed8 100644 --- a/include/controller.h +++ b/include/controller.h @@ -34,17 +34,29 @@ #include "mixer.h" #include "mv_base.h" #include "templates.h" +#include "journalling_object.h" class controllerDialog; class controller; typedef QVector controllerVector; -class controller : public model +class controller : public model, public journallingObject { Q_OBJECT public: - controller( model * _parent ); + enum ControllerTypes + { + LfoController, + /* + MidiController, + XYController, + PeakController, + */ + NumControllerTypes + } ; + + controller( ControllerTypes _type, model * _parent ); virtual ~controller(); @@ -67,6 +79,26 @@ public: return "Dummy Controller"; } + ControllerTypes type( void ) const + { + return( m_type ); + } + + + virtual const QString & name( void ) const + { + return( m_name ); + } + + + virtual void saveSettings( QDomDocument & _doc, QDomElement & _this ); + virtual void loadSettings( const QDomElement & _this ); + virtual QString nodeName( void ) const; + + static controller * create( ControllerTypes _tt, model * _parent ); + static controller * create( const QDomElement & _this, + model * _parent ); + inline static float fittedValue( float _val ) { return tLimit( _val, 0.0f, 1.0f ); @@ -81,6 +113,11 @@ public: public slots: virtual controllerDialog * createDialog( QWidget * _parent ); + virtual void setName( const QString & _new_name ) + { + m_name = _new_name; + } + protected: // The internal per-controller get-value function @@ -89,6 +126,8 @@ protected: float m_currentValue; bool m_sampleExact; + QString m_name; + ControllerTypes m_type; static controllerVector s_controllers; diff --git a/include/embed.h b/include/embed.h index 880fe9539..b18386c9a 100644 --- a/include/embed.h +++ b/include/embed.h @@ -86,6 +86,10 @@ public: return( QPixmap() ); } + virtual ~pixmapLoader() + { + } + protected: QString m_name; } ; diff --git a/include/lfo_controller.h b/include/lfo_controller.h index 33e85b337..4f13ad696 100644 --- a/include/lfo_controller.h +++ b/include/lfo_controller.h @@ -54,6 +54,9 @@ public: return "LFO Controller"; } + virtual void saveSettings( QDomDocument & _doc, QDomElement & _this ); + virtual void loadSettings( const QDomElement & _this ); + virtual QString nodeName( void ) const; public slots: virtual controllerDialog * createDialog( QWidget * _parent ); diff --git a/include/song.h b/include/song.h index 613001202..d66914627 100644 --- a/include/song.h +++ b/include/song.h @@ -179,6 +179,8 @@ public: } void addController( controller * _c ); + void removeController( controller * _c ); + // QT will implicitly share the Vector I believe.. const controllerVector & controllers( void ) const @@ -242,6 +244,8 @@ private: } void setPlayPos( tact _tact_num, tick _tick, PlayModes _play_mode ); + void saveControllerStates( QDomDocument & _doc, QDomElement & _this ); + void restoreControllerStates( const QDomElement & _this ); track * m_automationTrack; diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 17a91e530..f8cd0ca18 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -35,25 +35,36 @@ #include "mixer.h" #include "controller.h" #include "controller_dialog.h" +#include "lfo_controller.h" unsigned int controller::s_frames = 0; QVector controller::s_controllers; -controller::controller( model * _parent ) : - model( _parent ) + + +controller::controller( ControllerTypes _type, model * _parent ) : + model( _parent ), + m_type( _type ) { s_controllers.append( this ); } + controller::~controller() { + printf("controller dtor\n"); s_controllers.remove( s_controllers.indexOf( this ) ); + if( engine::getSong() ) + { + engine::getSong()->removeController( this ); + } } + // Get current value, with an offset into the current buffer for sample exactness float controller::currentValue( int _offset ) { @@ -66,6 +77,7 @@ float controller::currentValue( int _offset ) } + float controller::value( int _offset ) { return 0.5f; @@ -79,6 +91,8 @@ unsigned int controller::runningFrames() return s_frames; } + + // Get position in seconds float controller::runningTime() { @@ -86,6 +100,7 @@ float controller::runningTime() } + void controller::triggerFrameCounter( void ) { for( int i = 0; i < s_controllers.size(); ++i ) @@ -101,11 +116,72 @@ void controller::triggerFrameCounter( void ) //emit s_signaler.triggerValueChanged(); } + + void controller::resetFrameCounter( void ) { s_frames = 0; } + + +controller * controller::create( ControllerTypes _ct, model * _parent ) +{ + controller * c = NULL; + + switch( _ct ) + { + case LfoController: c = new lfoController( _parent ); break; + default: break; + } + + return( c ); +} + + + +controller * controller::create( const QDomElement & _this, model * _parent ) +{ + controller * c = create( + static_cast( _this.attribute( "type" ).toInt() ), + _parent ); + if( c != NULL ) + { + c->restoreState( _this ); + } + + return( c ); +} + + + +void controller::saveSettings( QDomDocument & _doc, QDomElement & _this ) +{ + _this.setAttribute( "type", type() ); + _this.setAttribute( "name", name() ); +} + + + +void controller::loadSettings( const QDomElement & _this ) +{ + if( _this.attribute( "type" ).toInt() != type() ) + { + qWarning( "controller-type does not match controller-type of " + "settings-node!\n" ); + } + + setName( _this.attribute( "muted" ) ); +} + + +QString controller::nodeName( void ) const +{ + return( "controller" ); +} + + + controllerDialog * controller::createDialog( QWidget * _parent ) { controllerDialog * d = new controllerDialog( this, _parent ); diff --git a/src/core/lfo_controller.cpp b/src/core/lfo_controller.cpp index 13bcd72b9..2fa086a87 100644 --- a/src/core/lfo_controller.cpp +++ b/src/core/lfo_controller.cpp @@ -40,7 +40,7 @@ const float TWO_PI = 6.28318531f; lfoController::lfoController( model * _parent ) : - controller( _parent ), + controller( LfoController, _parent ), m_lfoBaseModel( 0.5, 0.0, 1.0, 0.001, this ), m_lfoSpeedModel( 0.1, 0.01, 5.0, 0.0001, 20000.0, this ), m_lfoAmountModel( 1.0, -1.0, 1.0, 0.005, this ), @@ -64,8 +64,8 @@ lfoController::~lfoController() m_lfoBaseModel.disconnect( this ); m_lfoSpeedModel.disconnect( this ); m_lfoAmountModel.disconnect( this ); - m_lfoWaveModel.disconnect( this ); m_lfoPhaseModel.disconnect( this ); + m_lfoWaveModel.disconnect( this ); } @@ -166,6 +166,40 @@ void lfoController::updateSampleFunction( void ) +void lfoController::saveSettings( QDomDocument & _doc, QDomElement & _this ) +{ + controller::saveSettings( _doc, _this ); + + m_lfoBaseModel.saveSettings( _doc, _this, "base" ); + m_lfoSpeedModel.saveSettings( _doc, _this, "speed" ); + m_lfoAmountModel.saveSettings( _doc, _this, "amount" ); + m_lfoPhaseModel.saveSettings( _doc, _this, "phase" ); + m_lfoWaveModel.saveSettings( _doc, _this, "wave" ); +} + + + +void lfoController::loadSettings( const QDomElement & _this ) +{ + controller::loadSettings( _this ); + + m_lfoBaseModel.loadSettings( _this, "base" ); + m_lfoSpeedModel.loadSettings( _this, "speed" ); + m_lfoAmountModel.loadSettings( _this, "amount" ); + m_lfoPhaseModel.loadSettings( _this, "phase" ); + m_lfoWaveModel.loadSettings( _this, "wave" ); + + updateSampleFunction(); +} + + + +QString lfoController::nodeName( void ) const +{ + return( "lfocontroller" ); +} + + controllerDialog * lfoController::createDialog( QWidget * _parent ) {