Skip to content

Commit

Permalink
Fix extra bar with beat note near end
Browse files Browse the repository at this point in the history
  • Loading branch information
zonkmachine committed Aug 30, 2016
1 parent 37d6e9a commit edca72b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class QPushButton;
class InstrumentTrack;
class SampleBuffer;

static const int PATTERN_VERSION = 1;


class EXPORT Pattern : public TrackContentObject
Expand Down Expand Up @@ -140,6 +141,7 @@ protected slots:
InstrumentTrack * m_instrumentTrack;

PatternTypes m_patternType;
int m_version;

// data-stuff
NoteVector m_notes;
Expand Down
58 changes: 54 additions & 4 deletions src/tracks/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Pattern::Pattern( InstrumentTrack * _instrument_track ) :
TrackContentObject( _instrument_track ),
m_instrumentTrack( _instrument_track ),
m_patternType( BeatPattern ),
m_version( PATTERN_VERSION ),
m_steps( MidiTime::stepsPerTact() )
{
setName( _instrument_track->name() );
Expand All @@ -81,6 +82,7 @@ Pattern::Pattern( const Pattern& other ) :
TrackContentObject( other.m_instrumentTrack ),
m_instrumentTrack( other.m_instrumentTrack ),
m_patternType( other.m_patternType ),
m_version( PATTERN_VERSION ),
m_steps( other.m_steps )
{
for( NoteVector::ConstIterator it = other.m_notes.begin(); it != other.m_notes.end(); ++it )
Expand Down Expand Up @@ -195,21 +197,22 @@ MidiTime Pattern::beatPatternLength() const
if( ( *it )->length() < 0 )
{
max_length = qMax<tick_t>( max_length,
( *it )->pos() +
MidiTime::ticksPerTact() /
MidiTime::stepsPerTact() );
( *it )->pos() + 1 );
}
}

if( m_steps != MidiTime::stepsPerTact() )
{
max_length = m_steps * MidiTime::ticksPerTact() /
MidiTime::stepsPerTact() ;
MidiTime::stepsPerTact();
}

return MidiTime( max_length ).nextFullTact() * MidiTime::ticksPerTact();
}




Note * Pattern::addNote( const Note & _new_note, const bool _quant_pos )
{
Note * new_note = new Note( _new_note );
Expand Down Expand Up @@ -297,6 +300,8 @@ Note * Pattern::noteAtStep( int _step )
}




Note * Pattern::rearrangeNote( const Note * _note_to_proc,
const bool _quant_pos )
{
Expand All @@ -310,6 +315,7 @@ Note * Pattern::rearrangeNote( const Note * _note_to_proc,




void Pattern::rearrangeAllNotes()
{
// sort notes by start time
Expand All @@ -318,6 +324,7 @@ void Pattern::rearrangeAllNotes()




void Pattern::clearNotes()
{
instrumentTrack()->lock();
Expand Down Expand Up @@ -385,6 +392,7 @@ void Pattern::checkType()

void Pattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
_this.setAttribute( "version", m_version );
_this.setAttribute( "type", m_patternType );
_this.setAttribute( "name", name() );
// as the target of copied/dragged pattern is always an existing
Expand Down Expand Up @@ -453,6 +461,48 @@ void Pattern::loadSettings( const QDomElement & _this )
m_steps = MidiTime::stepsPerTact();
}

// Backward compatibility for < 1.2.0
if( ! _this.hasAttribute( "version" ) )
{
if( m_patternType == BeatPattern )
{
MidiTime oldLength = MidiTime( _this.attribute( "len" ).toInt() );

tick_t max_length = MidiTime::ticksPerTact();
int oldSteps = m_steps;

for( NoteVector::ConstIterator it = m_notes.begin();
it != m_notes.end(); ++it )
{
if( ( *it )->length() < 0 )
{
max_length = qMax<tick_t>( max_length,
( *it )->pos() +
MidiTime::ticksPerTact() /
MidiTime::stepsPerTact() );
}
}

if( m_steps != MidiTime::stepsPerTact() )
{
max_length = m_steps * MidiTime::ticksPerTact() /
MidiTime::stepsPerTact();
}

m_steps = m_steps > oldSteps ? m_steps : oldSteps;
max_length = qMax<tick_t>( max_length, oldLength );
while( max_length > m_steps * MidiTime::ticksPerTact() /
MidiTime::stepsPerTact() )
{
m_steps += MidiTime::stepsPerTact();
max_length -= MidiTime::ticksPerTact();
}

changeLength( MidiTime( max_length ).nextFullTact() *
MidiTime::ticksPerTact() );
}
}

ensureBeatNotes();
checkType();

Expand Down

0 comments on commit edca72b

Please sign in to comment.