+ MidiGhostRegion::Note* note;
+ guint fill = source_track_color(200);
+
+ GhostRegion::set_colors();
+
+ for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
+ if ((note = dynamic_cast<MidiGhostRegion::Note*>(*it)) != 0) {
+ note->rect->property_fill_color_rgba() = fill;
+ note->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline.get();
+ }
+ }
+}
+
+void
+MidiGhostRegion::update_range ()
+{
+ MidiStreamView* mv = midi_view();
+
+ if (!mv) {
+ return;
+ }
+
+ MidiGhostRegion::Note* note;
+ double const h = trackview.current_height() / double (mv->contents_note_range ());
+
+ for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
+ if ((note = dynamic_cast<MidiGhostRegion::Note*>(*it)) != 0) {
+ uint8_t const note_num = note->event->note()->note();
+
+ if (note_num < mv->lowest_note() || note_num > mv->highest_note()) {
+ note->rect->hide();
+ } else {
+ note->rect->show();
+ double const y = trackview.current_height() - (note_num + 1 - mv->lowest_note()) * h + 1;
+ note->rect->property_y1() = y;
+ note->rect->property_y2() = y + h;
+ }
+ }
+ }
+}
+
+void
+MidiGhostRegion::add_note(ArdourCanvas::CanvasNote* n)
+{
+ Note* note = new Note(n, group);
+ events.push_back(note);
+
+ note->rect->property_fill_color_rgba() = source_track_color(200);
+ note->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline.get();
+
+ MidiStreamView* mv = midi_view();
+
+ if (mv) {
+ const uint8_t note_num = n->note()->note();
+
+ if (note_num < mv->lowest_note() || note_num > mv->highest_note()) {
+ note->rect->hide();
+ } else {
+ const double y = mv->note_to_y(note_num);
+ note->rect->property_y1() = y;
+ note->rect->property_y2() = y + mv->note_height();
+ }
+ }
+}
+
+void
+MidiGhostRegion::clear_events()
+{
+ for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
+ delete *it;
+ }
+
+ 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;
+ }
+ }