add step editing sustain support
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 13 Aug 2010 14:11:01 +0000 (14:11 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 13 Aug 2010 14:11:01 +0000 (14:11 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7615 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/midi_region_view.cc
gtk2_ardour/midi_region_view.h
gtk2_ardour/midi_time_axis.cc
gtk2_ardour/midi_time_axis.h
gtk2_ardour/step_entry.cc

index 3482c62a514673c2963db0be99100483ebd45f79..b761941df19ebd3db696bd1b905296c6351fff76 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)
 {
@@ -2473,22 +2479,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;
index 268bcdc0dd8a772d3e2cbf38b6a51e1769d295f6..ccab1d06bc1429a856cd9f2deac3d56eb5a68e51 100644 (file)
@@ -94,8 +94,8 @@ class MidiRegionView : public RegionView
                { return midi_view()->midi_view(); }
 
        void step_add_note (uint8_t channel, uint8_t number, uint8_t velocity,
-                      Evoral::MusicalTime pos, Evoral::MusicalTime len);
-
+                            Evoral::MusicalTime pos, Evoral::MusicalTime len);
+        void step_sustain (Evoral::MusicalTime beats);
        void set_height (double);
        void apply_note_range(uint8_t lowest, uint8_t highest, bool force=false);
 
@@ -276,7 +276,7 @@ class MidiRegionView : public RegionView
 
        void goto_previous_note ();
        void goto_next_note ();
-       void change_note_lengths (bool, bool, bool start, bool end);
+       void change_note_lengths (bool, bool, Evoral::MusicalTime beats, bool start, bool end);
        void change_velocities (bool up, bool fine, bool allow_smush);
        void transpose (bool up, bool fine, bool allow_smush);
        void nudge_notes (bool forward);
index e62bd6223c46bc744770072f0f88669dffe9600a..464ed630f5453741153e19ceaed47fbe799b1b8c 100644 (file)
@@ -898,8 +898,12 @@ MidiTimeAxisView::start_step_editing ()
         _step_edit_triplet_countdown = 0;
         _step_edit_within_chord = 0;
         _step_edit_chord_duration = 0.0;
+        
+        boost::shared_ptr<Region> r = playlist()->top_region_at (step_edit_insert_position);
 
-       step_edit_region = playlist()->top_region_at (step_edit_insert_position);
+        if (r) {
+                step_edit_region = boost::dynamic_pointer_cast<MidiRegion>(r);
+        }
 
        if (step_edit_region) {
                RegionView* rv = view()->find_view (step_edit_region);
@@ -962,6 +966,8 @@ MidiTimeAxisView::stop_step_editing ()
         if (step_edit_region_view) {
                 step_edit_region_view->hide_step_edit_cursor();
         }
+
+        step_edit_region.reset ();
 }
 
 void
@@ -1006,6 +1012,14 @@ MidiTimeAxisView::step_add_program_change (uint8_t channel, uint8_t program)
         return 0;
 }
 
+void
+MidiTimeAxisView::step_edit_sustain (Evoral::MusicalTime beats)
+{
+        if (step_edit_region_view) {
+                step_edit_region_view->step_sustain (beats);
+        }
+}
+
 int
 MidiTimeAxisView::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evoral::MusicalTime beat_duration)
 {
@@ -1144,7 +1158,7 @@ MidiTimeAxisView::step_edit_bar_sync ()
         step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos);
 }
 
-boost::shared_ptr<Region>
+boost::shared_ptr<MidiRegion>
 MidiTimeAxisView::add_region (framepos_t pos)
 {
        Editor* real_editor = dynamic_cast<Editor*> (&_editor);
@@ -1172,7 +1186,7 @@ MidiTimeAxisView::add_region (framepos_t pos)
 
        real_editor->commit_reversible_command();
 
-       return region;
+       return boost::dynamic_pointer_cast<MidiRegion>(region);
 }
 
 void
index cbca25bd0e50580a0cc1d5e31c6611663fc337df..8012db5cc195faa7e4f27f4873db5cccfcc2f55e 100644 (file)
@@ -68,7 +68,7 @@ class MidiTimeAxisView : public RouteTimeAxisView
        void set_height (uint32_t);
        void hide ();
 
-       boost::shared_ptr<ARDOUR::Region> add_region (ARDOUR::framepos_t pos);
+       boost::shared_ptr<ARDOUR::MidiRegion> add_region (ARDOUR::framepos_t pos);
 
        void show_all_automation ();
        void show_existing_automation ();
@@ -95,6 +95,7 @@ class MidiTimeAxisView : public RouteTimeAxisView
         int  step_add_program_change (uint8_t channel, uint8_t program);
         int  step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, 
                             Evoral::MusicalTime beat_duration);
+        void step_edit_sustain (Evoral::MusicalTime beats);
         bool step_edit_within_triplet () const;
         void step_edit_toggle_triplet ();
         bool step_edit_within_chord () const;
@@ -147,7 +148,7 @@ class MidiTimeAxisView : public RouteTimeAxisView
 
        nframes64_t step_edit_insert_position;
        Evoral::MusicalTime step_edit_beat_pos;
-       boost::shared_ptr<ARDOUR::Region> step_edit_region;
+       boost::shared_ptr<ARDOUR::MidiRegion> step_edit_region;
        MidiRegionView* step_edit_region_view;
         uint8_t _step_edit_triplet_countdown;
         bool    _step_edit_within_chord;
index 74815653634d47ecd2ac202883cd952e9a825ce4..011fadc3c49025f16e49aa611a0b693f31a47c16 100644 (file)
@@ -1030,4 +1030,5 @@ StepEntry::octave_n (int n)
 void
 StepEntry::do_sustain ()
 {
+        _mtv->step_edit_sustain (note_length());
 }