mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-24 22:58:01 -04:00
Merge pull request #3881 from zonkmachine/arppatternsort
Note sorting algorithm rework
This commit is contained in:
@@ -113,11 +113,19 @@ public:
|
||||
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
|
||||
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user