From 6baac7d46f95cfe94eb1a67f64a2a68f0cf4552d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 2 Jun 2016 08:42:58 -0400 Subject: various safety checks for the result of dynamic_cast-ing a TimeAxisView to RouteTimeAxisView Now that we have VCATimeAxisView, this needed to be done, but it also potentially applied with automation --- gtk2_ardour/audio_region_view.cc | 5 +- gtk2_ardour/automation_time_axis.cc | 8 +-- gtk2_ardour/editor_drag.cc | 16 +++++- gtk2_ardour/editor_mouse.cc | 4 +- gtk2_ardour/editor_ops.cc | 102 ++++++++++++++++++------------------ gtk2_ardour/editor_routes.cc | 30 +++++++++++ 6 files changed, 106 insertions(+), 59 deletions(-) diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index ca0e5c68a9..1b984ab79d 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -1409,7 +1409,10 @@ GhostRegion* AudioRegionView::add_ghost (TimeAxisView& tv) { RouteTimeAxisView* rtv = dynamic_cast(&trackview); - assert(rtv); + + if (!rtv) { + return 0; + } double unit_position = _region->position () / samples_per_pixel; AudioGhostRegion* ghost = new AudioGhostRegion (*this, tv, trackview, unit_position); diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc index 820cc62501..9b5d999164 100644 --- a/gtk2_ardour/automation_time_axis.cc +++ b/gtk2_ardour/automation_time_axis.cc @@ -200,12 +200,12 @@ AutomationTimeAxisView::AutomationTimeAxisView ( // subscribe to route_active_changed, ... if (rtv && rtv->is_audio_track()) { blank0->set_name ("AudioTrackControlsBaseUnselected"); - } - else if (rtv && rtv->is_midi_track()) { + } else if (rtv && rtv->is_midi_track()) { blank0->set_name ("MidiTrackControlsBaseUnselected"); - } - else { + } else if (rtv) { blank0->set_name ("AudioBusControlsBaseUnselected"); + } else { + blank0->set_name ("UnknownControlsBaseUnselected"); } blank0->set_size_request (-1, -1); blank1->set_size_request (1, 0); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index bebc501ce7..c29fa230d4 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -529,7 +529,19 @@ struct PresentationInfoTimeAxisViewSorter { bool operator() (TimeAxisView* a, TimeAxisView* b) { RouteTimeAxisView* ra = dynamic_cast (a); RouteTimeAxisView* rb = dynamic_cast (b); - assert (ra && rb); + /* anything not a route goes at the end */ + if (!ra && rb) { + return false; + } + if (!rb && ra) { + return true; + } + if (!ra && !rb) { + /* XXXX pointer comparison. Should use + presentation_info in a time axis view + */ + return a < b; + } return ra->route()->presentation_info () < rb->route()->presentation_info(); } }; @@ -846,7 +858,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move) RouteTimeAxisView* rtv = dynamic_cast (tv); if (!rtv || !rtv->is_track()) { - /* ignore busses early on. we can't move any regions on them */ + /* ignore non-tracks early on. we can't move any regions on them */ } else if (_last_pointer_time_axis_view < 0) { /* Was in the drop-zone, now over a track. * Hence it must be an upward move (from the bottom) diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 9962e0e4d4..dfdd7d995f 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -2096,7 +2096,7 @@ Editor::visible_order_range (int* low, int* high) const RouteTimeAxisView* rtv = dynamic_cast (*i); - if (!rtv->hidden()) { + if (rtv && !rtv->hidden()) { if (*high < rtv->order()) { *high = rtv->order (); @@ -2309,7 +2309,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, framepos_t pos) RouteTimeAxisView* rtv = dynamic_cast(&rv->get_time_axis_view()); - if (rtv == 0 || !rtv->is_track()) { + if (!rtv || !rtv->is_track()) { return; } diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index d05b183028..ccb77558b8 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -2574,7 +2574,7 @@ Editor::play_from_edit_point_and_return () void Editor::play_selection () { - framepos_t start, end; + framepos_t start, end; if (!get_selection_extents ( start, end)) return; @@ -3043,62 +3043,63 @@ Editor::separate_regions_between (const TimeSelection& ts) for (TrackSelection::iterator i = tmptracks.begin(); i != tmptracks.end(); ++i) { - RouteTimeAxisView* rtv; - - if ((rtv = dynamic_cast ((*i))) != 0) { + RouteTimeAxisView* rtv = dynamic_cast ((*i)); - if (rtv->is_track()) { + if (!rtv) { + continue; + } - /* no edits to destructive tracks */ + if (!rtv->is_track()) { + continue; + } - if (rtv->track()->destructive()) { - continue; - } + /* no edits to destructive tracks */ - if ((playlist = rtv->playlist()) != 0) { + if (rtv->track()->destructive()) { + continue; + } - playlist->clear_changes (); + if ((playlist = rtv->playlist()) != 0) { - /* XXX need to consider musical time selections here at some point */ + playlist->clear_changes (); - double speed = rtv->track()->speed(); + /* XXX need to consider musical time selections here at some point */ + double speed = rtv->track()->speed(); - for (list::const_iterator t = ts.begin(); t != ts.end(); ++t) { + for (list::const_iterator t = ts.begin(); t != ts.end(); ++t) { - sigc::connection c = rtv->view()->RegionViewAdded.connect ( - sigc::mem_fun(*this, &Editor::collect_new_region_view)); + sigc::connection c = rtv->view()->RegionViewAdded.connect ( + sigc::mem_fun(*this, &Editor::collect_new_region_view)); - latest_regionviews.clear (); + latest_regionviews.clear (); - playlist->partition ((framepos_t)((*t).start * speed), - (framepos_t)((*t).end * speed), false); + playlist->partition ((framepos_t)((*t).start * speed), + (framepos_t)((*t).end * speed), false); - c.disconnect (); + c.disconnect (); - if (!latest_regionviews.empty()) { + if (!latest_regionviews.empty()) { - rtv->view()->foreach_regionview (sigc::bind ( - sigc::ptr_fun (add_if_covered), - &(*t), &new_selection)); + rtv->view()->foreach_regionview (sigc::bind ( + sigc::ptr_fun (add_if_covered), + &(*t), &new_selection)); - if (!in_command) { - begin_reversible_command (_("separate")); - in_command = true; - } + if (!in_command) { + begin_reversible_command (_("separate")); + in_command = true; + } - /* pick up changes to existing regions */ + /* pick up changes to existing regions */ - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); + vector cmds; + playlist->rdiff (cmds); + _session->add_commands (cmds); - /* pick up changes to the playlist itself (adds/removes) - */ + /* pick up changes to the playlist itself (adds/removes) + */ - _session->add_command(new StatefulDiffCommand (playlist)); - } - } + _session->add_command(new StatefulDiffCommand (playlist)); } } } @@ -3218,7 +3219,7 @@ Editor::separate_under_selected_regions () if (!playlist) { // is this check necessary? - continue; + continue; } vector::iterator i; @@ -3293,17 +3294,18 @@ Editor::crop_region_to (framepos_t start, framepos_t end) for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) { - RouteTimeAxisView* rtv; + RouteTimeAxisView* rtv = dynamic_cast ((*i)); - if ((rtv = dynamic_cast ((*i))) != 0) { + if (!rtv) { + continue; + } - boost::shared_ptr t = rtv->track(); + boost::shared_ptr t = rtv->track(); - if (t != 0 && ! t->destructive()) { + if (t != 0 && ! t->destructive()) { - if ((playlist = rtv->playlist()) != 0) { - playlists.push_back (playlist); - } + if ((playlist = rtv->playlist()) != 0) { + playlists.push_back (playlist); } } } @@ -3392,7 +3394,7 @@ Editor::region_fill_track () sigc::connection c = rtv->view()->RegionViewAdded.connect (sigc::mem_fun(*this, &Editor::collect_new_region_view)); framepos_t const position = end_frame + (r->first_frame() - start_frame + 1); - playlist = (*i)->region()->playlist(); + playlist = (*i)->region()->playlist(); playlist->clear_changes (); playlist->duplicate_until (r, position, gap, end); _session->add_command(new StatefulDiffCommand (playlist)); @@ -3957,9 +3959,9 @@ Editor::bounce_range_selection (bool replace, bool enable_processing) for (TrackViewList::iterator i = views.begin(); i != views.end(); ++i) { - RouteTimeAxisView* rtv; + RouteTimeAxisView* rtv = dynamic_cast (*i); - if ((rtv = dynamic_cast (*i)) == 0) { + if (!rtv) { continue; } @@ -4384,7 +4386,7 @@ Editor::remove_selected_regions () if (!playlist) { // is this check necessary? - continue; + continue; } /* get_regions_from_selection_and_entered() guarantees that @@ -4788,7 +4790,7 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) sigc::connection c = rtv->view()->RegionViewAdded.connect (sigc::mem_fun(*this, &Editor::collect_new_region_view)); framepos_t const position = end_frame + (r->first_frame() - start_frame + 1); - playlist = (*i)->region()->playlist(); + playlist = (*i)->region()->playlist(); playlist->clear_changes (); playlist->duplicate (r, position, gap, times); _session->add_command(new StatefulDiffCommand (playlist)); diff --git a/gtk2_ardour/editor_routes.cc b/gtk2_ardour/editor_routes.cc index 70d8887204..0fbc0db5b2 100644 --- a/gtk2_ardour/editor_routes.cc +++ b/gtk2_ardour/editor_routes.cc @@ -425,6 +425,11 @@ EditorRoutes::on_tv_rec_enable_changed (std::string const & path_string) TimeAxisView* tv = row[_columns.tv]; RouteTimeAxisView *rtv = dynamic_cast (tv); + + if (!rtv) { + return; + } + boost::shared_ptr ac = rtv->route()->rec_enable_control(); if (ac) { @@ -438,6 +443,11 @@ EditorRoutes::on_tv_rec_safe_toggled (std::string const & path_string) Gtk::TreeModel::Row row = *_model->get_iter (Gtk::TreeModel::Path (path_string)); TimeAxisView* tv = row[_columns.tv]; RouteTimeAxisView *rtv = dynamic_cast (tv); + + if (!rtv) { + return; + } + boost::shared_ptr ac (rtv->route()->rec_safe_control()); if (ac) { @@ -453,6 +463,11 @@ EditorRoutes::on_tv_mute_enable_toggled (std::string const & path_string) TimeAxisView *tv = row[_columns.tv]; RouteTimeAxisView *rtv = dynamic_cast (tv); + + if (!rtv) { + return; + } + boost::shared_ptr ac (rtv->route()->mute_control()); if (ac) { @@ -468,6 +483,11 @@ EditorRoutes::on_tv_solo_enable_toggled (std::string const & path_string) TimeAxisView *tv = row[_columns.tv]; RouteTimeAxisView* rtv = dynamic_cast (tv); + + if (!rtv) { + return; + } + boost::shared_ptr ac (rtv->route()->solo_control()); if (ac) { @@ -483,6 +503,11 @@ EditorRoutes::on_tv_solo_isolate_toggled (std::string const & path_string) TimeAxisView *tv = row[_columns.tv]; RouteTimeAxisView* rtv = dynamic_cast (tv); + + if (!rtv) { + return; + } + boost::shared_ptr ac (rtv->route()->solo_isolate_control()); if (ac) { @@ -498,6 +523,11 @@ EditorRoutes::on_tv_solo_safe_toggled (std::string const & path_string) TimeAxisView *tv = row[_columns.tv]; RouteTimeAxisView* rtv = dynamic_cast (tv); + + if (!rtv) { + return; + } + boost::shared_ptr ac (rtv->route()->solo_safe_control()); if (ac) { -- cgit v1.2.3