Hi all,

Here's my patch for the cut/copy/paste
for the undo branche revision 1620.

Hope you will try it.

Dave


Index: gui/src/PatternEditor/PatternEditorInstrumentList.h
===================================================================
--- gui/src/PatternEditor/PatternEditorInstrumentList.h	(revision 1620)
+++ gui/src/PatternEditor/PatternEditorInstrumentList.h	(working copy)
@@ -57,7 +57,11 @@
 	private slots:
 		void functionClearNotes();
 
-		void functionFillAllNotes();
+                void functionCopyNotes(); //added cut
+                void functionCutNotes(); //added copy
+                void functionPasteNotes(); //added paste
+
+                void functionFillAllNotes();
 		void functionFillEveryTwoNotes();
 		void functionFillEveryThreeNotes();
 		void functionFillEveryFourNotes();
Index: gui/src/PatternEditor/DrumPatternEditor.h
===================================================================
--- gui/src/PatternEditor/DrumPatternEditor.h	(revision 1620)
+++ gui/src/PatternEditor/DrumPatternEditor.h	(working copy)
@@ -58,6 +58,7 @@
 		void zoom_out();
 
 		static QColor computeNoteColor( float );
+                std::multimap <int, H2Core::Note*> tmpPattern;//for remembering copy/paste
 
 		// Implements EventListener interface
 		virtual void patternModifiedEvent();
@@ -89,6 +90,8 @@
 					int octaveKeyVal );
 		void functionClearNotesRedoAction( int nSelectedInstrument, int selectedPatternNumber );
 		void functionClearNotesUndoAction( std::list< H2Core::Note* > noteList, int nSelectedInstrument, int patternNumber );
+                void functionPasteNotesRedoAction( std::multimap< int, H2Core::Note* > noteMap, int nSelectedInstrument, int patternNumber );
+                void functionPasteNotesUndoAction( std::multimap< int, H2Core::Note* > noteMap, int nSelectedInstrument, int patternNumber );
 		void functionFillNotesUndoAction( QStringList noteList, int nSelectedInstrument, int patternNumber );
 		void functionFillNotesRedoAction( QStringList noteList, int nSelectedInstrument, int patternNumber );
 		void functionRandomVelocityAction( QStringList noteVeloValue, int nSelectedInstrument, int selectedPatternNumber );
Index: gui/src/PatternEditor/PatternEditorInstrumentList.cpp
===================================================================
--- gui/src/PatternEditor/PatternEditorInstrumentList.cpp	(revision 1620)
+++ gui/src/PatternEditor/PatternEditorInstrumentList.cpp	(working copy)
@@ -92,6 +92,9 @@
 	// Popup menu
 	m_pFunctionPopup = new QMenu( this );
 	m_pFunctionPopup->addAction( trUtf8( "Clear notes" ), this, SLOT( functionClearNotes() ) );
+        m_pFunctionPopup->addAction( trUtf8( "Cut notes" ), this, SLOT( functionCutNotes() ) );
+        m_pFunctionPopup->addAction( trUtf8( "Copy notes" ), this, SLOT( functionCopyNotes() ) );
+        m_pFunctionPopup->addAction( trUtf8( "Paste notes" ), this, SLOT( functionPasteNotes() ) );
 	m_pFunctionPopupSub = new QMenu( trUtf8( "Fill notes ..." ), m_pFunctionPopup );
 	m_pFunctionPopupSub->addAction( trUtf8( "Fill all notes" ), this, SLOT( functionFillAllNotes() ) );
 	m_pFunctionPopupSub->addAction( trUtf8( "Fill 1/2 notes" ), this, SLOT( functionFillEveryTwoNotes() ) );
@@ -246,7 +249,72 @@
 	}
 }
 
+void InstrumentLine::functionCutNotes()
+{
+        functionCopyNotes();
+        functionClearNotes();
+}
 
