+ (*i)->property_height() = ht;
+ (*i)->property_y() = yoff;
+ }
+}
+
+void
+AudioGhostRegion::set_colors ()
+{
+ GhostRegion::set_colors();
+ guint fill_color;
+
+ if (is_automation_ghost()) {
+ fill_color = ARDOUR_UI::config()->canvasvar_GhostTrackWaveFill.get();
+ }
+ else {
+ fill_color = source_track_color(200);
+ }
+
+ for (uint32_t n=0; n < waves.size(); ++n) {
+ waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave.get();
+ waves[n]->property_fill_color() = fill_color;
+ waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip.get();
+ waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine.get();
+ }
+}
+
+/** The general constructor; called when the destination timeaxisview doesn't have
+ * a midistreamview.
+ *
+ * @param tv TimeAxisView that this ghost region is on.
+ * @param source_tv TimeAxisView that we are the ghost for.
+ */
+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 ();
+
+ midi_view()->NoteRangeChanged.connect (sigc::mem_fun (*this, &MidiGhostRegion::update_range));
+}
+
+/**
+ * @param msv MidiStreamView that this ghost region is on.
+ * @param source_tv TimeAxisView that we are the ghost for.
+ */
+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 ();
+
+ midi_view()->NoteRangeChanged.connect (sigc::mem_fun (*this, &MidiGhostRegion::update_range));
+}
+
+MidiGhostRegion::~MidiGhostRegion()
+{
+ clear_events ();
+}
+
+MidiGhostRegion::Event::Event(ArdourCanvas::CanvasNoteEvent* e)
+ : event(e)
+{
+
+}
+
+MidiGhostRegion::Note::Note(ArdourCanvas::CanvasNote* n, ArdourCanvas::Group* g)
+ : Event(n)
+{
+ rect = new ArdourCanvas::SimpleRect(*g, n->x1(), n->y1(), n->x2(), n->y2());
+}
+
+MidiGhostRegion::Note::~Note()
+{
+ delete rect;
+}
+
+void
+MidiGhostRegion::set_samples_per_unit (double /*spu*/)
+{
+}
+
+/** @return MidiStreamView that we are providing a ghost for */
+MidiStreamView*
+MidiGhostRegion::midi_view ()
+{
+ StreamView* sv = source_trackview.view ();
+ assert (sv);
+ MidiStreamView* msv = dynamic_cast<MidiStreamView*> (sv);
+ assert (msv);
+
+ return msv;
+}
+
+void
+MidiGhostRegion::set_height ()
+{
+ GhostRegion::set_height();
+ update_range();
+}
+
+void
+MidiGhostRegion::set_colors()
+{
+ 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;
+ }
+ }