Changeset 2266

Show
Ignore:
Timestamp:
07/12/11 14:37:15 (23 months ago)
Author:
jeremyz
Message:

use Pattern::find_note and Pattern::remove_note

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/src/PatternEditor/PianoRollEditor.cpp

    r2260 r2266  
    522522                } 
    523523 
    524                 H2Core::Note *pDraggedNote; 
    525                 pDraggedNote = NULL; 
    526                  
    527                 std::multimap <int, Note*>::iterator pos; 
    528                 for ( pos = m_pPattern->note_map.lower_bound( nColumn ); pos != m_pPattern->note_map.upper_bound( nColumn ); ++pos ) { 
    529                         Note *pNote = pos->second; 
    530                         assert( pNote ); 
    531  
    532                         if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument) { 
    533                                 pDraggedNote = pNote; 
    534                                 break; 
    535                         } 
    536                 } 
    537                 if ( !pDraggedNote ) { 
    538                         for ( pos = m_pPattern->note_map.lower_bound( nRealColumn ); pos != m_pPattern->note_map.upper_bound( nRealColumn ); ++pos ) { 
    539                                 Note *pNote = pos->second; 
    540                                 assert( pNote ); 
    541  
    542                                 if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument) { 
    543                                         pDraggedNote = pNote; 
    544                                         break; 
    545                                 } 
    546                         }        
    547  
    548                 } 
     524        H2Core::Note* pDraggedNote = 0; 
     525        pDraggedNote = m_pPattern->find_note( nColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     526        if ( !pDraggedNote ) { 
     527            pDraggedNote = m_pPattern->find_note( nRealColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     528        } 
    549529 
    550530                int oldLength = -1; 
     
    609589//              AudioEngine::get_instance()->lock( RIGHT_HERE ); 
    610590 
    611                 std::multimap <int, Note*>::iterator pos; 
    612                 for ( pos = m_pPattern->note_map.lower_bound( nColumn ); pos != m_pPattern->note_map.upper_bound( nColumn ); ++pos ) { 
    613                         Note *pNote = pos->second; 
    614                         assert( pNote ); 
    615  
    616                         if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument) { 
    617                                 m_pDraggedNote = pNote; 
    618                                 break; 
    619                         } 
    620                 } 
    621                 if ( !m_pDraggedNote ) { 
    622                         for ( pos = m_pPattern->note_map.lower_bound( nRealColumn ); pos != m_pPattern->note_map.upper_bound( nRealColumn ); ++pos ) { 
    623                                 Note *pNote = pos->second; 
    624                                 assert( pNote ); 
    625  
    626                                 if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument) { 
    627                                         m_pDraggedNote = pNote; 
    628                                         break; 
    629                                 } 
    630                         }        
    631  
    632                 } 
    633  
    634                 for ( int nCol = 0; unsigned(nCol) < nRealColumn; ++nCol ) { 
    635                         if ( m_pDraggedNote ) break; 
    636                         for ( pos = m_pPattern->note_map.lower_bound( nCol ); pos != m_pPattern->note_map.upper_bound( nCol ); ++pos ) { 
    637                                 Note *pNote = pos->second; 
    638                                 assert( pNote ); 
    639  
    640                                 if ( ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument ) 
    641                                     && ( (nRealColumn <= pNote->get_position() + pNote->get_length() ) 
    642                                     && nRealColumn >= pNote->get_position() ) ){ 
    643                                         m_pDraggedNote = pNote; 
    644                                         break; 
    645                                 } 
    646                         } 
    647                 } 
    648  
    649  
     591        m_pDraggedNote = m_pPattern->find_note( nColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     592        if ( !m_pDraggedNote ) { 
     593            m_pDraggedNote = m_pPattern->find_note( nRealColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     594        } 
     595        if ( !m_pDraggedNote ) { 
     596            m_pDraggedNote = m_pPattern->find_note( nRealColumn, pSelectedInstrument, pressednotekey, pressedoctave, false ); 
     597        } 
    650598 
    651599                //needed for undo note length 
     
    715663 
    716664        bool bNoteAlreadyExist = false; 
    717         AudioEngine::get_instance()->lock( RIGHT_HERE );        // lock the audio engine 
    718         std::multimap <int, Note*>::iterator pos; 
    719         for ( pos = pPattern->note_map.lower_bound( nColumn ); pos != pPattern->note_map.upper_bound( nColumn ); ++pos ) { 
    720                 Note *pNote = pos->second; 
    721                 assert( pNote ); 
    722                 if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument ) { 
    723                         // the note exists...remove it! 
    724                         bNoteAlreadyExist = true; 
    725                         delete pNote; 
    726                         pPattern->note_map.erase( pos ); 
    727                         break; 
    728                 } 
    729         } 
     665    AudioEngine::get_instance()->lock( RIGHT_HERE );    // lock the audio engine 
     666    Note* note = m_pPattern->find_note( nColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     667    if( note ) { 
     668        // the note exists...remove it! 
     669        bNoteAlreadyExist = true; 
     670        m_pPattern->remove_note( note ); 
     671        delete note; 
     672    } 
    730673 
    731674        if ( bNoteAlreadyExist == false ) { 
     
    1040983        } 
    1041984 
    1042         Note *pDraggedNote; 
    1043985        Song *pSong = pEngine->getSong(); 
    1044986        int nInstruments = pSong->get_instrument_list()->size(); 
     
    1046988        Instrument *pSelectedInstrument = pSong->get_instrument_list()->get( nSelectedInstrumentnumber ); 
    1047989 
    1048         AudioEngine::get_instance()->lock( RIGHT_HERE ); 
    1049990 
    1050991    Note::Octave pressedoctave = (Note::Octave)(3 - (pressedline / 12 )); 
     
    1058999        } 
    10591000 
    1060         std::multimap <int, Note*>::iterator pos; 
    1061         for ( pos = pPattern->note_map.lower_bound( nColumn ); pos != pPattern->note_map.upper_bound( nColumn ); ++pos ) { 
    1062                 Note *pNote = pos->second; 
    1063                 assert( pNote ); 
    1064  
    1065                 if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument) { 
    1066                         pDraggedNote = pNote; 
    1067                         break; 
    1068                 } 
    1069         } 
    1070         if ( !pDraggedNote ) { 
    1071                 for ( pos = pPattern->note_map.lower_bound( nRealColumn ); pos != pPattern->note_map.upper_bound( nRealColumn ); ++pos ) { 
    1072                         Note *pNote = pos->second; 
    1073                         assert( pNote ); 
    1074  
    1075                         if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument) { 
    1076                                 pDraggedNote = pNote; 
    1077                                 break; 
    1078                         } 
    1079                 }        
    1080  
    1081         } 
    1082  
    1083         for ( int nCol = 0; unsigned(nCol) < nRealColumn; ++nCol ) { 
    1084                 if ( pDraggedNote ) break; 
    1085                 for ( pos = pPattern->note_map.lower_bound( nCol ); pos != pPattern->note_map.upper_bound( nCol ); ++pos ) { 
    1086                         Note *pNote = pos->second; 
    1087                         assert( pNote ); 
    1088  
    1089                         if ( ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument ) 
    1090                                 && ( (nRealColumn <= pNote->get_position() + pNote->get_length() ) 
    1091                                 && nRealColumn >= pNote->get_position() ) ){ 
    1092                                 pDraggedNote = pNote; 
    1093                                 break; 
    1094                         } 
    1095                 } 
    1096         } 
    1097  
    1098  
    1099         if ( pDraggedNote ){ 
    1100                 pDraggedNote->set_length( length ); 
    1101         } 
    1102         AudioEngine::get_instance()->unlock(); 
     1001    Note* pDraggedNote = 0; 
     1002    AudioEngine::get_instance()->lock( RIGHT_HERE ); 
     1003    pDraggedNote = m_pPattern->find_note( nColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     1004    if ( !pDraggedNote ) { 
     1005        pDraggedNote = m_pPattern->find_note( nRealColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     1006    } 
     1007    if ( !pDraggedNote ) { 
     1008        pDraggedNote = m_pPattern->find_note( nRealColumn, pSelectedInstrument, pressednotekey, pressedoctave, false ); 
     1009    } 
     1010    if ( pDraggedNote ){ 
     1011        pDraggedNote->set_length( length ); 
     1012    } 
     1013    AudioEngine::get_instance()->unlock(); 
    11031014        updateEditor(); 
    11041015        m_pPatternEditorPanel->getVelocityEditor()->updateEditor(); 
     
    11441055        } 
    11451056 
    1146         Note *pDraggedNote; 
    11471057        Song *pSong = pEngine->getSong(); 
    11481058        int nInstruments = pSong->get_instrument_list()->size(); 
     
    11501060        Instrument *pSelectedInstrument = pSong->get_instrument_list()->get( selectedInstrumentnumber ); 
    11511061 
    1152         AudioEngine::get_instance()->lock( RIGHT_HERE ); 
    1153  
    1154         std::multimap <int, Note*>::iterator pos; 
    1155         for ( pos = pPattern->note_map.lower_bound( nColumn ); pos != pPattern->note_map.upper_bound( nColumn ); ++pos ) { 
    1156                 Note *pNote = pos->second; 
    1157                 assert( pNote ); 
    1158  
    1159                 if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument) { 
    1160                         pDraggedNote = pNote; 
    1161                         break; 
    1162                 } 
    1163         } 
    1164         if ( !pDraggedNote ) { 
    1165                 for ( pos = pPattern->note_map.lower_bound( nRealColumn ); pos != pPattern->note_map.upper_bound( nRealColumn ); ++pos ) { 
    1166                         Note *pNote = pos->second; 
    1167                         assert( pNote ); 
    1168  
    1169                         if ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument) { 
    1170                                 pDraggedNote = pNote; 
    1171                                 break; 
    1172                         } 
    1173                 }        
    1174  
    1175         } 
    1176  
    1177         for ( int nCol = 0; unsigned(nCol) < nRealColumn; ++nCol ) { 
    1178                 if ( pDraggedNote ) break; 
    1179                 for ( pos = pPattern->note_map.lower_bound( nCol ); pos != pPattern->note_map.upper_bound( nCol ); ++pos ) { 
    1180                         Note *pNote = pos->second; 
    1181                         assert( pNote ); 
    1182  
    1183                         if ( ( pNote->get_octave() ==  pressedoctave && pNote->get_key()  ==  pressednotekey && pNote->get_instrument() == pSelectedInstrument ) 
    1184                                 && ( (nRealColumn <= pNote->get_position() + pNote->get_length() ) 
    1185                                 && nRealColumn >= pNote->get_position() ) ){ 
    1186                                 pDraggedNote = pNote; 
    1187                                 break; 
    1188                         } 
    1189                 } 
    1190         } 
    1191  
     1062    Note* pDraggedNote = 0; 
     1063    AudioEngine::get_instance()->lock( RIGHT_HERE ); 
     1064    pDraggedNote = m_pPattern->find_note( nColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     1065    if ( !m_pDraggedNote ) { 
     1066        pDraggedNote = m_pPattern->find_note( nRealColumn, pSelectedInstrument, pressednotekey, pressedoctave ); 
     1067    } 
     1068    if ( !pDraggedNote ) { 
     1069        pDraggedNote = m_pPattern->find_note( nRealColumn, pSelectedInstrument, pressednotekey, pressedoctave, false ); 
     1070    } 
    11921071        if ( pDraggedNote ){ 
    11931072                pDraggedNote->set_velocity( velocity ); 
    11941073                pDraggedNote->set_pan_l( pan_L ); 
    1195                 pDraggedNote->set_pan_r( pan_R );        
     1074                pDraggedNote->set_pan_r( pan_R ); 
    11961075                pDraggedNote->set_lead_lag( leadLag ); 
    11971076        }