Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions include/BBTrackContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class LMMS_EXPORT BBTrackContainer : public TrackContainer
BBTrackContainer();
virtual ~BBTrackContainer();

virtual bool play( TimePos _start, const fpp_t _frames,
const f_cnt_t _frame_base, int _tco_num = -1 );
virtual bool play(TimePos start, const fpp_t frames, const f_cnt_t frameBase, int tcoNum = -1);

void updateAfterTrackAdd() override;

Expand All @@ -48,19 +47,19 @@ class LMMS_EXPORT BBTrackContainer : public TrackContainer
return "bbtrackcontainer";
}

bar_t lengthOfBB( int _bb ) const;
bar_t lengthOfBB(int bb) const;
inline bar_t lengthOfCurrentBB()
{
return lengthOfBB( currentBB() );
return lengthOfBB(currentBB());
}
int numOfBBs() const;
void removeBB( int _bb );
void removeBB(int bb);

void swapBB( int _bb1, int _bb2 );
void swapBB(int bb1, int bb2);

void updateBBTrack( TrackContentObject * _tco );
void updateBBTrack(TrackContentObject * tco);
void fixIncorrectPositions();
void createTCOsForBB( int _bb );
void createTCOsForBB(int bb);

AutomatedValueMap automatedValuesAt(TimePos time, int tcoNum) const override;

Expand Down
114 changes: 56 additions & 58 deletions src/core/BBTrackContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

BBTrackContainer::BBTrackContainer() :
TrackContainer(),
m_bbComboBoxModel( this )
m_bbComboBoxModel(this)
{
connect( &m_bbComboBoxModel, SIGNAL( dataChanged() ),
this, SLOT( currentBBChanged() ) );
connect(&m_bbComboBoxModel, SIGNAL(dataChanged()),
this, SLOT(currentBBChanged()));
// we *always* want to receive updates even in case BB actually did
// not change upon setCurrentBB()-call
connect( &m_bbComboBoxModel, SIGNAL( dataUnchanged() ),
this, SLOT( currentBBChanged() ) );
setType( BBContainer );
connect(&m_bbComboBoxModel, SIGNAL(dataUnchanged()),
this, SLOT(currentBBChanged()));
setType(BBContainer);
}


Expand All @@ -53,35 +53,35 @@ BBTrackContainer::~BBTrackContainer()



bool BBTrackContainer::play( TimePos _start, fpp_t _frames,
f_cnt_t _offset, int _tco_num )
bool BBTrackContainer::play(TimePos start, fpp_t frames, f_cnt_t offset, int tcoNum)
{
bool played_a_note = false;
if( lengthOfBB( _tco_num ) <= 0 )
bool notePlayed = false;

if (lengthOfBB(tcoNum) <= 0)
{
return false;
}

_start = _start % ( lengthOfBB( _tco_num ) * TimePos::ticksPerBar() );
start = start % (lengthOfBB(tcoNum) * TimePos::ticksPerBar());

TrackList tl = tracks();
for( TrackList::iterator it = tl.begin(); it != tl.end(); ++it )
for (Track * t : tl)
{
if( ( *it )->play( _start, _frames, _offset, _tco_num ) )
if (t->play(start, frames, offset, tcoNum))
{
played_a_note = true;
notePlayed = true;
}
}

return played_a_note;
return notePlayed;
}




