forward port of 7539 from 2.x
[ardour.git] / gtk2_ardour / midi_region_view.cc
index 3482c62a514673c2963db0be99100483ebd45f79..1ca948f86075590a28475c283449e9753ee7ab35 100644 (file)
@@ -563,7 +563,7 @@ MidiRegionView::key_press (GdkEventKey* ev)
                 bool shorter = Keyboard::modifier_state_contains (ev->state, Keyboard::PrimaryModifier);
                 bool fine = Keyboard::modifier_state_contains (ev->state, Keyboard::SecondaryModifier);
                 
-                change_note_lengths (fine, shorter, start, end);
+                change_note_lengths (fine, shorter, 0.0, start, end);
                 
                 return true;
                 
@@ -1478,7 +1478,7 @@ MidiRegionView::add_note(const boost::shared_ptr<NoteType> note, bool visible)
 
 void
 MidiRegionView::step_add_note (uint8_t channel, uint8_t number, uint8_t velocity,
-                         Evoral::MusicalTime pos, Evoral::MusicalTime len)
+                               Evoral::MusicalTime pos, Evoral::MusicalTime len)
 {
        boost::shared_ptr<NoteType> new_note (new NoteType (channel, pos, len, number, velocity));
 
@@ -1501,6 +1501,12 @@ MidiRegionView::step_add_note (uint8_t channel, uint8_t number, uint8_t velocity
         // last_step_edit_note = new_note;
 }
 
+void
+MidiRegionView::step_sustain (Evoral::MusicalTime beats)
+{
+        change_note_lengths (false, false, beats, false, true);
+}
+
 void
 MidiRegionView::add_pgm_change(PCEvent& program, const string& displaytext)
 {
@@ -1950,7 +1956,7 @@ MidiRegionView::move_selection(double dx, double dy)
 }
 
 void
-MidiRegionView::note_dropped(CanvasNoteEvent *, double dt, int8_t dnote)
+MidiRegionView::note_dropped(CanvasNoteEvent *, frameoffset_t dt, int8_t dnote)
 {
        assert (!_selection.empty());
 
@@ -1985,15 +1991,7 @@ MidiRegionView::note_dropped(CanvasNoteEvent *, double dt, int8_t dnote)
 
        for (Selection::iterator i = _selection.begin(); i != _selection.end() ; ++i) {
 
-               nframes64_t start_frames = beats_to_frames((*i)->note()->time());
-
-               if (dt >= 0) {
-                       start_frames += snap_frame_to_frame(trackview.editor().pixel_to_frame(dt));
-               } else {
-                       start_frames -= snap_frame_to_frame(trackview.editor().pixel_to_frame(-dt));
-               }
-
-               Evoral::MusicalTime new_time = frames_to_beats(start_frames);
+               Evoral::MusicalTime new_time = frames_to_beats (beats_to_frames ((*i)->note()->time()) + dt);
 
                if (new_time < 0) {
                        continue;
@@ -2254,6 +2252,12 @@ MidiRegionView::commit_resizing (ArdourCanvas::CanvasNote* primary, bool at_fron
        apply_diff();
 }
 
+void
+MidiRegionView::change_note_channel (CanvasNoteEvent* event, int8_t channel)
+{
+       diff_add_change (event, MidiModel::DiffCommand::Channel, (uint8_t) channel);
+}
+
 void
 MidiRegionView::change_note_velocity(CanvasNoteEvent* event, int8_t velocity, bool relative)
 {
@@ -2380,6 +2384,12 @@ MidiRegionView::change_note_time (CanvasNoteEvent* event, Evoral::MusicalTime de
        diff_add_change (event, MidiModel::DiffCommand::StartTime, new_time);
 }
 
+void
+MidiRegionView::change_note_length (CanvasNoteEvent* event, Evoral::MusicalTime t)
+{
+       diff_add_change (event, MidiModel::DiffCommand::Length, t);
+}
+
 void
 MidiRegionView::change_velocities (bool up, bool fine, bool allow_smush)
 {
@@ -2473,22 +2483,22 @@ MidiRegionView::transpose (bool up, bool fine, bool allow_smush)
 }
 
 void
-MidiRegionView::change_note_lengths (bool fine, bool shorter, bool start, bool end)
+MidiRegionView::change_note_lengths (bool fine, bool shorter, Evoral::MusicalTime delta, bool start, bool end)
 {
-       Evoral::MusicalTime delta;
-
-       if (fine) {
-               delta = 1.0/128.0;
-       } else {
-               /* grab the current grid distance */
-               bool success;
-               delta = trackview.editor().get_grid_type_as_beats (success, _region->position());
-               if (!success) {
-                       /* XXX cannot get grid type as beats ... should always be possible ... FIX ME */
-                       cerr << "Grid type not available as beats - TO BE FIXED\n";
-                       return;
-               }
-       }
+        if (delta == 0.0) {
+                if (fine) {
+                        delta = 1.0/128.0;
+                } else {
+                        /* grab the current grid distance */
+                        bool success;
+                        delta = trackview.editor().get_grid_type_as_beats (success, _region->position());
+                        if (!success) {
+                                /* XXX cannot get grid type as beats ... should always be possible ... FIX ME */
+                                cerr << "Grid type not available as beats - TO BE FIXED\n";
+                                return;
+                        }
+                }
+        }
 
        if (shorter) {
                delta = -delta;