From faf4e1d8e863477a13b6c3e3c04d76fbd8011c61 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 22 Feb 2008 01:45:29 +0000 Subject: Clean up weird formatting from underlays patch. Fix several memory (valgrind) errors in a vain attempt to fix crash on session close. git-svn-id: svn://localhost/ardour2/branches/3.0@3105 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ghostregion.cc | 98 ++++++++++++++++++++++++----------------- gtk2_ardour/ghostregion.h | 1 + gtk2_ardour/midi_region_view.cc | 33 +++++++------- gtk2_ardour/midi_time_axis.cc | 14 +++--- gtk2_ardour/region_view.cc | 3 +- gtk2_ardour/region_view.h | 1 - gtk2_ardour/streamview.cc | 16 +++++-- gtk2_ardour/streamview.h | 1 + libs/ardour/region_factory.cc | 2 - libs/ardour/session.cc | 4 +- 10 files changed, 101 insertions(+), 72 deletions(-) diff --git a/gtk2_ardour/ghostregion.cc b/gtk2_ardour/ghostregion.cc index e57e3b6375..6384baffa0 100644 --- a/gtk2_ardour/ghostregion.cc +++ b/gtk2_ardour/ghostregion.cc @@ -46,7 +46,7 @@ GhostRegion::GhostRegion (ArdourCanvas::Group* parent, TimeAxisView& tv, TimeAxi base_rect->property_y2() = (double) trackview.height; base_rect->property_outline_what() = (guint32) 0; - if(!is_automation_ghost()) { + if (!is_automation_ghost()) { base_rect->hide(); } @@ -59,15 +59,15 @@ GhostRegion::GhostRegion (ArdourCanvas::Group* parent, TimeAxisView& tv, TimeAxi GhostRegion::~GhostRegion () { - GoingAway (this); + /*GoingAway (this); delete base_rect; - delete group; + delete group;*/ } void GhostRegion::set_duration (double units) { - base_rect->property_x2() = units; + base_rect->property_x2() = units; } void @@ -79,7 +79,7 @@ GhostRegion::set_height () void GhostRegion::set_colors () { - if(is_automation_ghost()) { + if (is_automation_ghost()) { base_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackBase.get(); base_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackBase.get(); } @@ -136,7 +136,7 @@ AudioGhostRegion::set_colors () GhostRegion::set_colors(); guint fill_color; - if(is_automation_ghost()) { + if (is_automation_ghost()) { fill_color = ARDOUR_UI::config()->canvasvar_GhostTrackWaveFill.get(); } else { @@ -157,47 +157,59 @@ AudioGhostRegion::set_colors () * no range controller in these tracks. maybe show the whole range. */ MidiGhostRegion::MidiGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos) - : GhostRegion(tv.ghost_group, tv, source_tv, initial_unit_pos) { + : GhostRegion(tv.ghost_group, tv, source_tv, initial_unit_pos) +{ base_rect->lower_to_bottom(); } MidiGhostRegion::MidiGhostRegion(MidiStreamView& msv, TimeAxisView& source_tv, double initial_unit_pos) - : GhostRegion(msv.midi_underlay_group, msv.trackview(), source_tv, initial_unit_pos) { - + : GhostRegion(msv.midi_underlay_group, msv.trackview(), source_tv, initial_unit_pos) +{ base_rect->lower_to_bottom(); } +MidiGhostRegion::~MidiGhostRegion() +{ + //clear_events(); +} + MidiGhostRegion::Event::Event(ArdourCanvas::CanvasMidiEvent* e) - : event(e) { + : event(e) +{ } MidiGhostRegion::Note::Note(ArdourCanvas::CanvasNote* n, ArdourCanvas::Group* g) - : Event(n) { - + : Event(n) +{ rect = new ArdourCanvas::SimpleRect(*g, n->x1(), n->y1(), n->x2(), n->y2()); } -MidiGhostRegion::Note::~Note() { - delete rect; +MidiGhostRegion::Note::~Note() +{ + //delete rect; } void -MidiGhostRegion::Note::x_changed() { +MidiGhostRegion::Note::x_changed() +{ rect->property_x1() = event->x1(); rect->property_x2() = event->x2(); } MidiGhostRegion::Hit::Hit(ArdourCanvas::CanvasHit* h, ArdourCanvas::Group*) - : Event(h) { + : Event(h) +{ cerr << "Hit ghost item does not work yet" << endl; } -MidiGhostRegion::Hit::~Hit() { +MidiGhostRegion::Hit::~Hit() +{ } void -MidiGhostRegion::Hit::x_changed() { +MidiGhostRegion::Hit::x_changed() +{ } void @@ -206,10 +218,11 @@ MidiGhostRegion::set_samples_per_unit (double spu) } MidiStreamView* -MidiGhostRegion::midi_view() { +MidiGhostRegion::midi_view() +{ MidiTimeAxisView* mtv; - if((mtv = dynamic_cast(&trackview)) != 0) { + if ((mtv = dynamic_cast(&trackview)) != 0) { return mtv->midi_view(); } else { @@ -218,20 +231,22 @@ MidiGhostRegion::midi_view() { } void -MidiGhostRegion::set_height() { +MidiGhostRegion::set_height() +{ GhostRegion::set_height(); update_range(); } void -MidiGhostRegion::set_colors() { +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(*it)) != 0) { + for (EventList::iterator it = events.begin(); it != events.end(); ++it) { + if ((note = dynamic_cast(*it)) != 0) { note->rect->property_fill_color_rgba() = fill; note->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline.get(); } @@ -239,10 +254,11 @@ MidiGhostRegion::set_colors() { } void -MidiGhostRegion::update_range() { +MidiGhostRegion::update_range() +{ MidiStreamView* mv = midi_view(); - if(!mv) { + if (!mv) { return; } @@ -250,11 +266,11 @@ MidiGhostRegion::update_range() { uint8_t note_num; double y; - for(EventList::iterator it = events.begin(); it != events.end(); ++it) { - if((note = dynamic_cast(*it)) != 0) { + for (EventList::iterator it = events.begin(); it != events.end(); ++it) { + if ((note = dynamic_cast(*it)) != 0) { note_num = note->event->note()->note(); - if(note_num < mv->lowest_note() || note_num > mv->highest_note()) { + if (note_num < mv->lowest_note() || note_num > mv->highest_note()) { note->rect->hide(); } else { @@ -268,7 +284,8 @@ MidiGhostRegion::update_range() { } void -MidiGhostRegion::add_note(ArdourCanvas::CanvasNote* n) { +MidiGhostRegion::add_note(ArdourCanvas::CanvasNote* n) +{ Note* note = new Note(n, group); events.push_back(note); @@ -277,15 +294,13 @@ MidiGhostRegion::add_note(ArdourCanvas::CanvasNote* n) { MidiStreamView* mv = midi_view(); - if(mv) { - uint8_t note_num = n->note()->note(); - double y; + if (mv) { + const uint8_t note_num = n->note()->note(); - if(note_num < mv->lowest_note() || note_num > mv->highest_note()) { + if (note_num < mv->lowest_note() || note_num > mv->highest_note()) { note->rect->hide(); - } - else { - y = mv->note_to_y(note_num); + } else { + const double y = mv->note_to_y(note_num); note->rect->property_y1() = y; note->rect->property_y2() = y + mv->note_height(); } @@ -293,15 +308,18 @@ MidiGhostRegion::add_note(ArdourCanvas::CanvasNote* n) { } void -MidiGhostRegion::add_hit(ArdourCanvas::CanvasHit* h) { +MidiGhostRegion::add_hit(ArdourCanvas::CanvasHit* h) +{ //events.push_back(new Hit(h, group)); } void -MidiGhostRegion::clear_events() { - for(EventList::iterator it = events.begin(); it != events.end(); ++it) { +MidiGhostRegion::clear_events() +{ + for (EventList::iterator it = events.begin(); it != events.end(); ++it) { delete *it; } events.clear(); } + diff --git a/gtk2_ardour/ghostregion.h b/gtk2_ardour/ghostregion.h index ba02762d0b..72658f2d53 100644 --- a/gtk2_ardour/ghostregion.h +++ b/gtk2_ardour/ghostregion.h @@ -103,6 +103,7 @@ public: MidiGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos); MidiGhostRegion(MidiStreamView& msv, TimeAxisView& source_tv, double initial_unit_pos); + ~MidiGhostRegion(); MidiStreamView* midi_view(); diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 83bfbffe54..3edd527ad0 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -381,17 +381,16 @@ MidiRegionView::create_note_at(double x, double y, double dur) void MidiRegionView::clear_events() { - for (std::vector::iterator i = _events.begin(); i != _events.end(); ++i) - delete *i; - MidiGhostRegion* gr; - - for(vector::iterator g = ghosts.begin(); g != ghosts.end(); ++g) { - if((gr = dynamic_cast(*g)) != 0) { + for (vector::iterator g = ghosts.begin(); g != ghosts.end(); ++g) { + if ((gr = dynamic_cast(*g)) != 0) { gr->clear_events(); } } + for (std::vector::iterator i = _events.begin(); i != _events.end(); ++i) + delete *i; + _events.clear(); } @@ -465,12 +464,16 @@ MidiRegionView::redisplay_model() MidiRegionView::~MidiRegionView () { in_destructor = true; + + RegionViewGoingAway (this); /* EMIT_SIGNAL */ + if (_active_notes) end_write(); + _selection.clear(); clear_events(); - - RegionViewGoingAway (this); /* EMIT_SIGNAL */ + delete _note_group; + delete _delta_command; } @@ -517,9 +520,9 @@ MidiRegionView::set_y_position_and_height (double y, double h) for (std::vector::const_iterator i = _events.begin(); i != _events.end(); ++i) { CanvasNote* note = dynamic_cast(*i); if (note && note->note()) { - if(note->note()->note() < midi_stream_view()->lowest_note() || + if (note->note()->note() < midi_stream_view()->lowest_note() || note->note()->note() > midi_stream_view()->highest_note()) { - if(canvas_item_visible(note)) { + if (canvas_item_visible(note)) { note->hide(); } } @@ -527,7 +530,7 @@ MidiRegionView::set_y_position_and_height (double y, double h) const double y1 = midi_stream_view()->note_to_y(note->note()->note()); const double y2 = y1 + floor(midi_stream_view()->note_height()); - if(!canvas_item_visible(note)) { + if (!canvas_item_visible(note)) { note->show(); } @@ -556,7 +559,7 @@ MidiRegionView::add_ghost (TimeAxisView& tv) MidiTimeAxisView* mtv = dynamic_cast(&tv); MidiGhostRegion* ghost; - if(mtv && mtv->midi_view()) { + if (mtv && mtv->midi_view()) { /* if ghost is inserted into midi track, use a dedicated midi ghost canvas group. this is because it's nice to have midi notes on top of the note lines and audio waveforms under it. @@ -572,7 +575,7 @@ MidiRegionView::add_ghost (TimeAxisView& tv) ghosts.push_back (ghost); for (std::vector::iterator i = _events.begin(); i != _events.end(); ++i) { - if((note = dynamic_cast(*i)) != 0) { + if ((note = dynamic_cast(*i)) != 0) { ghost->add_note(note); } } @@ -683,8 +686,8 @@ MidiRegionView::add_note(const boost::shared_ptr note) MidiGhostRegion* gr; - for(vector::iterator g = ghosts.begin(); g != ghosts.end(); ++g) { - if((gr = dynamic_cast(*g)) != 0) { + for (vector::iterator g = ghosts.begin(); g != ghosts.end(); ++g) { + if ((gr = dynamic_cast(*g)) != 0) { gr->add_note(ev_rect); } } diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index 2c7429c85a..7169302315 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -137,15 +137,11 @@ MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shar MidiTimeAxisView::~MidiTimeAxisView () { - if(_piano_roll_header) { - delete _piano_roll_header; - _piano_roll_header = 0; - } + delete _piano_roll_header; + _piano_roll_header = 0; - if(_range_scroomer) { - delete _range_scroomer; - _range_scroomer = 0; - } + delete _range_scroomer; + _range_scroomer = 0; } MidiStreamView* @@ -267,7 +263,7 @@ MidiTimeAxisView::update_range() MidiGhostRegion* mgr; for(list::iterator i = ghosts.begin(); i != ghosts.end(); ++i) { - if((mgr = dynamic_cast(*i)) != 0) { + if ((mgr = dynamic_cast(*i)) != 0) { mgr->update_range(); } } diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc index fe15fc9668..ffe64e6451 100644 --- a/gtk2_ardour/region_view.cc +++ b/gtk2_ardour/region_view.cc @@ -530,7 +530,8 @@ RegionView::move (double x_delta, double y_delta) } void -RegionView::remove_ghost_in (TimeAxisView& tv) { +RegionView::remove_ghost_in (TimeAxisView& tv) +{ for (vector::iterator i = ghosts.begin(); i != ghosts.end(); ++i) { if (&(*i)->trackview == &tv) { delete *i; diff --git a/gtk2_ardour/region_view.h b/gtk2_ardour/region_view.h index 33b4a7a5e9..a83010c490 100644 --- a/gtk2_ardour/region_view.h +++ b/gtk2_ardour/region_view.h @@ -89,7 +89,6 @@ class RegionView : public TimeAxisViewItem void enable_display(bool yn) { _enable_display = yn; } static sigc::signal RegionViewGoingAway; - sigc::signal GoingAway; protected: diff --git a/gtk2_ardour/streamview.cc b/gtk2_ardour/streamview.cc index d1ed929f46..46cb078c63 100644 --- a/gtk2_ardour/streamview.cc +++ b/gtk2_ardour/streamview.cc @@ -47,6 +47,7 @@ using namespace Editing; StreamView::StreamView (RouteTimeAxisView& tv, ArdourCanvas::Group* group) : _trackview (tv) + , owns_canvas_group(group == 0) , canvas_group(group ? group : new ArdourCanvas::Group(*_trackview.canvas_display)) , canvas_rect(new ArdourCanvas::SimpleRect (*canvas_group)) , _samples_per_unit(_trackview.editor.get_current_zoom()) @@ -85,7 +86,12 @@ StreamView::StreamView (RouteTimeAxisView& tv, ArdourCanvas::Group* group) StreamView::~StreamView () { undisplay_diskstream (); - delete canvas_group; + + delete canvas_rect; + + if (owns_canvas_group) { + delete canvas_group; + } } void @@ -170,8 +176,9 @@ StreamView::remove_region_view (boost::weak_ptr weak_r) for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { if (((*i)->region()) == r) { - delete *i; + RegionView* rv = *i; region_views.erase (i); + delete rv; break; } } @@ -180,8 +187,11 @@ StreamView::remove_region_view (boost::weak_ptr weak_r) void StreamView::undisplay_diskstream () { - for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) { + for (RegionViewList::iterator i = region_views.begin(); i != region_views.end() ; ) { + RegionViewList::iterator next = i; + ++next; delete *i; + i = next; } region_views.clear(); diff --git a/gtk2_ardour/streamview.h b/gtk2_ardour/streamview.h index 883c82d198..cb7a3332cd 100644 --- a/gtk2_ardour/streamview.h +++ b/gtk2_ardour/streamview.h @@ -127,6 +127,7 @@ protected: virtual void color_handler () = 0; RouteTimeAxisView& _trackview; + bool owns_canvas_group; ArdourCanvas::Group* canvas_group; ArdourCanvas::SimpleRect* canvas_rect; /* frame around the whole thing */ diff --git a/libs/ardour/region_factory.cc b/libs/ardour/region_factory.cc index bb40fb16cf..bd4b0873a7 100644 --- a/libs/ardour/region_factory.cc +++ b/libs/ardour/region_factory.cc @@ -108,8 +108,6 @@ RegionFactory::create (Session& session, XMLNode& node, bool yn) boost::shared_ptr RegionFactory::create (const SourceList& srcs, nframes_t start, nframes_t length, const string& name, layer_t layer, Region::Flag flags, bool announce) { - cerr << "CREATE REGION " << name << " " << start << " * " << length << endl; - if (srcs.empty()) { return boost::shared_ptr(); } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 52cfc093cc..ae41f3c0dc 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -334,6 +334,8 @@ Session::destroy () AudioDiskstream::free_working_buffers(); + Route::SyncOrderKeys.clear(); + #undef TRACK_DESTRUCTION #ifdef TRACK_DESTRUCTION cerr << "delete named selections\n"; @@ -396,7 +398,7 @@ Session::destroy () #ifdef TRACK_DESTRUCTION cerr << "delete routes\n"; #endif /* TRACK_DESTRUCTION */ - { + { RCUWriter writer (routes); boost::shared_ptr r = writer.get_copy (); for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { -- cgit v1.2.3