X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fghostregion.cc;h=cb4a0d95d3da0a9d09d971e6d5b00481746c9c81;hb=e12432cc632125821d6ed192d129ef385fb25002;hp=4c2f17d29d0c0c659da9b86d741b6c59ee887d3f;hpb=60f48d24f40e6d73b1ccf5dc2885d45570626212;p=ardour.git diff --git a/gtk2_ardour/ghostregion.cc b/gtk2_ardour/ghostregion.cc index 4c2f17d29d..cb4a0d95d3 100644 --- a/gtk2_ardour/ghostregion.cc +++ b/gtk2_ardour/ghostregion.cc @@ -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,17 +203,7 @@ MidiGhostRegion::Note::Note(ArdourCanvas::CanvasNote* n, ArdourCanvas::Group* g) MidiGhostRegion::Note::~Note() { - //delete rect; -} - -MidiGhostRegion::Hit::Hit(ArdourCanvas::CanvasHit* h, ArdourCanvas::Group*) - : Event(h) -{ - cerr << "Hit ghost item does not work yet" << endl; -} - -MidiGhostRegion::Hit::~Hit() -{ + delete rect; } void @@ -306,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() { @@ -322,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 (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; +}