From ae32daa14886864a1661fa346e90690a93cf1101 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 20 Apr 2022 17:09:14 -0600 Subject: [PATCH] allow ARDOUR::Filter to be used with MIDI regions/sources --- gtk2_ardour/editor_ops.cc | 80 +++++++++++++++++++-------------------- libs/ardour/filter.cc | 2 - 2 files changed, 39 insertions(+), 43 deletions(-) diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 596cbfca38..82938ab698 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -6155,60 +6155,58 @@ Editor::apply_filter (Filter& filter, string command, ProgressReporter* progress RegionSelection::iterator tmp = r; ++tmp; - AudioRegionView* const arv = dynamic_cast(*r); - if (arv) { - boost::shared_ptr playlist = arv->region()->playlist(); + RegionView* const rv = *r; + boost::shared_ptr playlist = rv->region()->playlist(); - if (progress) { - progress->descend (1.0 / N); + if (progress) { + progress->descend (1.0 / N); + } + + if (rv->region()->apply (filter, progress) == 0) { + + playlist->clear_changes (); + playlist->clear_owned_changes (); + + if (!in_command) { + begin_reversible_command (command); + in_command = true; } - if (arv->audio_region()->apply (filter, progress) == 0) { + if (filter.results.empty ()) { - playlist->clear_changes (); - playlist->clear_owned_changes (); + /* no regions returned; remove the old one */ + // playlist->remove_region (rv->region ()); - if (!in_command) { - begin_reversible_command (command); - in_command = true; - } + } else { - if (filter.results.empty ()) { + playlist->freeze (); + std::vector >::iterator res = filter.results.begin (); - /* no regions returned; remove the old one */ - playlist->remove_region (arv->region ()); + /* first region replaces the old one */ + playlist->replace_region (rv->region(), *res, (*res)->position()); + ++res; - } else { - - playlist->freeze (); - std::vector >::iterator res = filter.results.begin (); - - /* first region replaces the old one */ - playlist->replace_region (arv->region(), *res, (*res)->position()); + /* add the rest */ + while (res != filter.results.end()) { + playlist->add_region (*res, (*res)->position()); ++res; - - /* add the rest */ - while (res != filter.results.end()) { - playlist->add_region (*res, (*res)->position()); - ++res; - } - playlist->thaw (); - } + playlist->thaw (); - /* We might have removed regions, which alters other regions' layering_index, - so we need to do a recursive diff here. - */ - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); - - _session->add_command(new StatefulDiffCommand (playlist)); } - if (progress) { - progress->ascend (); - } + /* We might have removed regions, which alters other regions' layering_index, + so we need to do a recursive diff here. + */ + vector cmds; + playlist->rdiff (cmds); + _session->add_commands (cmds); + + _session->add_command(new StatefulDiffCommand (playlist)); + } + + if (progress) { + progress->ascend (); } r = tmp; diff --git a/libs/ardour/filter.cc b/libs/ardour/filter.cc index 6a7ae284ab..4a98a7b4e3 100644 --- a/libs/ardour/filter.cc +++ b/libs/ardour/filter.cc @@ -80,8 +80,6 @@ Filter::make_new_sources (boost::shared_ptr region, SourceList& nsrcs, s if (aregion) { sample_rate = aregion->audio_source()->sample_rate(); - } else { - return -1; } }