use "mute" not cut in monitor section
[ardour.git] / gtk2_ardour / midi_region_view.cc
index 6fe9768febd2d1531cc541c60768579cf84e675e..0f30c357330873cb259b25320f0d38dda70068cc 100644 (file)
@@ -294,12 +294,18 @@ MidiRegionView::init (Gdk::Color const & basic_color, bool wfd)
        SelectionCleared.connect (_selection_cleared_connection, invalidator (*this), ui_bind (&MidiRegionView::selection_cleared, this, _1), gui_context ());
 }
 
+const boost::shared_ptr<ARDOUR::MidiRegion>
+MidiRegionView::midi_region() const
+{
+       return boost::dynamic_pointer_cast<ARDOUR::MidiRegion>(_region);
+}
+
 void
 MidiRegionView::connect_to_diskstream ()
 {
        midi_view()->midi_track()->DataRecorded.connect(
                *this, invalidator(*this),
-               ui_bind(&MidiRegionView::data_recorded, this, _1, _2),
+               ui_bind(&MidiRegionView::data_recorded, this, _1),
                gui_context());
 }
 
@@ -388,7 +394,7 @@ MidiRegionView::enter_notify (GdkEventCrossing* ev)
 }
 
 bool
-MidiRegionView::leave_notify (GdkEventCrossing* ev)
+MidiRegionView::leave_notify (GdkEventCrossing*)
 {
        _mouse_mode_connection.disconnect ();
 
@@ -719,6 +725,13 @@ MidiRegionView::scroll (GdkEventScroll* ev)
                return false;
        }
 
+       if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+               /* XXX: bit of a hack; allow PrimaryModifier scroll through so that
+                  it still works for zoom.
+               */
+               return false;
+       }
+
        trackview.editor().verbose_cursor()->hide ();
 
        bool fine = !Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier);
@@ -843,7 +856,7 @@ void
 MidiRegionView::channel_edit ()
 {
        bool first = true;
-       uint8_t current_channel;
+       uint8_t current_channel = 0;
 
        if (_selection.empty()) {
                return;
@@ -2020,6 +2033,31 @@ MidiRegionView::select_all_notes ()
        }
 }
 
+void
+MidiRegionView::select_range (framepos_t start, framepos_t end)
+{
+       clear_selection ();
+
+       for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
+               framepos_t t = source_beats_to_absolute_frames((*i)->note()->time());
+               if (t >= start && t <= end) {
+                       add_to_selection (*i);
+               }
+       }
+}
+
+void
+MidiRegionView::invert_selection ()
+{
+       for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
+               if ((*i)->selected()) {
+                       remove_from_selection(*i);
+               } else {
+                       add_to_selection (*i);
+               }
+       }
+}
+
 void
 MidiRegionView::select_matching_notes (uint8_t notenum, uint16_t channel_mask, bool add, bool extend)
 {
@@ -2359,6 +2397,9 @@ MidiRegionView::note_dropped(CanvasNoteEvent *, frameoffset_t dt, int8_t dnote)
        }
 }
 
+/** @param x Pixel relative to the region position.
+ *  @return Snapped frame relative to the region position.
+ */
 framepos_t
 MidiRegionView::snap_pixel_to_frame(double x)
 {
@@ -2366,6 +2407,9 @@ MidiRegionView::snap_pixel_to_frame(double x)
        return snap_frame_to_frame (editor.pixel_to_frame (x));
 }
 
+/** @param x Pixel relative to the region position.
+ *  @return Snapped pixel relative to the region position.
+ */
 double
 MidiRegionView::snap_to_pixel(double x)
 {
@@ -2505,9 +2549,6 @@ MidiRegionView::update_resizing (ArdourCanvas::CanvasNoteEvent* primary, bool at
                        double beats;
 
                        beats = snap_pixel_to_frame (current_x);
-                       /* XXX not sure this is correct - snap_pixel_to_frame()
-                          returns an absolute frame.
-                       */
                        beats = region_frames_to_region_beats (beats);
 
                        double len;
@@ -2570,13 +2611,10 @@ MidiRegionView::commit_resizing (ArdourCanvas::CanvasNoteEvent* primary, bool at
                        }
                }
 
-               /* Convert that to a frame within the region */
+               /* Convert that to a frame within the source */
                current_x = snap_pixel_to_frame (current_x) + _region->start ();
 
                /* and then to beats */
-               /* XXX not sure this is correct - snap_pixel_to_frame()
-                  returns an absolute frame.
-               */
                current_x = region_frames_to_region_beats (current_x);
 
                if (at_front && current_x < canvas_note->note()->end_time()) {
@@ -3487,11 +3525,10 @@ MidiRegionView::set_step_edit_cursor_width (Evoral::MusicalTime beats)
 }
 
 /** Called when a diskstream on our track has received some data.  Update the view, if applicable.
- *  @param buf Data that has been recorded.
- *  @param w Source that this data will end up in.
+ *  @param w Source that the data will end up in.
  */
 void
-MidiRegionView::data_recorded (boost::shared_ptr<MidiBuffer> buf, boost::weak_ptr<MidiSource> w)
+MidiRegionView::data_recorded (boost::weak_ptr<MidiSource> w)
 {
        if (!_active_notes) {
                /* we aren't actively being recorded to */
@@ -3505,6 +3542,9 @@ MidiRegionView::data_recorded (boost::shared_ptr<MidiBuffer> buf, boost::weak_pt
        }
 
        MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (&trackview);
+
+       boost::shared_ptr<MidiBuffer> buf = mtv->midi_track()->get_gui_feed_buffer ();
+
        BeatsFramesConverter converter (trackview.session()->tempo_map(), mtv->midi_track()->get_capture_start_frame (0));
 
        framepos_t back = max_framepos;