diff --git a/include/FxLine.h b/include/FxLine.h index 2cc479799..69f6a9ed0 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -73,6 +73,7 @@ private: private slots: void renameChannel(); void removeChannel(); + void removeUnusedChannels(); void moveChannelLeft(); void moveChannelRight(); void displayHelp(); diff --git a/include/FxMixerView.h b/include/FxMixerView.h index 83010c4cb..0bb5796e0 100644 --- a/include/FxMixerView.h +++ b/include/FxMixerView.h @@ -92,6 +92,9 @@ public: // notify the view that an fx channel was deleted void deleteChannel(int index); + // delete all unused channels + void deleteUnusedChannels(); + // move the channel to the left or right void moveChannelLeft(int index); void moveChannelRight(int index); diff --git a/src/gui/FxMixerView.cpp b/src/gui/FxMixerView.cpp index d278608c3..b32183e9e 100644 --- a/src/gui/FxMixerView.cpp +++ b/src/gui/FxMixerView.cpp @@ -395,6 +395,40 @@ void FxMixerView::deleteChannel(int index) +void FxMixerView::deleteUnusedChannels() +{ + TrackContainer::TrackList tracks; + tracks += Engine::getSong()->tracks(); + tracks += Engine::getBBTrackContainer()->tracks(); + + // go through all FX Channels + for(int i = m_fxChannelViews.size()-1; i > 0; --i) + { + // check if an instrument references to the current channel + bool empty=true; + foreach( Track* t, tracks ) + { + if( t->type() == Track::InstrumentTrack ) + { + InstrumentTrack* inst = dynamic_cast( t ); + if( i == inst->effectChannelModel()->value(0) ) + { + empty=false; + break; + } + } + } + FxChannel * ch = Engine::fxMixer()->effectChannel( i ); + // delete channel if no references found + if( empty && ch->m_receives.isEmpty() ) + { + deleteChannel( i ); + } + } +} + + + void FxMixerView::moveChannelLeft(int index) { // can't move master or first channel left or last channel right diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 8f39af38c..adb47d4f8 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -192,14 +192,18 @@ void FxLine::contextMenuEvent( QContextMenuEvent * ) } contextMenu->addAction( tr( "Rename &channel" ), this, SLOT( renameChannel() ) ); contextMenu->addSeparator(); - + if( m_channelIndex != 0 ) // no remove-option in master { contextMenu->addAction( embed::getIconPixmap( "cancel" ), tr( "R&emove channel" ), this, SLOT( removeChannel() ) ); contextMenu->addSeparator(); } - + + contextMenu->addAction( embed::getIconPixmap( "cancel" ), tr( "Remove &unused channels" ), + this, SLOT( removeUnusedChannels() ) ); + contextMenu->addSeparator(); + contextMenu->addHelpAction(); contextMenu->exec( QCursor::pos() ); delete contextMenu; @@ -230,6 +234,13 @@ void FxLine::removeChannel() } +void FxLine::removeUnusedChannels() +{ + FxMixerView * mix = Engine::fxMixerView(); + mix->deleteUnusedChannels(); +} + + void FxLine::moveChannelLeft() { FxMixerView * mix = Engine::fxMixerView();