+
+void InstrumentLine::functionCopyNotes()
+{
+        Hydrogen *pEngine = Hydrogen::get_instance();
+        Pattern *pCurrentPattern = getCurrentPattern();
+        int nSelectedInstrument = pEngine->getSelectedInstrumentNumber();
+        DrumPatternEditor *pCurrentDrumPatternEditor = HydrogenApp::get_instance()->getPatternEditorPanel()->getDrumPatternEditor();
+
+        Instrument *instrRef = (pEngine->getSong()->get_instrument_list())->get( nSelectedInstrument );
+
+        for(std::multimap<int, Note*>::iterator i=pCurrentPattern->note_map.begin();i!=pCurrentPattern->note_map.end();++i){
+                if(i->second->get_instrument()==instrRef){ //only copy selected instrument notes -> like a clipboard
+                        pCurrentDrumPatternEditor->tmpPattern.insert(std::make_pair( i->first,new Note (i->second) ));//make copy in stead of references/pointers
+                }//the notes added with new are being destroyed by de destructor of the class DrumPatternEditor
+        }
+}
+
+void InstrumentLine::functionPasteNotes()
+{
+        Hydrogen *pEngine = Hydrogen::get_instance();
+        Pattern *pCurrentPattern = getCurrentPattern();
+        int nSelectedInstrument = pEngine->getSelectedInstrumentNumber();
+        DrumPatternEditor *pCurrentDrumPatternEditor = HydrogenApp::get_instance()->getPatternEditorPanel()->getDrumPatternEditor();
+
+        AudioEngine::get_instance()->lock( RIGHT_HERE );	// lock the audio engine -> still needed?
+
+        Instrument *instrRef = (pEngine->getSong()->get_instrument_list())->get( nSelectedInstrument );
+
+        for(std::multimap<int, Note*>::iterator j=pCurrentDrumPatternEditor->tmpPattern.begin();j!=pCurrentDrumPatternEditor->tmpPattern.end();++j){
+                j->second->set_instrument(instrRef);   //change references to selected instrument
+        }
+
+        //copy the old notemap for undo action
+        std::multimap<int, Note*> noteMap_old;
+        for(std::multimap<int, Note*>::iterator j=pCurrentPattern->note_map.begin();j!=pCurrentPattern->note_map.end();++j){
+                noteMap_old.insert(std::make_pair( j->first,new Note (j->second) ));//make copy in stead of references/pointers
+        }//the notes added with new are being destroyed by de destructor of the class SE_pasteNotesPatternEditorAction
+
+
+        //add copy of notes to the current note_map
+        for(std::multimap<int, Note*>::iterator j=pCurrentDrumPatternEditor->tmpPattern.begin();j!=pCurrentDrumPatternEditor->tmpPattern.end();++j){
+                pCurrentPattern->note_map.insert(std::make_pair( j->first,new Note (j->second) ));//make copy in stead of references/pointers
+        }
+
+        //copy the new notemap for redo action
+        std::multimap<int, Note*> noteMap_new;
+        for(std::multimap<int, Note*>::iterator j=pCurrentPattern->note_map.begin();j!=pCurrentPattern->note_map.end();++j){
+                noteMap_new.insert(std::make_pair( j->first,new Note (j->second) ));//make copy in stead of references/pointers
+        }//the notes added with new are being destroyed by de destructor of the class SE_pasteNotesPatternEditorAction
+
+        SE_pasteNotesPatternEditorAction *action = new SE_pasteNotesPatternEditorAction( noteMap_new,noteMap_old,nSelectedInstrument,pEngine->getSelectedPatternNumber());
+        HydrogenApp::get_instance()->m_undoStack->push( action );
+
+        AudioEngine::get_instance()->unlock();	// unlock the audio engine
+
+        // this will force an update...
+        EventQueue::get_instance()->push_event( EVENT_SELECTED_INSTRUMENT_CHANGED, -1 );
+
+}
+
 void InstrumentLine::functionFillAllNotes(){ functionFillNotes(1); }
 void InstrumentLine::functionFillEveryTwoNotes(){ functionFillNotes(2); }
 void InstrumentLine::functionFillEveryThreeNotes(){ functionFillNotes(3); }
Index: gui/src/PatternEditor/DrumPatternEditor.cpp
===================================================================
--- gui/src/PatternEditor/DrumPatternEditor.cpp	(revision 1620)
+++ gui/src/PatternEditor/DrumPatternEditor.cpp	(working copy)
@@ -77,6 +77,9 @@
 
 DrumPatternEditor::~DrumPatternEditor()
 {
+    for(std::multimap<int, Note*>::iterator j=tmpPattern.begin();j!=tmpPattern.end();++j){
+            delete j->second; //free memory
+    }
 }
 
 
@@ -1192,8 +1195,57 @@
 
 }
 
