Skip to content

Commit

Permalink
Add copy/paste
Browse files Browse the repository at this point in the history
  • Loading branch information
SwadicalRag committed Jan 1, 2021
1 parent 672f54c commit daadaf2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/controllers/muonproject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MuonProjectController extends GetxController {
// other
final selectedNotes = Map<MuonNoteController,bool>().obs;
final playheadTime = 0.0.obs;
List<MuonNote> copiedNotes = [];

// subdivision manager
final currentSubdivision = 1.obs;
Expand Down
40 changes: 40 additions & 0 deletions lib/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,46 @@ class _MuonEditorState extends State<MuonEditor> {
}
}

// 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(() {});
}
Expand Down

0 comments on commit daadaf2

Please sign in to comment.