Changeset 1549
- Timestamp:
- 02/01/10 01:35:22 (3 years ago)
- Location:
- branches/undo
- Files:
-
- 6 modified
-
gui/src/PatternEditor/DrumPatternEditor.cpp (modified) (1 diff)
-
gui/src/PatternEditor/DrumPatternEditor.h (modified) (1 diff)
-
gui/src/PatternEditor/PatternEditorInstrumentList.cpp (modified) (4 diffs)
-
gui/src/PatternEditor/PatternEditorInstrumentList.h (modified) (1 diff)
-
gui/src/UndoActions.h (modified) (1 diff)
-
undo_implementation_todo (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/undo/gui/src/PatternEditor/DrumPatternEditor.cpp
r1547 r1549 1274 1274 m_pPatternEditorPanel->getPianoRollEditor()->updateEditor(); 1275 1275 } 1276 1277 1278 void 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 1321 void 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 1335 void 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 } 1276 1369 ///~undo / redo actions from pattern editor instrument list 1277 1370 ///========================================================== -
branches/undo/gui/src/PatternEditor/DrumPatternEditor.h
r1547 r1549 91 91 void functionFillNotesRedoAction( QStringList noteList, int nSelectedInstrument, int patternNumber ); 92 92 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 ); 93 96 94 97 public slots: -
branches/undo/gui/src/PatternEditor/PatternEditorInstrumentList.cpp
r1547 r1549 440 440 441 441 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_SUPPORT475 engine->renameJackPorts();476 #endif477 478 AudioEngine::get_instance()->unlock();479 engine->setSelectedInstrumentNumber( nTargetInstrument );480 481 pSong->__is_modified = true;482 }483 442 484 443 /// … … 573 532 } 574 533 575 moveInstrumentLine( nSourceInstrument , nTargetInstrument ); 534 SE_moveInstrumentAction *action = new SE_moveInstrumentAction( nSourceInstrument, nTargetInstrument ); 535 HydrogenApp::get_instance()->m_undoStack->push( action ); 576 536 577 537 event->acceptProposedAction(); … … 585 545 QString sDrumkitName = tokens.at( 0 ); 586 546 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 615 548 int nTargetInstrument = event->pos().y() / m_nGridHeight; 616 549 … … 619 552 Because the right part of the grid starts above the name column, we have to subtract the difference 620 553 */ 621 622 554 if ( event->pos().x() > 181 ) nTargetInstrument = ( event->pos().y() - 90 ) / m_nGridHeight ; 623 555 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 ); 631 558 632 559 event->acceptProposedAction(); -
branches/undo/gui/src/PatternEditor/PatternEditorInstrumentList.h
r1494 r1549 117 117 118 118 InstrumentLine* createInstrumentLine(); 119 void moveInstrumentLine(int,int);120 119 121 120 }; -
branches/undo/gui/src/UndoActions.h
r1547 r1549 720 720 int __nSelectedInstrument; 721 721 int __selectedPatternNumber; 722 }; 723 724 725 726 class SE_moveInstrumentAction : public QUndoCommand 727 { 728 public: 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 } 746 private: 747 int __nSourceInstrument; 748 int __nTargetInstrument; 749 }; 750 751 class SE_dragInstrumentAction : public QUndoCommand 752 { 753 public: 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 } 772 private: 773 QString __sDrumkitName; 774 QString __sInstrumentName; 775 int __nTargetInstrument; 722 776 }; 723 777 //~pattern editor commands -
branches/undo/undo_implementation_todo
r1548 r1549 33 33 + Context menu fill notes | Done 34 34 + Context menu random velocity | Done 35 + Add/delete instrument | ---- 35 + Drag and drop instruments order | Done 36 + Context menu Delete instrument | ---- 36 37 + Drag and drop intrument from library | ---- 37 + Drag and drop instruments order| ----38 + Main menu Add instrument | ---- 38 39 39 40 … … 43 44 + Edit lead lag | Done 44 45 + Edit note key | Done 45