+void DrumPatternEditor::functionPasteNotesUndoAction( std::multimap< int, H2Core::Note* > noteMap, int nSelectedInstrument, int patternNumber )
+{
+        Hydrogen * H = Hydrogen::get_instance();
+        PatternList *pPatternList = Hydrogen::get_instance()->getSong()->get_pattern_list();
+        Pattern *pPattern = pPatternList->get( patternNumber );
 
+        for(std::multimap<int, Note*>::iterator j=pPattern->note_map.begin();j!=pPattern->note_map.end();++j){
+                delete j->second; //free memory
+        }
 
+        pPattern->note_map=noteMap;
+
+        for(std::multimap<int, Note*>::iterator j=pPattern->note_map.begin();j!=pPattern->note_map.end();++j){
+                j->second=new Note(j->second);   //make copy so it can be cleaned by the patterneditor and the source by the Undo Class
+        }
+
+        EventQueue::get_instance()->push_event( EVENT_SELECTED_INSTRUMENT_CHANGED, -1 );
+        updateEditor();
+        m_pPatternEditorPanel->getVelocityEditor()->updateEditor();
+        m_pPatternEditorPanel->getPanEditor()->updateEditor();
+        m_pPatternEditorPanel->getLeadLagEditor()->updateEditor();
+        m_pPatternEditorPanel->getNoteKeyEditor()->updateEditor();
+        m_pPatternEditorPanel->getPianoRollEditor()->updateEditor();
+
+}
+
+void DrumPatternEditor::functionPasteNotesRedoAction( std::multimap< int, H2Core::Note* > noteMap, int nSelectedInstrument, int patternNumber )
+{
+        Hydrogen * H = Hydrogen::get_instance();
+        PatternList *pPatternList = Hydrogen::get_instance()->getSong()->get_pattern_list();
+        Pattern *pPattern = pPatternList->get( patternNumber );
+
+        for(std::multimap<int, Note*>::iterator j=pPattern->note_map.begin();j!=pPattern->note_map.end();++j){
+                delete j->second; //free memory
+        }
+        pPattern->note_map=noteMap;
+
+        for(std::multimap<int, Note*>::iterator j=pPattern->note_map.begin();j!=pPattern->note_map.end();++j){
+                j->second=new Note(j->second);   //make copy so it can be cleaned by the patterneditor and the source by the Undo Class
+        }
+
+        EventQueue::get_instance()->push_event( EVENT_SELECTED_INSTRUMENT_CHANGED, -1 );
+        updateEditor();
+        m_pPatternEditorPanel->getVelocityEditor()->updateEditor();
+        m_pPatternEditorPanel->getPanEditor()->updateEditor();
+        m_pPatternEditorPanel->getLeadLagEditor()->updateEditor();
+        m_pPatternEditorPanel->getNoteKeyEditor()->updateEditor();
+        m_pPatternEditorPanel->getPianoRollEditor()->updateEditor();
+
+}
+
 void DrumPatternEditor::functionFillNotesUndoAction( QStringList noteList, int nSelectedInstrument, int patternNumber )
 {
 	Hydrogen * H = Hydrogen::get_instance();
Index: gui/src/UndoActions.h
===================================================================
--- gui/src/UndoActions.h	(revision 1620)
+++ gui/src/UndoActions.h	(working copy)
@@ -645,7 +645,46 @@
 	int __selectedPatternNumber;
 };
 
+class SE_pasteNotesPatternEditorAction : public QUndoCommand
+{
+public:
+        SE_pasteNotesPatternEditorAction(std::multimap< int, H2Core::Note* > nMapNew,std::multimap< int, H2Core::Note* > nMapOld, int nSelectedInstrument, int selectedPatternNumber ){
+        setText( QString( "paste notes sequense" ) );
+        __noteMap_old = nMapOld;
+        __noteMap_new = nMapNew;
+        __nSelectedInstrument = nSelectedInstrument;
+        __selectedPatternNumber = selectedPatternNumber;
+        }
 
+        ~SE_pasteNotesPatternEditorAction(){
+                //qDebug() << "delete left notes in notemap copies";
+             for(std::multimap<int, H2Core::Note*>::iterator j=__noteMap_old.begin();j!=__noteMap_old.end();j++){
+                 delete j->second;
+             }
+             for(std::multimap<int, H2Core::Note*>::iterator j=__noteMap_new.begin();j!=__noteMap_new.end();j++){
+                 delete j->second;
+             }
+        }
+
+        virtual void undo()
+        {
+                //qDebug() << "clear note sequense Undo ";
+                HydrogenApp* h2app = HydrogenApp::get_instance();
+                h2app->getPatternEditorPanel()->getDrumPatternEditor()->functionPasteNotesUndoAction( __noteMap_old, __nSelectedInstrument, __selectedPatternNumber );
+        }
+        virtual void redo()
+        {
+                //qDebug() << "clear note sequense Redo " ;
+                HydrogenApp* h2app = HydrogenApp::get_instance();
+                h2app->getPatternEditorPanel()->getDrumPatternEditor()->functionPasteNotesRedoAction( __noteMap_new, __nSelectedInstrument, __selectedPatternNumber );
+        }
+private:
+        std::multimap< int,H2Core::Note* > __noteMap_new;
+        std::multimap< int,H2Core::Note* > __noteMap_old;
+        int __nSelectedInstrument;
+        int __selectedPatternNumber;
+};
+
 class SE_fillNotesRightClickAction : public QUndoCommand
 {
 public:
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Hydrogen-devel mailing list
Hydrogen-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel

Reply via email to