void BBTrackContainer::updateAfterTrackAdd()
{
if( numOfBBs() == 0 && !Engine::getSong()->isLoadingProject() )
if (numOfBBs() == 0 && !Engine::getSong()->isLoadingProject())
{
Engine::getSong()->addBBTrack();
}
Expand All @@ -90,69 +90,68 @@ void BBTrackContainer::updateAfterTrackAdd()



bar_t BBTrackContainer::lengthOfBB( int _bb ) const
bar_t BBTrackContainer::lengthOfBB(int bb) const
{
TimePos max_length = TimePos::ticksPerBar();
TimePos maxLength = TimePos::ticksPerBar();

const TrackList & tl = tracks();
for (Track* t : tl)
for (Track * t : tl)
{
// Don't create TCOs here if not exist
if (_bb < t->numOfTCOs())
// Don't create TCOs here if they don't exist
if (bb < t->numOfTCOs())
{
max_length = qMax(max_length, t->getTCO( _bb )->length());
maxLength = qMax(maxLength, t->getTCO(bb)->length());
}
}

return max_length.nextFullBar();
return maxLength.nextFullBar();
}




int BBTrackContainer::numOfBBs() const
{
return Engine::getSong()->countTracks( Track::BBTrack );
return Engine::getSong()->countTracks(Track::BBTrack);
}




void BBTrackContainer::removeBB( int _bb )
void BBTrackContainer::removeBB(int bb)
{
TrackList tl = tracks();
for( TrackList::iterator it = tl.begin(); it != tl.end(); ++it )
for (Track * t : tl)
{
delete ( *it )->getTCO( _bb );
( *it )->removeBar( _bb * DefaultTicksPerBar );
delete t->getTCO(bb);
t->removeBar(bb * DefaultTicksPerBar);
}
if( _bb <= currentBB() )
if (bb <= currentBB())
{
setCurrentBB( qMax( currentBB() - 1, 0 ) );
setCurrentBB(qMax(currentBB() - 1, 0));
}
}




void BBTrackContainer::swapBB( int _bb1, int _bb2 )
void BBTrackContainer::swapBB(int bb1, int bb2)
{
TrackList tl = tracks();
for( TrackList::iterator it = tl.begin(); it != tl.end(); ++it )
for (Track * t : tl)
{
( *it )->swapPositionOfTCOs( _bb1, _bb2 );
t->swapPositionOfTCOs(bb1, bb2);
}
updateComboBox();
}




void BBTrackContainer::updateBBTrack( TrackContentObject * _tco )
void BBTrackContainer::updateBBTrack(TrackContentObject * tco)
{
BBTrack * t = BBTrack::findBBTrack( _tco->startPosition() /
DefaultTicksPerBar );
if( t != NULL )
BBTrack * t = BBTrack::findBBTrack(tco->startPosition() / DefaultTicksPerBar);
if (t != NULL)
{
t->dataChanged();
}
Expand All @@ -164,11 +163,11 @@ void BBTrackContainer::updateBBTrack( TrackContentObject * _tco )
void BBTrackContainer::fixIncorrectPositions()
{
TrackList tl = tracks();
for( TrackList::iterator it = tl.begin(); it != tl.end(); ++it )
for (Track * t : tl)
{
for( int i = 0; i < numOfBBs(); ++i )
for (int i = 0; i < numOfBBs(); ++i)
{
( *it )->getTCO( i )->movePosition( TimePos( i, 0 ) );
t->getTCO(i)->movePosition(TimePos(i, 0));
}
}
}
Expand All @@ -178,7 +177,7 @@ void BBTrackContainer::fixIncorrectPositions()

void BBTrackContainer::play()
{
if( Engine::getSong()->playMode() != Song::Mode_PlayBB )
if (Engine::getSong()->playMode() != Song::Mode_PlayBB)
{
Engine::getSong()->playBB();
}
Expand All @@ -201,44 +200,43 @@ void BBTrackContainer::stop()

void BBTrackContainer::updateComboBox()
{
const int cur_bb = currentBB();
const int curBB = currentBB();

m_bbComboBoxModel.clear();

for( int i = 0; i < numOfBBs(); ++i )
for (int i = 0; i < numOfBBs(); ++i)
{
BBTrack * bbt = BBTrack::findBBTrack( i );
m_bbComboBoxModel.addItem( bbt->name() );
BBTrack * bbt = BBTrack::findBBTrack(i);
m_bbComboBoxModel.addItem(bbt->name());
}
setCurrentBB( cur_bb );
setCurrentBB(curBB);
}




void BBTrackContainer::currentBBChanged()
{
// now update all track-labels (the current one has to become white,
// the others gray)
// now update all track-labels (the current one has to become white, the others gray)
TrackList tl = Engine::getSong()->tracks();
for( TrackList::iterator it = tl.begin(); it != tl.end(); ++it )
for (Track * t : tl)
{
if( ( *it )->type() == Track::BBTrack )
if (t->type() == Track::BBTrack)
{
( *it )->dataChanged();
t->dataChanged();
}
}
}




void BBTrackContainer::createTCOsForBB( int _bb )
void BBTrackContainer::createTCOsForBB(int bb)
{
TrackList tl = tracks();
for( int i = 0; i < tl.size(); ++i )
for (Track * t : tl)
{
tl[i]->createTCOsForBB( _bb );
t->createTCOsForBB(bb);
}
}

Expand All @@ -247,11 +245,11 @@ AutomatedValueMap BBTrackContainer::automatedValuesAt(TimePos time, int tcoNum)
Q_ASSERT(tcoNum >= 0);
Q_ASSERT(time.getTicks() >= 0);

auto length_bars = lengthOfBB(tcoNum);
auto length_ticks = length_bars * TimePos::ticksPerBar();
if (time > length_ticks)
auto lengthBars = lengthOfBB(tcoNum);
auto lengthTicks = lengthBars * TimePos::ticksPerBar();
if (time > lengthTicks)
{
time = length_ticks;
time = lengthTicks;
}

return TrackContainer::automatedValuesAt(time + (TimePos::ticksPerBar() * tcoNum), tcoNum);
Expand Down