Skip to content

Commit

Permalink
Move PeakController to the peak_controller_effect plugin
Browse files Browse the repository at this point in the history
This commit also introduces the usage of ControllerFactory in Controller::create. That's done in order to support dynamic loading of PeakControllers.
  • Loading branch information
Reflexe committed Oct 17, 2019
1 parent 96cc2df commit 20608b0
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 58 deletions.
1 change: 0 additions & 1 deletion include/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class LMMS_EXPORT Controller : public Model, public JournallingObject
DummyController,
LfoController,
MidiController,
PeakController,
/*
XYController,
EquationController
Expand Down
7 changes: 6 additions & 1 deletion plugins/peak_controller_effect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
INCLUDE(BuildPlugin)

BUILD_PLUGIN(peakcontrollereffect peak_controller_effect.cpp peak_controller_effect_controls.cpp peak_controller_effect_control_dialog.cpp peak_controller_effect.h peak_controller_effect_controls.h peak_controller_effect_control_dialog.h MOCFILES peak_controller_effect_controls.h peak_controller_effect_control_dialog.h EMBEDDED_RESOURCES artwork.png logo.png)
BUILD_PLUGIN(peakcontrollereffect
peak_controller_effect.cpp peak_controller_effect_controls.cpp
peak_controller_effect_control_dialog.cpp peak_controller_effect.h peak_controller_effect_controls.h
peak_controller_effect_control_dialog.h PeakController.h PeakController.cpp PeakControllerDialog.cpp
MOCFILES peak_controller_effect_controls.h peak_controller_effect_control_dialog.h PeakController.h
EMBEDDED_RESOURCES artwork.png logo.png)
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@

#include "Mixer.h"
#include "EffectChain.h"
#include "plugins/peak_controller_effect/peak_controller_effect.h"
#include "peak_controller_effect.h"

PeakControllerEffectVector PeakController::s_effects;


PeakController::PeakController( Model * _parent,
PeakControllerEffect * _peak_effect ) :
Controller( Controller::PeakController, _parent, tr( "Peak Controller" ) ),
Controller( s_peakControllerType, _parent, tr( "Peak Controller" ) ),
m_peakEffect( _peak_effect ),
m_currentSample( 0.0f )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class PeakControllerEffect;
typedef QVector<PeakControllerEffect *> PeakControllerEffectVector;


class LMMS_EXPORT PeakController : public Controller
class PeakController : public Controller
{
Q_OBJECT
public:
static constexpr Controller::ControllerTypes s_peakControllerType = static_cast<ControllerTypes>(3);

PeakController( Model * _parent,
PeakControllerEffect *_peak_effect = NULL );

Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions plugins/peak_controller_effect/peak_controller_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "PresetPreviewPlayHandle.h"
#include "PeakController.h"
#include "peak_controller_effect.h"
#include "ControllerFactory.h"
#include "lmms_math.h"

#include "embed.h"
Expand Down Expand Up @@ -74,13 +75,18 @@ PeakControllerEffect::PeakControllerEffect(
Engine::getSong()->addController( m_autoController );
}
PeakController::s_effects.append( this );

setupControllerFactory();
}




PeakControllerEffect::~PeakControllerEffect()
{
// Don't remove the controller from the factory
// since there might be other instances of this type.

int idx = PeakController::s_effects.indexOf( this );
if( idx >= 0 )
{
Expand Down Expand Up @@ -143,7 +149,27 @@ bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf,
return isRunning();
}

void PeakControllerEffect::setupControllerFactory() {
Engine::controllerFactory()->addFactory(PeakController::s_peakControllerType,
[] (Model *parent, const QDomElement *element) {
Q_ASSERT(element);
int effectId = element->attribute( "effectId" ).toInt();
auto findEffectFromEffectID = [effectId] (PeakControllerEffect *effect) {
return effectId == effect->m_effectId;
};

auto result = std::find_if(PeakController::s_effects.begin(),
PeakController::s_effects.end(),
findEffectFromEffectID);

if (result == PeakController::s_effects.end()) {
qWarning("Could not load effectid: %d; creating a new empty peak controller", effectId);
return new PeakController(parent);
}

return (*result)->controller();
});
}


extern "C"
Expand Down
1 change: 1 addition & 0 deletions plugins/peak_controller_effect/peak_controller_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class PeakControllerEffect : public Effect

friend class PeakControllerEffectControls;

static void setupControllerFactory();
} ;

#endif
1 change: 0 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ set(LMMS_SRCS
core/Note.cpp
core/NotePlayHandle.cpp
core/Oscillator.cpp
core/PeakController.cpp
core/PerfLog.cpp
core/Piano.cpp
core/PlayHandle.cpp
Expand Down
56 changes: 5 additions & 51 deletions src/core/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "ControllerDialog.h"
#include "LfoController.h"
#include "MidiController.h"
#include "PeakController.h"
#include "ControllerFactory.h"


long Controller::s_periods = 0;
Expand Down Expand Up @@ -183,60 +183,14 @@ void Controller::resetFrameCounter()

Controller * Controller::create( ControllerTypes _ct, Model * _parent )
{
static Controller * dummy = NULL;
Controller * c = NULL;

switch( _ct )
{
case Controller::DummyController:
if (!dummy)
dummy = new Controller( DummyController, NULL,
QString() );
c = dummy;
break;

case Controller::LfoController:
c = new ::LfoController( _parent );
break;

case Controller::PeakController:
//Already instantiated in EffectChain::loadSettings()
Q_ASSERT( false );
break;

case Controller::MidiController:
c = new ::MidiController( _parent );
break;

default:
break;
}

return( c );
return Engine::controllerFactory()->create(_ct, _parent, nullptr);
}



Controller * Controller::create( const QDomElement & _this, Model * _parent )
{
Controller * c;
if( _this.attribute( "type" ).toInt() == Controller::PeakController )
{
c = PeakController::getControllerBySetting( _this );
}
else
{
c = create(
static_cast<ControllerTypes>( _this.attribute( "type" ).toInt() ),
_parent );
}

if( c != NULL )
{
c->restoreState( _this );
}

return( c );
Controller * Controller::create( const QDomElement & _this, Model * _parent ) {
auto controllerType = static_cast<ControllerTypes>(_this.attribute( "type" ).toInt());
return Engine::controllerFactory()->create(controllerType, _parent, &_this);
}


Expand Down
1 change: 0 additions & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ SET(LMMS_SRCS
gui/MainWindow.cpp
gui/MidiSetupWidget.cpp
gui/ModelView.cpp
gui/PeakControllerDialog.cpp
gui/PianoView.cpp
gui/PluginBrowser.cpp
gui/RowTableView.cpp
Expand Down

0 comments on commit 20608b0

Please sign in to comment.