From daadaf2d30a731bee6fbca1a23b2f75d83652162 Mon Sep 17 00:00:00 2001 From: swadical Date: Fri, 1 Jan 2021 23:27:50 +1030 Subject: [PATCH] Add copy/paste --- lib/controllers/muonproject.dart | 1 + lib/editor.dart | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/controllers/muonproject.dart b/lib/controllers/muonproject.dart index 01a9b46..d6dfd01 100644 --- a/lib/controllers/muonproject.dart +++ b/lib/controllers/muonproject.dart @@ -23,6 +23,7 @@ class MuonProjectController extends GetxController { // other final selectedNotes = Map().obs; final playheadTime = 0.0.obs; + List copiedNotes = []; // subdivision manager final currentSubdivision = 1.obs; diff --git a/lib/editor.dart b/lib/editor.dart index 8e38400..d5ede03 100644 --- a/lib/editor.dart +++ b/lib/editor.dart @@ -434,6 +434,46 @@ class _MuonEditorState extends State { } } + // dumb hack to force repaint + pianoRoll.state.setState(() {}); + } + else if(keyEvent.isKeyPressed(LogicalKeyboardKey.keyC) || keyEvent.isKeyPressed(LogicalKeyboardKey.keyX)) { + // copy / cut + + bool cut = keyEvent.isKeyPressed(LogicalKeyboardKey.keyX); + currentProject.copiedNotes.clear(); + + int earliestTime = 2147483647; // assuming int32, I cannot be bothered verifying this + for(final selectedNote in currentProject.selectedNotes.keys) { + if(currentProject.selectedNotes[selectedNote]) { + currentProject.copiedNotes.add(selectedNote.toSerializable()); + earliestTime = min(earliestTime,selectedNote.startAtTime.value); + + if(cut) { + selectedNote.voice.notes.remove(selectedNote); + } + } + } + + for(final note in currentProject.copiedNotes) { + note.startAtTime -= earliestTime; + } + + // dumb hack to force repaint + pianoRoll.state.setState(() {}); + } + else if(keyEvent.isKeyPressed(LogicalKeyboardKey.keyV)) { + // paste + + final currentVoice = currentProject.voices[0]; + if(currentVoice != null) { + for(final note in currentProject.copiedNotes) { + final cNote = MuonNoteController.fromSerializable(note); + cNote.startAtTime.value = cNote.startAtTime.value + (currentProject.playheadTime.value * currentProject.timeUnitsPerBeat.value).floor(); + currentVoice.addNote(cNote); + } + } + // dumb hack to force repaint pianoRoll.state.setState(() {}); }