Use correct default value for MIDI faders, and put the
[ardour.git] / gtk2_ardour / ghostregion.cc
index 0145aafc101faae3f7a716bb1f0c77e595cc95d3..cb4a0d95d3da0a9d09d971e6d5b00481746c9c81 100644 (file)
@@ -20,7 +20,6 @@
 #include "evoral/Note.hpp"
 #include "ardour_ui.h"
 #include "automation_time_axis.h"
-#include "canvas-hit.h"
 #include "canvas-note.h"
 #include "ghostregion.h"
 #include "midi_streamview.h"
@@ -105,7 +104,7 @@ GhostRegion::is_automation_ghost()
 AudioGhostRegion::AudioGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
        : GhostRegion(tv.ghost_group(), tv, source_tv, initial_unit_pos)
 {
-       
+
 }
 
 void
@@ -163,6 +162,7 @@ AudioGhostRegion::set_colors ()
  */
 MidiGhostRegion::MidiGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
        : GhostRegion(tv.ghost_group(), tv, source_tv, initial_unit_pos)
+       , _optimization_iterator (events.end ())
 {
        base_rect->lower_to_bottom();
        update_range ();
@@ -176,6 +176,7 @@ MidiGhostRegion::MidiGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, doub
  */
 MidiGhostRegion::MidiGhostRegion(MidiStreamView& msv, TimeAxisView& source_tv, double initial_unit_pos)
        : GhostRegion(msv.midi_underlay_group, msv.trackview(), source_tv, initial_unit_pos)
+       , _optimization_iterator (events.end ())
 {
        base_rect->lower_to_bottom();
        update_range ();
@@ -185,12 +186,13 @@ MidiGhostRegion::MidiGhostRegion(MidiStreamView& msv, TimeAxisView& source_tv, d
 
 MidiGhostRegion::~MidiGhostRegion()
 {
-       //clear_events();
+       clear_events ();
 }
 
 MidiGhostRegion::Event::Event(ArdourCanvas::CanvasNoteEvent* e)
        : event(e)
 {
+
 }
 
 MidiGhostRegion::Note::Note(ArdourCanvas::CanvasNote* n, ArdourCanvas::Group* g)
@@ -201,29 +203,7 @@ MidiGhostRegion::Note::Note(ArdourCanvas::CanvasNote* n, ArdourCanvas::Group* g)
 
 MidiGhostRegion::Note::~Note()
 {
-       //delete rect;
-}
-
-void
-MidiGhostRegion::Note::x_changed()
-{
-       rect->property_x1() = event->x1();
-       rect->property_x2() = event->x2();
-}
-
-MidiGhostRegion::Hit::Hit(ArdourCanvas::CanvasHit* h, ArdourCanvas::Group*)
-       : Event(h)
-{
-       cerr << "Hit ghost item does not work yet" << endl;
-}
-
-MidiGhostRegion::Hit::~Hit()
-{
-}
-
-void
-MidiGhostRegion::Hit::x_changed()
-{
+       delete rect;
 }
 
 void
@@ -318,12 +298,6 @@ MidiGhostRegion::add_note(ArdourCanvas::CanvasNote* n)
        }
 }
 
-void
-MidiGhostRegion::add_hit(ArdourCanvas::CanvasHit* /*h*/)
-{
-       //events.push_back(new Hit(h, group));
-}
-
 void
 MidiGhostRegion::clear_events()
 {
@@ -334,3 +308,51 @@ MidiGhostRegion::clear_events()
        events.clear();
 }
 
+/** Update the x positions of our representation of a parent's note.
+ *  @param parent The CanvasNote from the parent MidiRegionView.
+ */
+void
+MidiGhostRegion::update_note (ArdourCanvas::CanvasNote* parent)
+{
+       Event* ev = find_event (parent);
+       if (!ev) {
+               return;
+       }
+
+       Note* note = dynamic_cast<Note *> (ev);
+       if (note) {
+               double const x1 = parent->property_x1 ();
+               double const x2 = parent->property_x2 ();
+               note->rect->property_x1 () = x1;
+               note->rect->property_x2 () = x2;
+       }
+}
+
+/** Given a note in our parent region (ie the actual MidiRegionView), find our
+ *  representation of it.
+ *  @return Our Event, or 0 if not found.
+ */
+
+MidiGhostRegion::Event *
+MidiGhostRegion::find_event (ArdourCanvas::CanvasNote* parent)
+{
+       /* we are using _optimization_iterator to speed up the common case where a caller
+          is going through our notes in order.
+       */
+
+       if (_optimization_iterator != events.end()) {
+               ++_optimization_iterator;
+       }
+
+       if (_optimization_iterator != events.end() && (*_optimization_iterator)->event == parent) {
+               return *_optimization_iterator;
+       }
+
+       for (_optimization_iterator = events.begin(); _optimization_iterator != events.end(); ++_optimization_iterator) {
+               if ((*_optimization_iterator)->event == parent) {
+                       return *_optimization_iterator;
+               }
+       }
+
+       return 0;
+}