From 06cb85b771cc9936279ce330b60caa1a774f3bd2 Mon Sep 17 00:00:00 2001 From: Amadeus Folego Date: Wed, 14 Jan 2015 16:46:36 -0200 Subject: [PATCH 1/2] Move FX assignment/creation logic to InsTrackView --- include/InstrumentTrack.h | 8 ++++++++ include/Track.h | 2 -- src/core/Track.cpp | 27 ++------------------------- src/tracks/InstrumentTrack.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index ffbb61ccc..f172e6094 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -322,6 +322,9 @@ private slots: void midiConfigChanged(); void muteChanged(); + void assignFxLine( int channelIndex ); + void createFxLine(); + private: InstrumentTrackWindow * m_window; @@ -375,6 +378,11 @@ public: void setInstrumentTrackView( InstrumentTrackView * _tv ); + InstrumentTrackView * instrumentTrackView() + { + return m_itv; + } + PianoView * pianoView() { return m_pianoView; diff --git a/include/Track.h b/include/Track.h index b766b6056..91aadfde2 100644 --- a/include/Track.h +++ b/include/Track.h @@ -391,8 +391,6 @@ private slots: void recordingOn(); void recordingOff(); void clearTrack(); - void assignFxLine( int channelIndex ); - void createFxLine(); private: static QPixmap * s_grip; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index a6f98e1df..524bc3837 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1711,29 +1711,6 @@ void TrackOperationsWidget::clearTrack() -/*! \brief Create and assign a new FX Channel for this track */ -void TrackOperationsWidget::createFxLine() -{ - int channelIndex = gui->fxMixerView()->addNewChannel(); - - Engine::fxMixer()->effectChannel( channelIndex )->m_name = m_trackView->getTrack()->name(); - - assignFxLine(channelIndex); -} - - - -/*! \brief Assign a specific FX Channel for this track */ -void TrackOperationsWidget::assignFxLine(int channelIndex) -{ - Track * track = m_trackView->getTrack(); - dynamic_cast( track )->effectChannelModel()->setValue( channelIndex ); - - gui->fxMixerView()->setCurrentFxLine( channelIndex ); -} - - - /*! \brief Remove this track from the track list * */ @@ -1777,7 +1754,7 @@ void TrackOperationsWidget::updateMenu() QMenu * fxMenu = new QMenu( tr( "FX %1: %2" ).arg( channelIndex ).arg( fxChannel->m_name ), to_menu ); QSignalMapper * fxMenuSignalMapper = new QSignalMapper(this); - fxMenu->addAction("Assign to new FX Channel" , this, SLOT( createFxLine() ) ); + fxMenu->addAction( tr( "Assign to new FX Channel" ), trackView, SLOT( createFxLine() ) ); fxMenu->addSeparator(); @@ -1794,7 +1771,7 @@ void TrackOperationsWidget::updateMenu() } to_menu->addMenu(fxMenu); - connect(fxMenuSignalMapper, SIGNAL(mapped(int)), this, SLOT(assignFxLine(int))); + connect(fxMenuSignalMapper, SIGNAL(mapped(int)), trackView, SLOT(assignFxLine(int))); to_menu->addSeparator(); to_menu->addMenu( trackView->midiMenu() ); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index e9317dc52..a4bef2828 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -963,6 +963,30 @@ InstrumentTrackWindow * InstrumentTrackView::topLevelInstrumentTrackWindow() + +/*! \brief Create and assign a new FX Channel for this track */ +void InstrumentTrackView::createFxLine() +{ + int channelIndex = gui->fxMixerView()->addNewChannel(); + + Engine::fxMixer()->effectChannel( channelIndex )->m_name = getTrack()->name(); + + assignFxLine(channelIndex); +} + + + + +/*! \brief Assign a specific FX Channel for this track */ +void InstrumentTrackView::assignFxLine(int channelIndex) +{ + model()->effectChannelModel()->setValue( channelIndex ); + + gui->fxMixerView()->setCurrentFxLine( channelIndex ); +} + + + // TODO: Add windows to free list on freeInstrumentTrackWindow. // But, don't NULL m_window or disconnect signals. This will allow windows // that are being show/hidden frequently to stay connected. From c99e47f5816e802c45d8887be4684333ade2fb44 Mon Sep 17 00:00:00 2001 From: Amadeus Folego Date: Wed, 14 Jan 2015 16:50:25 -0200 Subject: [PATCH 2/2] Add "Assign to new FX Channel" action to FXSpinBox Fix #604 #921 --- include/InstrumentTrack.h | 6 +++- src/core/Track.cpp | 25 +------------- src/tracks/InstrumentTrack.cpp | 63 ++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 25 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index f172e6094..8c8c963fa 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -306,6 +306,9 @@ public: static void cleanupWindowCache(); + // Create a menu for assigning/creating channels for this track + QMenu * createFxMenu( QString title, QString newFxLabel ); + protected: virtual void dragEnterEvent( QDragEnterEvent * _dee ); @@ -378,11 +381,12 @@ public: void setInstrumentTrackView( InstrumentTrackView * _tv ); - InstrumentTrackView * instrumentTrackView() + InstrumentTrackView *instrumentTrackView() { return m_itv; } + PianoView * pianoView() { return m_pianoView; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 524bc3837..1eb16776d 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1747,31 +1747,8 @@ void TrackOperationsWidget::updateMenu() } if( InstrumentTrackView * trackView = dynamic_cast( m_trackView ) ) { - int channelIndex = trackView->model()->effectChannelModel()->value(); - - FxChannel * fxChannel = Engine::fxMixer()->effectChannel( channelIndex ); - - QMenu * fxMenu = new QMenu( tr( "FX %1: %2" ).arg( channelIndex ).arg( fxChannel->m_name ), to_menu ); - QSignalMapper * fxMenuSignalMapper = new QSignalMapper(this); - - fxMenu->addAction( tr( "Assign to new FX Channel" ), trackView, SLOT( createFxLine() ) ); - fxMenu->addSeparator(); - - - for (int i = 0; i < Engine::fxMixer()->fxChannels().size(); ++i) - { - FxChannel * currentChannel = Engine::fxMixer()->fxChannels()[i]; - - if ( currentChannel != fxChannel ) - { - QString label = tr( "FX %1: %2" ).arg( currentChannel->m_channelIndex ).arg( currentChannel->m_name ); - QAction * action = fxMenu->addAction( label, fxMenuSignalMapper, SLOT( map() ) ); - fxMenuSignalMapper->setMapping(action, currentChannel->m_channelIndex); - } - } - + QMenu *fxMenu = trackView->createFxMenu( tr( "FX %1: %2" ), tr( "Assign to new FX Channel" )); to_menu->addMenu(fxMenu); - connect(fxMenuSignalMapper, SIGNAL(mapped(int)), trackView, SLOT(assignFxLine(int))); to_menu->addSeparator(); to_menu->addMenu( trackView->midiMenu() ); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index a4bef2828..7fcf2b0dc 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -36,12 +36,14 @@ #include #include #include +#include #include "FileDialog.h" #include "InstrumentTrack.h" #include "AudioPort.h" #include "AutomationPattern.h" #include "BBTrack.h" +#include "CaptionMenu.h" #include "ConfigManager.h" #include "ControllerConnection.h" #include "debug.h" @@ -1171,6 +1173,43 @@ void InstrumentTrackView::muteChanged() +QMenu * InstrumentTrackView::createFxMenu(QString title, QString newFxLabel) +{ + int channelIndex = model()->effectChannelModel()->value(); + + FxChannel *fxChannel = Engine::fxMixer()->effectChannel( channelIndex ); + + // If title allows interpolation, pass channel index and name + if ( title.contains( "%2" ) ) + { + title = title.arg( channelIndex ).arg( fxChannel->m_name ); + } + + QMenu *fxMenu = new QMenu( title ); + + QSignalMapper * fxMenuSignalMapper = new QSignalMapper(fxMenu); + + fxMenu->addAction( newFxLabel, this, SLOT( createFxLine() ) ); + fxMenu->addSeparator(); + + for (int i = 0; i < Engine::fxMixer()->fxChannels().size(); ++i) + { + FxChannel * currentChannel = Engine::fxMixer()->fxChannels()[i]; + + if ( currentChannel != fxChannel ) + { + QString label = tr( "FX %1: %2" ).arg( currentChannel->m_channelIndex ).arg( currentChannel->m_name ); + QAction * action = fxMenu->addAction( label, fxMenuSignalMapper, SLOT( map() ) ); + fxMenuSignalMapper->setMapping(action, currentChannel->m_channelIndex); + } + } + + connect(fxMenuSignalMapper, SIGNAL(mapped(int)), this, SLOT(assignFxLine(int))); + + return fxMenu; +} + + class fxLineLcdSpinBox : public LcdSpinBox @@ -1189,6 +1228,30 @@ class fxLineLcdSpinBox : public LcdSpinBox gui->fxMixerView()->setFocus();// set focus to fxMixer window //engine::getFxMixerView()->raise(); } + + virtual void contextMenuEvent( QContextMenuEvent* event ) + { + // for the case, the user clicked right while pressing left mouse- + // button, the context-menu appears while mouse-cursor is still hidden + // and it isn't shown again until user does something which causes + // an QApplication::restoreOverrideCursor()-call... + mouseReleaseEvent( NULL ); + + QPointer contextMenu = new CaptionMenu( model()->displayName(), this ); + + // This condition is here just as a safety check, fxLineLcdSpinBox is aways + // created inside a TabWidget inside an InstrumentTrackWindow + if ( InstrumentTrackWindow* window = dynamic_cast( (QWidget *)this->parent()->parent() ) ) + { + QMenu *fxMenu = window->instrumentTrackView()->createFxMenu( tr( "Assign to:" ), tr( "New FX Channel" ) ); + contextMenu->addMenu( fxMenu ); + + contextMenu->addSeparator(); + } + addDefaultActions( contextMenu ); + contextMenu->exec( QCursor::pos() ); + } + };