Skip to content

Commit

Permalink
fix copy/cut & paste TRIS: fix deselectAndOverwriteNotes()
Browse files Browse the repository at this point in the history
  • Loading branch information
oddtime committed Apr 28, 2021
1 parent d7dbd23 commit 3101b64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/Basics/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void Pattern::save_to( XMLNode* node, const Instrument* instrumentOnly ) const
}
}

Note* Pattern::find_note( double idx_a, int idx_b, Instrument* instrument, Note::Key key, Note::Octave octave, bool strict ) const // TODO tolerance epsilon
Note* Pattern::find_note( double idx_a, int idx_b, Instrument* instrument, Note::Key key, Note::Octave octave, bool strict ) const
{
for( notes_cst_it_t it=__notes.lower_bound( idx_a - POS_EPSILON ) ; it!=__notes.upper_bound( idx_a + POS_EPSILON ); it++ ) {
Note* note = it->second;
Expand Down Expand Up @@ -179,7 +179,7 @@ Note* Pattern::find_note( double idx_a, int idx_b, Instrument* instrument, Note:
Note* Pattern::find_note( double idx_a, int idx_b, Instrument* instrument, bool strict ) const
{
notes_cst_it_t it;
for( it=__notes.lower_bound( idx_a - POS_EPSILON ); it!=__notes.upper_bound( idx_a + POS_EPSILON ); it++ ) { // TODO tolerance epsilon
for( it=__notes.lower_bound( idx_a - POS_EPSILON ); it!=__notes.upper_bound( idx_a + POS_EPSILON ); it++ ) {
Note* note = it->second;
assert( note );
if ( note->get_instrument() == instrument ) return note;
Expand Down
8 changes: 5 additions & 3 deletions src/gui/src/PatternEditor/PatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void PatternEditor::updateModifiers( QInputEvent *ev ) {

bool PatternEditor::notesMatchExactly( Note *pNoteA, Note *pNoteB ) const {
return ( pNoteA->match( pNoteB->get_instrument(), pNoteB->get_key(), pNoteB->get_octave() )
&& pNoteA->get_position() == pNoteB->get_position()
&& fabs( pNoteA->get_position() - pNoteB->get_position() ) < 2 * POS_EPSILON
&& pNoteA->get_velocity() == pNoteB->get_velocity()
&& pNoteA->get_pan_r() == pNoteB->get_pan_r()
&& pNoteA->get_pan_l() == pNoteB->get_pan_l()
Expand Down Expand Up @@ -484,13 +484,15 @@ void PatternEditor::deselectAndOverwriteNotes( std::vector< H2Core::Note *> &sel
m_selection.removeFromSelection( pSelectedNote, /* bCheck=*/false );
bool bFoundExact = false;
double fPosition = pSelectedNote->get_position();
FOREACH_NOTE_IT_BOUND( pNotes, it, fPosition) {
for ( auto it = pNotes->lower_bound( fPosition - POS_EPSILON );
it != pNotes->end() && it->first < fPosition + POS_EPSILON; ) { // NOTE: counter not incremented here!
Note *pNote = it->second;
if ( !bFoundExact && notesMatchExactly( pNote, pSelectedNote ) ) {
// Found an exact match. We keep this.
bFoundExact = true;
++it;
} else if ( pSelectedNote->match( pNote ) && pNote->get_position() == pSelectedNote->get_position() ) { //TODO tolerance
} else if ( pSelectedNote->match( pNote ) // match key, octave & instrument
&& fabs( pNote->get_position() - pSelectedNote->get_position() ) < 2 * POS_EPSILON ) {
// Something else occupying the same position (which may or may not be an exact duplicate)
it = pNotes->erase( it );
} else {
Expand Down

0 comments on commit 3101b64

Please sign in to comment.