Skip to content

Commit

Permalink
Merge pull request #200 from wongcc966422/issue28
Browse files Browse the repository at this point in the history
Fixes removing controller in controller rack bug
  • Loading branch information
tobydox committed Jan 30, 2014
2 parents c83115d + 7196d67 commit 9f6b894
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 7 deletions.
9 changes: 8 additions & 1 deletion include/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include "JournallingObject.h"

class ControllerDialog;
class Controller;
class Controller;
class ControllerConnection;

typedef QVector<Controller *> ControllerVector;

Expand Down Expand Up @@ -118,6 +119,11 @@ class Controller : public Model, public JournallingObject
static void triggerFrameCounter();
static void resetFrameCounter();

//Accepts a ControllerConnection * as it may be used in the future.
void addConnection( ControllerConnection * );
void removeConnection( ControllerConnection * );
int connectionCount() const;


public slots:
virtual ControllerDialog * createDialog( QWidget * _parent );
Expand All @@ -136,6 +142,7 @@ public slots:

float m_currentValue;
bool m_sampleExact;
int m_connectionCount;

QString m_name;
ControllerTypes m_type;
Expand Down
6 changes: 6 additions & 0 deletions include/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ class EXPORT Effect : public Plugin
return m_key;
}

EffectChain * effectChain() const
{
return m_parent;
}

virtual EffectControls * controls() = 0;

static Effect * instantiate( const QString & _plugin_name,
Expand Down Expand Up @@ -189,6 +194,7 @@ class EXPORT Effect : public Plugin


private:
EffectChain * m_parent;
void resample( int _i, const sampleFrame * _src_buf,
sample_rate_t _src_sr,
sampleFrame * _dst_buf, sample_rate_t _dst_sr,
Expand Down
4 changes: 2 additions & 2 deletions plugins/peak_controller_effect/peak_controller_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class PeakControllerEffect : public Effect
{
public:
PeakControllerEffect( Model * parent,
const Descriptor::SubPluginFeatures::Key * _key );
const Descriptor::SubPluginFeatures::Key * _key );
virtual ~PeakControllerEffect();
virtual bool processAudioBuffer( sampleFrame * _buf,
const fpp_t _frames );
const fpp_t _frames );

virtual EffectControls * controls()
{
Expand Down
27 changes: 27 additions & 0 deletions src/core/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Controller::Controller( ControllerTypes _type, Model * _parent,
const QString & _display_name ) :
Model( _parent, _display_name ),
JournallingObject(),
m_connectionCount( 0 ),
m_type( _type )
{
if( _type != DummyController && _type != MidiController )
Expand Down Expand Up @@ -277,6 +278,32 @@ ControllerDialog * Controller::createDialog( QWidget * _parent )
}




void Controller::addConnection( ControllerConnection * )
{
m_connectionCount++;
}




void Controller::removeConnection( ControllerConnection * )
{
m_connectionCount--;
Q_ASSERT( m_connectionCount >= 0 );
}




int Controller::connectionCount() const{
return m_connectionCount;
}




#include "moc_Controller.cxx"


12 changes: 12 additions & 0 deletions src/core/ControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ControllerConnectionVector ControllerConnection::s_connections;


ControllerConnection::ControllerConnection( Controller * _controller ) :
m_controller( NULL ),
m_controllerId( -1 ),
m_ownsController( false )
{
Expand Down Expand Up @@ -71,6 +72,10 @@ ControllerConnection::ControllerConnection( int _controllerId ) :

ControllerConnection::~ControllerConnection()
{
if( m_controller && m_controller->type() != Controller::DummyController )
{
m_controller->removeConnection( this );
}
s_connections.remove( s_connections.indexOf( this ) );
if( m_ownsController )
{
Expand All @@ -93,6 +98,12 @@ void ControllerConnection::setController( Controller * _controller )
if( m_ownsController && m_controller )
{
delete m_controller;
m_controller = NULL;
}

if( m_controller && m_controller->type() != Controller::DummyController )
{
m_controller->removeConnection( this );
}

if( !_controller )
Expand All @@ -107,6 +118,7 @@ void ControllerConnection::setController( Controller * _controller )

if( _controller->type() != Controller::DummyController )
{
_controller->addConnection( this );
QObject::connect( _controller, SIGNAL( valueChanged() ),
this, SIGNAL( valueChanged() ) );
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Effect::Effect( const Plugin::Descriptor * _desc,
Model * _parent,
const Descriptor::SubPluginFeatures::Key * _key ) :
Plugin( _desc, _parent ),
m_parent( NULL ),
m_key( _key ? *_key : Descriptor::SubPluginFeatures::Key() ),
m_processors( 1 ),
m_okay( true ),
Expand Down Expand Up @@ -117,7 +118,9 @@ Effect * Effect::instantiate( const QString & _plugin_name,
if( dynamic_cast<Effect *>( p ) != NULL )
{
// everything ok, so return pointer
return dynamic_cast<Effect *>( p );
Effect * effect = dynamic_cast<Effect *>( p );
effect->m_parent = dynamic_cast<EffectChain *>(_parent);
return effect;
}

// not quite... so delete plugin and return dummy effect
Expand Down
2 changes: 2 additions & 0 deletions src/core/EffectChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ void EffectChain::removeEffect( Effect * _effect )
engine::mixer()->lock();
m_effects.erase( qFind( m_effects.begin(), m_effects.end(), _effect ) );
engine::mixer()->unlock();

emit dataChanged();
}


Expand Down
8 changes: 6 additions & 2 deletions src/core/PeakController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "engine.h"
#include "Mixer.h"
#include "PeakController.h"
#include "EffectChain.h"
#include "ControllerDialog.h"
#include "plugins/peak_controller_effect/peak_controller_effect.h"

Expand All @@ -57,7 +58,10 @@ PeakController::PeakController( Model * _parent,

PeakController::~PeakController()
{
// disconnects
if( m_peakEffect != NULL && m_peakEffect->effectChain() != NULL )
{
m_peakEffect->effectChain()->removeEffect( m_peakEffect );
}
}


Expand All @@ -76,7 +80,7 @@ float PeakController::value( int _offset )
void PeakController::handleDestroyedEffect( )
{
// possible race condition...
printf("disconnecting effect\n");
//printf("disconnecting effect\n");
disconnect( m_peakEffect );
m_peakEffect = NULL;
//deleteLater();
Expand Down
19 changes: 18 additions & 1 deletion src/gui/widgets/ControllerRackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QtGui/QScrollArea>
#include <QtGui/QVBoxLayout>
#include <QtGui/QMdiArea>
#include <QMessageBox>

#include "song.h"
#include "embed.h"
Expand Down Expand Up @@ -117,8 +118,24 @@ void ControllerRackView::loadSettings( const QDomElement & _this )

void ControllerRackView::deleteController( ControllerView * _view )
{

Controller * c = _view->getController();

int connectionCount = c->connectionCount();
if( connectionCount > 0 )
{
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
msgBox.setWindowTitle( tr("Confirm Delete") );
msgBox.setText( tr("Confirm delete? There are existing connection(s) "
"associted with this controller. There is no way to undo.") );
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
if( msgBox.exec() != QMessageBox::Ok )
{
return;
}
}


m_controllerViews.erase( qFind( m_controllerViews.begin(),
m_controllerViews.end(), _view ) );
delete _view;
Expand Down

0 comments on commit 9f6b894

Please sign in to comment.