From 3b191ecc2c65e28f80871785cc0dad71b41a29d4 Mon Sep 17 00:00:00 2001 From: Paul Giblock Date: Tue, 8 Apr 2008 08:33:25 +0000 Subject: [PATCH] More controller improvements git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@903 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 4 +- include/controller_connection_dialog.h | 3 +- include/lfo_controller.h | 3 +- include/lfo_controller_dialog.h | 60 ----------- src/core/lfo_controller.cpp | 125 +++++++++++++++++++++++ src/gui/controller_connection_dialog.cpp | 3 +- src/gui/lfo_controller_dialog.cpp | 2 +- 7 files changed, 134 insertions(+), 66 deletions(-) delete mode 100644 include/lfo_controller_dialog.h create mode 100644 src/core/lfo_controller.cpp diff --git a/ChangeLog b/ChangeLog index 273ea21d2..a41fdedd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +2008-04-08 Paul Giblock + * include/engine.h: * src/core/engine.cpp: add static accessor to the controller rack. I'm sure this won't be it's @@ -19,8 +21,8 @@ * src/gui/widgets/visualization_widget.cpp: drop back from 40 to an arbitrary 24fps - * include/lfo_controller_dialog.h: * include/lfo_controller.h: + * src/gui/lfo_controller.cpp: * src/gui/lfo_controller_dialog.cpp: - add beginnings of an LFO controller and dialog - don't mind the unoptimized code, it will be fixed diff --git a/include/controller_connection_dialog.h b/include/controller_connection_dialog.h index a10e591bb..fbdd0778e 100644 --- a/include/controller_connection_dialog.h +++ b/include/controller_connection_dialog.h @@ -1,5 +1,6 @@ /* - * controller_connection_dialog.h - + * controller_connection_dialog.h - dialog allowing the user to create and + * modify links between controllers and models * * Copyright (c) 2008 Paul Giblock * diff --git a/include/lfo_controller.h b/include/lfo_controller.h index 13f24f6d5..125aa1a0b 100644 --- a/include/lfo_controller.h +++ b/include/lfo_controller.h @@ -1,6 +1,5 @@ /* - * lfo_controller.h - A LFO-based controller - * controller's settings + * lfo_controller.h - A LFO-based controller and dialog * * Copyright (c) 2008 Paul Giblock * diff --git a/include/lfo_controller_dialog.h b/include/lfo_controller_dialog.h deleted file mode 100644 index 472bb686c..000000000 --- a/include/lfo_controller_dialog.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * controller_dialog.h - per-controller-specific view for changing a - * controller's settings - * - * Copyright (c) 2008 Paul Giblock - * - * 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 _LFO_CONTROLLER_H -#define _LFO_CONTROLLER_H - -#include - -#include "automatable_model.h" -#include "controller.h" -#include "controller_dialog.h" -#include "mv_base.h" - -class lfoControllerDialog : public controllerDialog -{ - Q_OBJECT -public: - lfoControllerDialog( controller * _controller, QWidget * _parent ); - virtual ~lfoControllerDialog(); - -public slots: - //void editControls( void ); - //void deletePlugin( void ); - //void displayHelp( void ); - //void closeEffects( void ); - - -signals: - - -protected: - virtual void contextMenuEvent( QContextMenuEvent * _me ); - virtual void paintEvent( QPaintEvent * _pe ); - virtual void modelChanged( void ); - -} ; - -#endif diff --git a/src/core/lfo_controller.cpp b/src/core/lfo_controller.cpp new file mode 100644 index 000000000..969994c85 --- /dev/null +++ b/src/core/lfo_controller.cpp @@ -0,0 +1,125 @@ +#ifndef SINGLE_SOURCE_COMPILE + +/* + * lfo_controller.cpp - implementation of class controller which handles remote-control + * of automatableModels + * + * Copyright (c) 2008 Paul Giblock + * + * 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. + * + */ + +#include +#include +#include +#include + + +#include "song.h" +#include "engine.h" +#include "mixer.h" +#include "lfo_controller.h" +#include "controller_dialog.h" + +const float TWO_PI = 6.28318531f; + +lfoController::lfoController( model * _parent ) : + controller( _parent ), + m_lfoAttackModel( 0.0, 0.0, 1.0, 0.001, this ), + m_lfoSpeedModel( 0.1, 0.01, 10.0, 0.0001, 20000.0, this ), + m_lfoAmountModel( 1.0, -1.0, 1.0, 0.005, this ), + m_lfoWaveModel( SineWave, 0, NumLfoShapes, 1, this ), + m_duration( 0 ), + m_phaseCorrection( 0 ) +{ +} + + +lfoController::~lfoController() +{ + m_lfoAttackModel.disconnect( this ); + m_lfoSpeedModel.disconnect( this ); + m_lfoAmountModel.disconnect( this ); + m_lfoWaveModel.disconnect( this ); +} + +// This code took forever to get right. It can +// definately be optimized a bit. +float lfoController::value( int _offset ) +{ + int frame = runningFrames() + _offset + m_phaseCorrection; + + // Recalculate speed each period + if (_offset == 0) { + + // The new duration in frames + // (Samples/Second) / (periods/second) = (Samples/cycle) + int newDuration = engine::getMixer()->sampleRate() / m_lfoSpeedModel.value(); + + if (newDuration != m_duration) { + // frame offset + // (Samples - Samples) = Samples + float oldFramePhase = (frame % m_duration); + + // Phase between 0 and 1 + // (Samples/Samples) = factor + float phase = oldFramePhase / m_duration; + + // where we SHOULD be according to new frequency + // (factor*Samples) = Samples + int newFrameOffset = phase * newDuration; + + // recalc + // (Samples - (Samples-Samples)) = Samples + + // Go back to beginning of last natural period + m_phaseCorrection = -(runningFrames()%newDuration); + + // newFrameOffset has old phaseCorrection built-in + m_phaseCorrection += newFrameOffset; + + + // re-run the first calculation again + frame = runningFrames() + m_phaseCorrection; + + m_duration = newDuration; + } + } + + + // 44100 frames/sec + return 0.5 + (m_lfoAmountModel.value() * + sinf( TWO_PI * float(frame * m_lfoSpeedModel.value()) / engine::getMixer()->sampleRate() ) / 2.0f); +} + + +controllerDialog * lfoController::createDialog( QWidget * _parent ) +{ + controllerDialog * d = new lfoControllerDialog( this, _parent ); + + + + return d; +} + + +#include "lfo_controller.moc" + + +#endif diff --git a/src/gui/controller_connection_dialog.cpp b/src/gui/controller_connection_dialog.cpp index b036ff4ac..ba903cdc2 100644 --- a/src/gui/controller_connection_dialog.cpp +++ b/src/gui/controller_connection_dialog.cpp @@ -1,7 +1,8 @@ #ifndef SINGLE_SOURCE_COMPILE /* - * controller_connection_dialog.cpp - + * controller_connection_dialog.cpp - dialog allowing the user to create and + * modify links between controllers and models * * Copyright (c) 2008 Paul Giblock * diff --git a/src/gui/lfo_controller_dialog.cpp b/src/gui/lfo_controller_dialog.cpp index b4d4ac0ca..cc8e66ac6 100644 --- a/src/gui/lfo_controller_dialog.cpp +++ b/src/gui/lfo_controller_dialog.cpp @@ -1,7 +1,7 @@ #ifndef SINGLE_SOURCE_COMPILE /* - * controller_dialog.cpp - per-controller-specific view for changing a + * lfo_controller_dialog.cpp - per-controller-specific view for changing a * controller's settings * * Copyright (c) 2008 Paul Giblock