Ability to re-order mixer channels

In the Fx Mixer View, you can select a channel and press Alt+Left
and Alt+Right respectively to re-order Fx Channels. This should be
made more easily available in the GUI eventually.
This commit is contained in:
Andrew Kelley
2009-09-30 06:53:23 -07:00
parent e09c12687a
commit 33753495bd
3 changed files with 143 additions and 6 deletions

View File

@@ -87,6 +87,10 @@ public:
// notify the view that an fx channel was deleted
void deleteChannel(int index);
// move the channel to the left or right
void moveChannelLeft(int index);
void moveChannelRight(int index);
private slots:
void updateFaders();
void addNewChannel();

View File

@@ -173,7 +173,7 @@ void FxMixer::deleteChannel(int index)
void FxMixer::moveChannelLeft(int index)
{
// can't move master or first channel
if( index <= 1 )
if( index <= 1 || index >= m_fxChannels.size() )
{
return;
}
@@ -182,6 +182,63 @@ void FxMixer::moveChannelLeft(int index)
int a = index - 1, b = index;
// go through every instrument and adjust for the channel index change
QVector<track *> songTrackList = engine::getSong()->tracks();
QVector<track *> bbTrackList = engine::getBBTrackContainer()->tracks();
QVector<track *> trackLists[] = {songTrackList, bbTrackList};
for(int tl=0; tl<2; ++tl)
{
QVector<track *> trackList = trackLists[tl];
for(int i=0; i<trackList.size(); ++i)
{
if( trackList[i]->type() == track::InstrumentTrack )
{
InstrumentTrack * inst = (InstrumentTrack *) trackList[i];
int val = inst->effectChannelModel()->value(0);
if( val == a )
{
inst->effectChannelModel()->setValue(b);
}
else if( val == b )
{
inst->effectChannelModel()->setValue(a);
}
}
}
}
for(int i=0; i<m_fxChannels.size(); ++i)
{
// for every send/receive, adjust for the channel index change
for(int j=0; j<m_fxChannels[i]->m_sends.size(); ++j)
{
if( m_fxChannels[i]->m_sends[j] == a )
{
m_fxChannels[i]->m_sends[j] = b;
}
else if( m_fxChannels[i]->m_sends[j] == b )
{
m_fxChannels[i]->m_sends[j] = a;
}
}
for(int j=0; j<m_fxChannels[i]->m_receives.size(); ++j)
{
if( m_fxChannels[i]->m_receives[j] == a )
{
m_fxChannels[i]->m_receives[j] = b;
}
else if( m_fxChannels[i]->m_receives[j] == b )
{
m_fxChannels[i]->m_receives[j] = a;
}
}
}
// actually do the swap
FxChannel * tmpChannel = m_fxChannels[a];
m_fxChannels[a] = m_fxChannels[b];
m_fxChannels[b] = tmpChannel;
}

View File

@@ -89,7 +89,22 @@ FxMixerView::FxMixerView() :
chLayout->addWidget(m_fxChannelViews[i]->m_fxLine);
}
// add the scrolling section to the main layout
channelArea = new QScrollArea(this);
// class for scroll area to pass key presses down
class ChannelArea : public QScrollArea
{
public:
ChannelArea(QWidget * parent, FxMixerView * mv) :
QScrollArea(parent), m_mv(mv) {}
~ChannelArea() {}
virtual void keyPressEvent(QKeyEvent * e)
{
m_mv->keyPressEvent(e);
}
private:
FxMixerView * m_mv;
};
channelArea = new ChannelArea(this, this);
channelArea->setWidget(m_channelAreaWidget);
channelArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
channelArea->setFrameStyle( QFrame::NoFrame );
@@ -237,13 +252,12 @@ void FxMixerView::updateFxLine(int index)
void FxMixerView::deleteChannel(int index)
{
// can't delete master
if( index == 0 ) return;
// remember selected line
int selLine = m_currentFxLine->channelIndex();
// can't delete master
if( index == 0 )
return;
// delete the real channel
engine::fxMixer()->deleteChannel(index);
@@ -253,6 +267,7 @@ void FxMixerView::deleteChannel(int index)
delete m_fxChannelViews[index]->m_muteBtn;
delete m_fxChannelViews[index]->m_fxLine;
delete m_fxChannelViews[index];
m_channelAreaWidget->adjustSize();
// make sure every channel knows what index it is
for(int i=0; i<m_fxChannelViews.size(); ++i)
@@ -274,6 +289,55 @@ void FxMixerView::deleteChannel(int index)
}
void FxMixerView::moveChannelLeft(int index)
{
// can't move master or first channel left or last channel right
if( index <= 1 || index >= m_fxChannelViews.size() ) return;
int selIndex = m_currentFxLine->channelIndex();
FxMixer * mix = engine::fxMixer();
mix->moveChannelLeft(index);
// refresh the two mixer views
for( int i = index-1; i <= index; ++i )
{
// delete the mixer view
int replaceIndex = chLayout->indexOf(m_fxChannelViews[i]->m_fxLine);
chLayout->removeWidget(m_fxChannelViews[i]->m_fxLine);
delete m_fxChannelViews[i]->m_fader;
delete m_fxChannelViews[i]->m_muteBtn;
delete m_fxChannelViews[i]->m_fxLine;
delete m_fxChannelViews[i];
// add it again
m_fxChannelViews[i] = new FxChannelView(m_channelAreaWidget, this, i);
chLayout->insertWidget(replaceIndex, m_fxChannelViews[i]->m_fxLine);
}
// keep selected channel
if( selIndex == index )
{
selIndex = index-1;
}
else if( selIndex == index - 1 )
{
selIndex = index;
}
setCurrentFxLine(selIndex);
}
void FxMixerView::moveChannelRight(int index)
{
moveChannelLeft(index+1);
}
void FxMixerView::keyPressEvent(QKeyEvent * e)
{
switch(e->key())
@@ -281,6 +345,18 @@ void FxMixerView::keyPressEvent(QKeyEvent * e)
case Qt::Key_Delete:
deleteChannel(m_currentFxLine->channelIndex());
break;
case Qt::Key_Left:
if( e->modifiers() & Qt::AltModifier )
{
moveChannelLeft( m_currentFxLine->channelIndex() );
}
break;
case Qt::Key_Right:
if( e->modifiers() & Qt::AltModifier )
{
moveChannelRight( m_currentFxLine->channelIndex() );
}
break;
}
}