Skip to content

Commit

Permalink
Drop notes with length zero (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasp00 authored Sep 12, 2016
1 parent ede0e07 commit 1f90337
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 189 deletions.
1 change: 1 addition & 0 deletions include/MidiTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class EXPORT MidiTime
static tick_t ticksPerTact( const TimeSig &sig );
static int stepsPerTact();
static void setTicksPerTact( tick_t tpt );
static MidiTime stepPosition( int step );

private:
tick_t m_ticks;
Expand Down
8 changes: 4 additions & 4 deletions include/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class EXPORT Pattern : public TrackContentObject
// note management
Note * addNote( const Note & _new_note, const bool _quant_pos = true );

void removeNote( const Note * _note_to_del );
void removeNote( Note * _note_to_del );

Note * noteAtStep( int _step );

Note * rearrangeNote( const Note * _note_to_proc,
Note * rearrangeNote( Note * _note_to_proc,
const bool _quant_pos = true );
void rearrangeAllNotes();
void clearNotes();
Expand All @@ -84,7 +84,8 @@ class EXPORT Pattern : public TrackContentObject
return m_notes;
}

void setStep( int _step, bool _enabled );
Note * addStepNote( int step );
void setStep( int step, bool enabled );

// pattern-type stuff
inline PatternTypes type() const
Expand Down Expand Up @@ -122,7 +123,6 @@ class EXPORT Pattern : public TrackContentObject


protected:
void ensureBeatNotes();
void updateBBTrack();


Expand Down
6 changes: 6 additions & 0 deletions src/core/midi/MidiTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,9 @@ void MidiTime::setTicksPerTact( tick_t tpt )
{
s_ticksPerTact = tpt;
}


MidiTime MidiTime::stepPosition( int step )
{
return step * ticksPerTact() / stepsPerTact();
}
28 changes: 4 additions & 24 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1627,17 +1627,8 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
m_mouseDownRight = true;
if( it != notes.begin()-1 )
{
Note *note = *it;
m_pattern->addJournalCheckPoint();
if( note->length() > 0 )
{
m_pattern->removeNote( note );
}
else
{
note->setLength( 0 );
m_pattern->dataChanged();
}
m_pattern->removeNote( *it );
Engine::getSong()->setModified();
}
}
Expand Down Expand Up @@ -2288,19 +2279,8 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me )
)
{
// delete this note
if( it != notes.end() )
{
if( note->length() > 0 )
{
m_pattern->removeNote( note );
}
else
{
note->setLength( 0 );
m_pattern->dataChanged();
}
Engine::getSong()->setModified();
}
m_pattern->removeNote( note );
Engine::getSong()->setModified();
}
else
{
Expand Down Expand Up @@ -3700,7 +3680,7 @@ void PianoRoll::cutSelectedNotes()

Engine::getSong()->setModified();

for( const Note *note : selected_notes )
for( Note *note : selected_notes )
{
// note (the memory of it) is also deleted by
// pattern::removeNote(...) so we don't have to do that
Expand Down
30 changes: 13 additions & 17 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,25 +656,21 @@ bool InstrumentTrack::play( const MidiTime & _start, const fpp_t _frames,
while( nit != notes.end() &&
( cur_note = *nit )->pos() == cur_start )
{
if( cur_note->length() != 0 )
{
const f_cnt_t note_frames =
cur_note->length().frames(
frames_per_tick );

NotePlayHandle* notePlayHandle = NotePlayHandleManager::acquire( this, _offset, note_frames, *cur_note );
notePlayHandle->setBBTrack( bb_track );
// are we playing global song?
if( _tco_num < 0 )
{
// then set song-global offset of pattern in order to
// properly perform the note detuning
notePlayHandle->setSongGlobalParentOffset( p->startPosition() );
}
const f_cnt_t note_frames =
cur_note->length().frames( frames_per_tick );

Engine::mixer()->addPlayHandle( notePlayHandle );
played_a_note = true;
NotePlayHandle* notePlayHandle = NotePlayHandleManager::acquire( this, _offset, note_frames, *cur_note );
notePlayHandle->setBBTrack( bb_track );
// are we playing global song?
if( _tco_num < 0 )
{
// then set song-global offset of pattern in order to
// properly perform the note detuning
notePlayHandle->setSongGlobalParentOffset( p->startPosition() );
}

Engine::mixer()->addPlayHandle( notePlayHandle );
played_a_note = true;
++nit;
}
}
Expand Down
Loading

0 comments on commit 1f90337

Please sign in to comment.