Skip to content

Commit

Permalink
Make "Assign to" menu work with sample tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
PhysSong committed Oct 24, 2018
1 parent 648c26b commit f3ff59c
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 19 deletions.
11 changes: 8 additions & 3 deletions include/FxLineLcdSpinBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@

#include "LcdSpinBox.h"

class InstrumentTrackWindow;
class TrackView;


class FxLineLcdSpinBox : public LcdSpinBox
{
Q_OBJECT
public:
FxLineLcdSpinBox(int numDigits, QWidget * parent, const QString& name) :
LcdSpinBox(numDigits, parent, name)
FxLineLcdSpinBox(int numDigits, QWidget * parent, const QString& name, TrackView * tv = NULL) :
LcdSpinBox(numDigits, parent, name), m_tv(tv)
{}
virtual ~FxLineLcdSpinBox() {}

void setTrackView(TrackView * tv);

protected:
virtual void mouseDoubleClickEvent(QMouseEvent* event);
virtual void contextMenuEvent(QContextMenuEvent* event);

private:
TrackView * m_tv;

};

#endif
11 changes: 8 additions & 3 deletions include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class SampleTrackView : public TrackView
}


virtual QMenu * createFxMenu( QString title, QString newFxLabel );


public slots:
void showEffects();

Expand All @@ -216,13 +219,15 @@ public slots:
}


private slots:
void assignFxLine( int channelIndex );
void createFxLine();


private:
EffectRackView * m_effectRack;
QWidget * m_effWindow;
SampleTrackWindow * m_window;
Knob * m_volumeKnob;
Knob * m_panningKnob;
LcdSpinBox * m_effectChannelNumber;

TrackLabelButton * m_tlb;

Expand Down
4 changes: 4 additions & 0 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ class TrackView : public QWidget, public ModelView, public JournallingObject

virtual void update();

// Create a menu for assigning/creating channels for this track
// Currently instrument track and sample track supports it
virtual QMenu * createFxMenu(QString title, QString newFxLabel);


public slots:
virtual bool close();
Expand Down
21 changes: 18 additions & 3 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,13 +1921,15 @@ void TrackOperationsWidget::updateMenu()
{
toMenu->addAction( tr( "Clear this track" ), this, SLOT( clearTrack() ) );
}
if (InstrumentTrackView * trackView = dynamic_cast<InstrumentTrackView *>(m_trackView))
if (QMenu *fxMenu = m_trackView->createFxMenu(tr("FX %1: %2"), tr("Assign to new FX Channel")))
{
QMenu *fxMenu = trackView->createFxMenu( tr( "FX %1: %2" ), tr( "Assign to new FX Channel" ));
toMenu->addMenu(fxMenu);
}

if (InstrumentTrackView * trackView = dynamic_cast<InstrumentTrackView *>(m_trackView))
{
toMenu->addSeparator();
toMenu->addMenu( trackView->midiMenu() );
toMenu->addMenu(trackView->midiMenu());
}
if( dynamic_cast<AutomationTrackView *>( m_trackView ) )
{
Expand Down Expand Up @@ -2672,6 +2674,19 @@ void TrackView::update()



/*! \brief Create a menu for assigning/creating channels for this track.
*
*/
QMenu * TrackView::createFxMenu(QString title, QString newFxLabel)
{
Q_UNUSED(title)
Q_UNUSED(newFxLabel)
return NULL;
}




/*! \brief Close this track View.
*
*/
Expand Down
15 changes: 7 additions & 8 deletions src/gui/widgets/FxLineLcdSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
#include "CaptionMenu.h"
#include "FxMixerView.h"
#include "GuiApplication.h"
#include "InstrumentTrack.h"
#include "Track.h"

void FxLineLcdSpinBox::setTrackView(TrackView * tv)
{
m_tv = tv;
}

void FxLineLcdSpinBox::mouseDoubleClickEvent(QMouseEvent* event)
{
Expand All @@ -50,14 +54,9 @@ void FxLineLcdSpinBox::contextMenuEvent(QContextMenuEvent* event)

QPointer<CaptionMenu> 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
// FIXME this won't necessarily be true anymore
if (InstrumentTrackWindow* window =
dynamic_cast<InstrumentTrackWindow*>((QWidget*)this->parent()->parent()))
if (QMenu *fxMenu = m_tv->createFxMenu(
tr("Assign to:"), tr("New FX Channel")))
{
QMenu *fxMenu = window->instrumentTrackView()->createFxMenu(
tr("Assign to:"), tr("New FX Channel"));
contextMenu->addMenu(fxMenu);

contextMenu->addSeparator();
Expand Down
3 changes: 2 additions & 1 deletion src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :


// setup spinbox for selecting FX-channel
m_effectChannelNumber = new FxLineLcdSpinBox( 2, NULL, tr( "FX channel" ) );
m_effectChannelNumber = new FxLineLcdSpinBox( 2, NULL, tr( "FX channel" ), m_itv );

basicControlsLayout->addWidget( m_effectChannelNumber, 0, 6 );
basicControlsLayout->setAlignment( m_effectChannelNumber, widgetAlignment );
Expand Down Expand Up @@ -1487,6 +1487,7 @@ void InstrumentTrackWindow::setInstrumentTrackView( InstrumentTrackView* view )
}

m_itv = view;
m_effectChannelNumber->setTrackView(m_itv);
}


Expand Down
64 changes: 63 additions & 1 deletion src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "MainWindow.h"
#include "Mixer.h"
#include "EffectRackView.h"
#include "FxMixerView.h"
#include "TabWidget.h"
#include "TrackLabelButton.h"

Expand Down Expand Up @@ -814,6 +815,44 @@ SampleTrackView::~SampleTrackView()



QMenu * SampleTrackView::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()->numChannels(); ++i)
{
FxChannel * currentChannel = Engine::fxMixer()->effectChannel(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;
}




void SampleTrackView::showEffects()
{
Expand Down Expand Up @@ -909,7 +948,7 @@ SampleTrackWindow::SampleTrackWindow(SampleTrackView * tv) :


// setup spinbox for selecting FX-channel
m_effectChannelNumber = new FxLineLcdSpinBox(2, NULL, tr("FX channel"));
m_effectChannelNumber = new FxLineLcdSpinBox(2, NULL, tr("FX channel"), m_stv);

basicControlsLayout->addWidget(m_effectChannelNumber, 0, 3);
basicControlsLayout->setAlignment(m_effectChannelNumber, widgetAlignment);
Expand Down Expand Up @@ -987,6 +1026,29 @@ void SampleTrackWindow::modelChanged()



/*! \brief Create and assign a new FX Channel for this track */
void SampleTrackView::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 SampleTrackView::assignFxLine(int channelIndex)
{
model()->effectChannelModel()->setValue(channelIndex);

gui->fxMixerView()->setCurrentFxLine(channelIndex);
}



void SampleTrackWindow::updateName()
{
setWindowTitle(m_track->name().length() > 25 ? (m_track->name().left(24) + "...") : m_track->name());
Expand Down

0 comments on commit f3ff59c

Please sign in to comment.