Changeset 1549

Show
Ignore:
Timestamp:
02/01/10 01:35:22 (3 years ago)
Author:
wolke
Message:

add "drag and drop intrument from library" to undo stack

Location:
branches/undo
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • branches/undo/gui/src/PatternEditor/DrumPatternEditor.cpp

    r1547 r1549  
    12741274        m_pPatternEditorPanel->getPianoRollEditor()->updateEditor(); 
    12751275} 
     1276 
     1277 
     1278void DrumPatternEditor::functionMoveInstrumentAction( int nSourceInstrument,  int nTargetInstrument ) 
     1279{ 
     1280                Hydrogen *engine = Hydrogen::get_instance(); 
     1281                AudioEngine::get_instance()->lock( RIGHT_HERE ); 
     1282 
     1283                Song *pSong = engine->getSong(); 
     1284                InstrumentList *pInstrumentList = pSong->get_instrument_list(); 
     1285 
     1286                if ( ( nTargetInstrument > (int)pInstrumentList->get_size() ) || ( nTargetInstrument < 0) ) { 
     1287                        AudioEngine::get_instance()->unlock(); 
     1288                        return; 
     1289                } 
     1290 
     1291 
     1292                // move instruments... 
     1293 
     1294                Instrument *pSourceInstr = pInstrumentList->get(nSourceInstrument); 
     1295                if ( nSourceInstrument < nTargetInstrument) { 
     1296                        for (int nInstr = nSourceInstrument; nInstr < nTargetInstrument; nInstr++) { 
     1297                                Instrument * pInstr = pInstrumentList->get(nInstr + 1); 
     1298                                pInstrumentList->replace( pInstr, nInstr ); 
     1299                        } 
     1300                        pInstrumentList->replace( pSourceInstr, nTargetInstrument ); 
     1301                } 
     1302                else { 
     1303                        for (int nInstr = nSourceInstrument; nInstr >= nTargetInstrument; nInstr--) { 
     1304                                Instrument * pInstr = pInstrumentList->get(nInstr - 1); 
     1305                                pInstrumentList->replace( pInstr, nInstr ); 
     1306                        } 
     1307                        pInstrumentList->replace( pSourceInstr, nTargetInstrument ); 
     1308                } 
     1309 
     1310                #ifdef JACK_SUPPORT 
     1311                engine->renameJackPorts(); 
     1312                #endif 
     1313 
     1314                AudioEngine::get_instance()->unlock(); 
     1315                engine->setSelectedInstrumentNumber( nTargetInstrument ); 
     1316 
     1317                pSong->__is_modified = true; 
     1318} 
     1319 
     1320 
     1321void  DrumPatternEditor::functionDropInstrumentUndoAction( int nTargetInstrument ) 
     1322{ 
     1323        Hydrogen *pEngine = Hydrogen::get_instance(); 
     1324        pEngine->removeInstrument( nTargetInstrument, false ); 
     1325         
     1326        AudioEngine::get_instance()->lock( RIGHT_HERE ); 
     1327#ifdef JACK_SUPPORT 
     1328        pEngine->renameJackPorts(); 
     1329#endif 
     1330        AudioEngine::get_instance()->unlock(); 
     1331        updateEditor(); 
     1332} 
     1333 
     1334 
     1335void  DrumPatternEditor::functionDropInstrumentRedoAction( QString sDrumkitName, QString sInstrumentName, int nTargetInstrument ) 
     1336{ 
     1337                Instrument *pNewInstrument = Instrument::load_instrument( sDrumkitName, sInstrumentName ); 
     1338                if( pNewInstrument == NULL ) return;             
     1339 
     1340                Hydrogen *pEngine = Hydrogen::get_instance(); 
     1341 
     1342                // create a new valid ID for this instrument 
     1343                int nID = -1; 
     1344                for ( uint i = 0; i < pEngine->getSong()->get_instrument_list()->get_size(); ++i ) { 
     1345                        Instrument* pInstr = pEngine->getSong()->get_instrument_list()->get( i ); 
     1346                        if ( pInstr->get_id().toInt() > nID ) { 
     1347                                nID = pInstr->get_id().toInt(); 
     1348                        } 
     1349                } 
     1350                ++nID; 
     1351 
     1352                pNewInstrument->set_id( QString("%1").arg( nID ) ); 
     1353 
     1354                AudioEngine::get_instance()->lock( RIGHT_HERE ); 
     1355                pEngine->getSong()->get_instrument_list()->add( pNewInstrument ); 
     1356 
     1357                #ifdef JACK_SUPPORT 
     1358                pEngine->renameJackPorts(); 
     1359                #endif 
     1360 
     1361                AudioEngine::get_instance()->unlock(); 
     1362                //move instrument to the position where it was dropped 
     1363                functionMoveInstrumentAction(pEngine->getSong()->get_instrument_list()->get_size() - 1 , nTargetInstrument ); 
     1364 
     1365                // select the new instrument 
     1366                pEngine->setSelectedInstrumentNumber(nTargetInstrument); 
     1367                updateEditor(); 
     1368} 
    12761369///~undo / redo actions from pattern editor instrument list 
    12771370///========================================================== 
  • branches/undo/gui/src/PatternEditor/DrumPatternEditor.h

    r1547 r1549  
    9191                void functionFillNotesRedoAction( QStringList noteList, int nSelectedInstrument, int patternNumber ); 
    9292                void functionRandomVelocityAction( QStringList noteVeloValue, int nSelectedInstrument, int selectedPatternNumber ); 
     93                void functionMoveInstrumentAction( int nSourceInstrument,  int nTargetInstrument ); 
     94                void functionDropInstrumentUndoAction( int nTargetInstrument ); 
     95                void functionDropInstrumentRedoAction( QString sDrumkitName, QString sInstrumentName, int nTargetInstrument ); 
    9396 
    9497        public slots: 
  • branches/undo/gui/src/PatternEditor/PatternEditorInstrumentList.cpp

    r1547 r1549  
    440440 
    441441 
    442 void PatternEditorInstrumentList::moveInstrumentLine( int nSourceInstrument , int nTargetInstrument ) 
    443 { 
    444                 Hydrogen *engine = Hydrogen::get_instance(); 
    445                 AudioEngine::get_instance()->lock( RIGHT_HERE ); 
    446  
    447                 Song *pSong = engine->getSong(); 
    448                 InstrumentList *pInstrumentList = pSong->get_instrument_list(); 
    449  
    450                 if ( ( nTargetInstrument > (int)pInstrumentList->get_size() ) || ( nTargetInstrument < 0) ) { 
    451                         AudioEngine::get_instance()->unlock(); 
    452                         return; 
    453                 } 
    454  
    455  
    456                 // move instruments... 
    457  
    458                 Instrument *pSourceInstr = pInstrumentList->get(nSourceInstrument); 
    459                 if ( nSourceInstrument < nTargetInstrument) { 
    460                         for (int nInstr = nSourceInstrument; nInstr < nTargetInstrument; nInstr++) { 
    461                                 Instrument * pInstr = pInstrumentList->get(nInstr + 1); 
    462                                 pInstrumentList->replace( pInstr, nInstr ); 
    463                         } 
    464                         pInstrumentList->replace( pSourceInstr, nTargetInstrument ); 
    465                 } 
    466                 else { 
    467                         for (int nInstr = nSourceInstrument; nInstr >= nTargetInstrument; nInstr--) { 
    468                                 Instrument * pInstr = pInstrumentList->get(nInstr - 1); 
    469                                 pInstrumentList->replace( pInstr, nInstr ); 
    470                         } 
    471                         pInstrumentList->replace( pSourceInstr, nTargetInstrument ); 
    472                 } 
    473  
    474                 #ifdef JACK_SUPPORT 
    475                 engine->renameJackPorts(); 
    476                 #endif 
    477  
    478                 AudioEngine::get_instance()->unlock(); 
    479                 engine->setSelectedInstrumentNumber( nTargetInstrument ); 
    480  
    481                 pSong->__is_modified = true; 
    482 } 
    483442 
    484443/// 
     
    573532                } 
    574533 
    575                 moveInstrumentLine( nSourceInstrument , nTargetInstrument ); 
     534                SE_moveInstrumentAction *action = new SE_moveInstrumentAction( nSourceInstrument, nTargetInstrument ); 
     535                HydrogenApp::get_instance()->m_undoStack->push( action ); 
    576536 
    577537                event->acceptProposedAction(); 
     
    585545                QString sDrumkitName = tokens.at( 0 ); 
    586546                QString sInstrumentName = tokens.at( 1 ); 
    587                  
    588                 Instrument *pNewInstrument = Instrument::load_instrument( sDrumkitName, sInstrumentName ); 
    589                 if( pNewInstrument == NULL ) return;             
    590  
    591                 Hydrogen *pEngine = Hydrogen::get_instance(); 
    592  
    593                 // create a new valid ID for this instrument 
    594                 int nID = -1; 
    595                 for ( uint i = 0; i < pEngine->getSong()->get_instrument_list()->get_size(); ++i ) { 
    596                         Instrument* pInstr = pEngine->getSong()->get_instrument_list()->get( i ); 
    597                         if ( pInstr->get_id().toInt() > nID ) { 
    598                                 nID = pInstr->get_id().toInt(); 
    599                         } 
    600                 } 
    601                 ++nID; 
    602  
    603                 pNewInstrument->set_id( QString("%1").arg( nID ) ); 
    604  
    605                 AudioEngine::get_instance()->lock( RIGHT_HERE ); 
    606                 pEngine->getSong()->get_instrument_list()->add( pNewInstrument ); 
    607  
    608                 #ifdef JACK_SUPPORT 
    609                 pEngine->renameJackPorts(); 
    610                 #endif 
    611  
    612                 AudioEngine::get_instance()->unlock(); 
    613  
    614          
     547 
    615548                int nTargetInstrument = event->pos().y() / m_nGridHeight; 
    616549 
     
    619552                    Because the right part of the grid starts above the name column, we have to subtract the difference  
    620553                */ 
    621  
    622554                if (  event->pos().x() > 181 ) nTargetInstrument = ( event->pos().y() - 90 )  / m_nGridHeight ; 
    623555 
    624                 //move instrument to the position where it was dropped 
    625                 moveInstrumentLine(pEngine->getSong()->get_instrument_list()->get_size() - 1 , nTargetInstrument ); 
    626  
    627  
    628  
    629                 // select the new instrument 
    630                 pEngine->setSelectedInstrumentNumber(nTargetInstrument); 
     556                SE_dragInstrumentAction *action = new SE_dragInstrumentAction( sDrumkitName, sInstrumentName, nTargetInstrument ); 
     557                HydrogenApp::get_instance()->m_undoStack->push( action ); 
    631558 
    632559                event->acceptProposedAction(); 
  • branches/undo/gui/src/PatternEditor/PatternEditorInstrumentList.h

    r1494 r1549  
    117117 
    118118                InstrumentLine* createInstrumentLine(); 
    119                 void moveInstrumentLine(int,int); 
    120119 
    121120}; 
  • branches/undo/gui/src/UndoActions.h

    r1547 r1549  
    720720        int __nSelectedInstrument; 
    721721        int __selectedPatternNumber; 
     722}; 
     723 
     724 
     725 
     726class SE_moveInstrumentAction : public QUndoCommand 
     727{ 
     728public: 
     729        SE_moveInstrumentAction(  int nSourceInstrument, int nTargetInstrument  ){ 
     730        setText( QString( "move Instrument" ) ); 
     731        __nSourceInstrument = nSourceInstrument; 
     732        __nTargetInstrument = nTargetInstrument; 
     733        } 
     734        virtual void undo() 
     735        { 
     736                qDebug() << "move Instrument Undo "; 
     737                HydrogenApp* h2app = HydrogenApp::get_instance(); 
     738                h2app->getPatternEditorPanel()->getDrumPatternEditor()->functionMoveInstrumentAction( __nTargetInstrument, __nSourceInstrument ); 
     739        } 
     740        virtual void redo() 
     741        { 
     742                qDebug() << "move Instrument Redo " ; 
     743                HydrogenApp* h2app = HydrogenApp::get_instance(); 
     744                h2app->getPatternEditorPanel()->getDrumPatternEditor()->functionMoveInstrumentAction( __nSourceInstrument, __nTargetInstrument ); 
     745        } 
     746private: 
     747        int __nSourceInstrument; 
     748        int __nTargetInstrument; 
     749}; 
     750 
     751class SE_dragInstrumentAction : public QUndoCommand 
     752{ 
     753public: 
     754        SE_dragInstrumentAction(  QString sDrumkitName, QString sInstrumentName, int nTargetInstrument  ){ 
     755        setText( QString( "drop Instrument" ) ); 
     756        __sDrumkitName = sDrumkitName; 
     757        __sInstrumentName = sInstrumentName; 
     758        __nTargetInstrument = nTargetInstrument; 
     759        } 
     760        virtual void undo() 
     761        { 
     762                qDebug() << "drop Instrument Undo "; 
     763                HydrogenApp* h2app = HydrogenApp::get_instance(); 
     764                h2app->getPatternEditorPanel()->getDrumPatternEditor()->functionDropInstrumentUndoAction( __nTargetInstrument ); 
     765        } 
     766        virtual void redo() 
     767        { 
     768                qDebug() << "drop Instrument Redo " ; 
     769                HydrogenApp* h2app = HydrogenApp::get_instance(); 
     770                h2app->getPatternEditorPanel()->getDrumPatternEditor()->functionDropInstrumentRedoAction( __sDrumkitName, __sInstrumentName, __nTargetInstrument ); 
     771        } 
     772private: 
     773        QString __sDrumkitName; 
     774        QString __sInstrumentName; 
     775        int __nTargetInstrument; 
    722776}; 
    723777//~pattern editor commands 
  • branches/undo/undo_implementation_todo

    r1548 r1549  
    3333 + Context menu fill notes                                      | Done 
    3434 + Context menu random velocity                                 | Done 
    35  + Add/delete instrument                                        | ---- 
     35 + Drag and drop instruments order                              | Done 
     36 + Context menu Delete instrument                               | ---- 
    3637 + Drag and drop intrument from library                         | ---- 
    37  + Drag and drop instruments order                              | ---- 
     38 + Main menu Add instrument                                     | ---- 
    3839 
    3940 
     
    4344 + Edit lead lag                                                | Done 
    4445 + Edit note key                                                | Done 
    45