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
12 changes: 10 additions & 2 deletions include/Note.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,19 @@ class EXPORT Note : public SerializingObject
void quantizeLength( const int qGrid );
void quantizePos( const int qGrid );

static inline bool lessThan( Note * &lhs, Note * &rhs )
static inline bool lessThan( const Note * lhs, const Note * rhs )
{
// function to compare two notes - must be called explictly when
// using qSort
return (bool) ((int) ( *lhs ).pos() < (int) ( *rhs ).pos());
if( (int)( *lhs ).pos() < (int)( *rhs ).pos() )
{
return true;
}
else if( (int)( *lhs ).pos() > (int)( *rhs ).pos() )
{
return false;
}
return ( (int)( *lhs ).key() > (int)( *rhs ).key() );
}

inline bool selected() const
Expand Down
25 changes: 2 additions & 23 deletions src/tracks/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,28 +213,7 @@ Note * Pattern::addNote( const Note & _new_note, const bool _quant_pos )
}

instrumentTrack()->lock();
if( m_notes.size() == 0 || m_notes.back()->pos() <= new_note->pos() )
{
m_notes.push_back( new_note );
}
else
{
// simple algorithm for inserting the note between two
// notes with smaller and greater position
// maybe it could be optimized by starting in the middle and
// going forward or backward but note-inserting isn't that
// time-critical since it is usually not done while playing...
long new_note_abs_time = new_note->pos();
NoteVector::Iterator it = m_notes.begin();

while( it != m_notes.end() &&
( *it )->pos() < new_note_abs_time )
{
++it;
}

m_notes.insert( it, new_note );
}
m_notes.insert(std::upper_bound(m_notes.begin(), m_notes.end(), new_note, Note::lessThan), new_note);
instrumentTrack()->unlock();

checkType();
Expand Down Expand Up @@ -292,7 +271,7 @@ Note * Pattern::noteAtStep( int _step )
void Pattern::rearrangeAllNotes()
{
// sort notes by start time
qSort(m_notes.begin(), m_notes.end(), Note::lessThan );
std::sort(m_notes.begin(), m_notes.end(), Note::lessThan);
}


Expand Down