@@ -1851,7 +1851,7 @@ void MainPanel::mouseDrag(const juce::MouseEvent &event) {
18511851 for (int i = 0 ; i < notes.size (); ++i) {
18521852 if (notes[i].id == clickStartMoveNoteId) {
18531853 dragManuallyPlayedKeys.erase (initialTotalCentsForDrag[idx] +
1854- prevDcents);
1854+ prevDcents);
18551855 dragManuallyPlayedKeys.insert (
18561856 {notes[i].cents + notes[i].octave * 1200 , notes[i].velocity });
18571857 editor.setManuallyPlayedKeys (dragManuallyPlayedKeys, " drag" );
@@ -2633,42 +2633,51 @@ void MainPanel::correctRatioMarksBasedOnSelNotes(float dtime) {
26332633bool MainPanel::keyPressed (const juce::KeyPress &key, juce::Component *originatingComponent) {
26342634 juce::ignoreUnused (originatingComponent);
26352635
2636+ // NOTE: DON'T ALLOW OPERATIONS THAT CHANGE SELECTED NOTES (DELETE/SELECT/UNSELECT)
2637+ // IF THERE IS DRAGGING THAT RELIES ON SELECTED NOTES IS GOING ON
2638+
26362639 // select all notes
26372640 if (key == juce::KeyPress (' a' , juce::ModifierKeys::commandModifier, 0 )) {
2638- selectAllNotes ();
2639- if (isShowingVelocityPanel) {
2640- showOrUpdateVelocityPanel ();
2641+ if (!isInDragNotesOperation ()) {
2642+ selectAllNotes ();
2643+ if (isShowingVelocityPanel) {
2644+ showOrUpdateVelocityPanel ();
2645+ }
26412646 }
26422647 return true ;
26432648 }
26442649
26452650 // unselect all notes
26462651 if (key == juce::KeyPress::escapeKey) {
2647- isDrawingRatioMark = false ;
2648- unselectAllNotes ();
2649- repaint ();
2650- hideVelocityPanel ();
2652+ if (!isInDragNotesOperation ()) {
2653+ isDrawingRatioMark = false ;
2654+ unselectAllNotes ();
2655+ repaint ();
2656+ hideVelocityPanel ();
2657+ }
26512658 return true ;
26522659 }
26532660
26542661 // delete selected notes
26552662 if (key == juce::KeyPress::deleteKey) {
2656- if (!thereAreSelectedNotes ()) {
2657- return true ;
2658- }
2663+ if (!isInDragNotesOperation ()) {
2664+ if (!thereAreSelectedNotes ()) {
2665+ return true ;
2666+ }
26592667
2660- int numNotes = static_cast <int >(notes.size ());
2661- for (int i = 0 ; i < numNotes; ++i) {
2662- if (notes[i].isSelected ) {
2663- deleteNote (i);
2664- i--;
2665- numNotes--;
2668+ int numNotes = static_cast <int >(notes.size ());
2669+ for (int i = 0 ; i < numNotes; ++i) {
2670+ if (notes[i].isSelected ) {
2671+ deleteNote (i);
2672+ i--;
2673+ numNotes--;
2674+ }
26662675 }
2676+ saveState ();
2677+ editor.updateNotes (notes);
2678+ hideVelocityPanel ();
2679+ repaint ();
26672680 }
2668- saveState ();
2669- editor.updateNotes (notes);
2670- hideVelocityPanel ();
2671- repaint ();
26722681 return true ;
26732682 }
26742683
@@ -2686,54 +2695,60 @@ bool MainPanel::keyPressed(const juce::KeyPress &key, juce::Component *originati
26862695
26872696 // paste copied notes
26882697 if (key == juce::KeyPress (' v' , juce::ModifierKeys::commandModifier, 0 )) {
2689- unselectAllNotes ();
2690- hideVelocityPanel ();
2691- bool needGenNewKeys = false ;
2692- bool needUpdateKeys = false ;
2693- for (int i = 0 ; i < copiedNotes.size (); ++i) {
2694- copiedNotes[i].id = Note::generateId (); // NEW Id FOR COPIED NOTES!
2695- notes.push_back (copiedNotes[i]);
2696- int cents = copiedNotes[i].cents ;
2697- if (params.zones .isNoteInActiveZone (copiedNotes[i])) {
2698- auto [_, inserted] = keys.insert (cents);
2699- if (inserted || keyIsGenNew[cents]) {
2700- keyIsGenNew[cents] = false ;
2701- if (params.generateNewKeys ) {
2702- needGenNewKeys = true ;
2698+ if (!isInDragNotesOperation ()) {
2699+ unselectAllNotes ();
2700+ hideVelocityPanel ();
2701+ bool needGenNewKeys = false ;
2702+ bool needUpdateKeys = false ;
2703+ for (int i = 0 ; i < copiedNotes.size (); ++i) {
2704+ copiedNotes[i].id = Note::generateId (); // NEW Id FOR COPIED NOTES!
2705+ notes.push_back (copiedNotes[i]);
2706+ int cents = copiedNotes[i].cents ;
2707+ if (params.zones .isNoteInActiveZone (copiedNotes[i])) {
2708+ auto [_, inserted] = keys.insert (cents);
2709+ if (inserted || keyIsGenNew[cents]) {
2710+ keyIsGenNew[cents] = false ;
2711+ if (params.generateNewKeys ) {
2712+ needGenNewKeys = true ;
2713+ }
2714+ needUpdateKeys = true ;
27032715 }
2704- needUpdateKeys = true ;
27052716 }
2717+ keysFromAllNotes.insert (cents);
27062718 }
2707- keysFromAllNotes.insert (cents);
2708- }
2709- if (needGenNewKeys) {
2710- generateNewKeys ();
2711- }
2712- if (needUpdateKeys) {
2713- editor.updateKeys (keys);
2719+ if (needGenNewKeys) {
2720+ generateNewKeys ();
2721+ }
2722+ if (needUpdateKeys) {
2723+ editor.updateKeys (keys);
2724+ }
2725+ editor.showMessage (juce::String (copiedNotes.size ()) + " note" +
2726+ (copiedNotes.size () == 1 ? " " : " s" ) + " pasted!" );
2727+ saveState ();
2728+ editor.updateNotes (notes);
2729+ repaint ();
27142730 }
2715- editor.showMessage (juce::String (copiedNotes.size ()) + " note" +
2716- (copiedNotes.size () == 1 ? " " : " s" ) + " pasted!" );
2717- saveState ();
2718- editor.updateNotes (notes);
2719- repaint ();
27202731 return true ;
27212732 }
27222733
27232734 // Undo
27242735 if (key == juce::KeyPress (' z' , juce::ModifierKeys::commandModifier, 0 )) {
2725- if (params.stateHistory .canUndo ()) {
2726- params.stateHistory .undo ();
2727- restoreState ();
2736+ if (!isInDragNotesOperation ()) {
2737+ if (params.stateHistory .canUndo ()) {
2738+ params.stateHistory .undo ();
2739+ restoreState ();
2740+ }
27282741 }
27292742 return true ;
27302743 }
27312744
27322745 // Redo
27332746 if (key == juce::KeyPress (' y' , juce::ModifierKeys::commandModifier, 0 )) {
2734- if (params.stateHistory .canRedo ()) {
2735- params.stateHistory .redo ();
2736- restoreState ();
2747+ if (!isInDragNotesOperation ()) {
2748+ if (params.stateHistory .canRedo ()) {
2749+ params.stateHistory .redo ();
2750+ restoreState ();
2751+ }
27372752 }
27382753 return true ;
27392754 }
0 commit comments