2013-01-16 13:22:15 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2008-2012 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2016 Nick Mainsbridge <mainsbridge@gmail.com>
|
|
|
|
* Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-01-16 13:22:15 -05:00
|
|
|
|
2008-02-01 22:57:35 -05:00
|
|
|
#include <gtkmm/stock.h>
|
|
|
|
#include <gtkmm2ext/utils.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/memento_command.h"
|
2010-02-11 12:08:34 -05:00
|
|
|
#include "pbd/convert.h"
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/audioregion.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/onset_detector.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/session.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/transient_detector.h"
|
2008-02-01 22:57:35 -05:00
|
|
|
|
|
|
|
#include "rhythm_ferret.h"
|
|
|
|
#include "audio_region_view.h"
|
2010-07-06 07:33:27 -04:00
|
|
|
#include "editor.h"
|
2009-06-28 20:38:32 -04:00
|
|
|
#include "time_axis_view.h"
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2008-02-01 22:57:35 -05:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gdk;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
|
|
|
/* order of these must match the AnalysisMode enums
|
|
|
|
in rhythm_ferret.h
|
|
|
|
*/
|
|
|
|
static const gchar * _analysis_mode_strings[] = {
|
|
|
|
N_("Percussive Onset"),
|
|
|
|
N_("Note Onset"),
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
static const gchar * _onset_function_strings[] = {
|
|
|
|
N_("Energy Based"),
|
|
|
|
N_("Spectral Difference"),
|
|
|
|
N_("High-Frequency Content"),
|
|
|
|
N_("Complex Domain"),
|
|
|
|
N_("Phase Deviation"),
|
|
|
|
N_("Kullback-Liebler"),
|
|
|
|
N_("Modified Kullback-Liebler"),
|
2016-05-01 12:48:27 -04:00
|
|
|
#ifdef HAVE_AUBIO4
|
|
|
|
N_("Spectral Flux"),
|
|
|
|
#endif
|
2008-09-10 11:03:30 -04:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
static const gchar * _operation_strings[] = {
|
|
|
|
N_("Split region"),
|
2016-05-01 12:48:27 -04:00
|
|
|
#if 0 // these don't do what a user expects
|
2011-01-19 13:35:11 -05:00
|
|
|
N_("Snap regions"),
|
|
|
|
N_("Conform regions"),
|
2016-05-01 12:48:27 -04:00
|
|
|
#endif
|
2010-04-30 09:29:14 -04:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2010-07-06 07:33:27 -04:00
|
|
|
RhythmFerret::RhythmFerret (Editor& e)
|
2008-02-01 22:57:35 -05:00
|
|
|
: ArdourDialog (_("Rhythm Ferret"))
|
|
|
|
, editor (e)
|
2016-05-01 12:48:27 -04:00
|
|
|
, detection_threshold_adjustment (-35, -80, -6, 1, 6)
|
2008-02-01 22:57:35 -05:00
|
|
|
, detection_threshold_scale (detection_threshold_adjustment)
|
|
|
|
, sensitivity_adjustment (40, 0, 100, 1, 10)
|
|
|
|
, sensitivity_scale (sensitivity_adjustment)
|
|
|
|
, analyze_button (_("Analyze"))
|
2008-09-10 11:03:30 -04:00
|
|
|
, peak_picker_threshold_adjustment (0.3, 0.0, 1.0, 0.01, 0.1)
|
|
|
|
, peak_picker_threshold_scale (peak_picker_threshold_adjustment)
|
2016-05-05 22:02:34 -04:00
|
|
|
, silence_threshold_adjustment (-90.0, -120.0, 0.0, 1, 10)
|
|
|
|
, silence_threshold_scale (silence_threshold_adjustment)
|
2016-05-01 12:48:27 -04:00
|
|
|
#ifdef HAVE_AUBIO4
|
|
|
|
, minioi_adjustment (4, 0, 40, 1, 5)
|
|
|
|
, minioi_scale (minioi_adjustment)
|
|
|
|
#endif
|
2008-02-01 22:57:35 -05:00
|
|
|
, trigger_gap_adjustment (3, 0, 100, 1, 10)
|
|
|
|
, trigger_gap_spinner (trigger_gap_adjustment)
|
|
|
|
, action_button (Stock::APPLY)
|
|
|
|
{
|
2010-04-30 09:29:14 -04:00
|
|
|
operation_strings = I18N (_operation_strings);
|
|
|
|
Gtkmm2ext::set_popdown_strings (operation_selector, operation_strings);
|
|
|
|
operation_selector.set_active (0);
|
2008-02-01 22:57:35 -05:00
|
|
|
|
|
|
|
analysis_mode_strings = I18N (_analysis_mode_strings);
|
|
|
|
Gtkmm2ext::set_popdown_strings (analysis_mode_selector, analysis_mode_strings);
|
|
|
|
analysis_mode_selector.set_active_text (analysis_mode_strings.front());
|
2009-12-11 18:29:48 -05:00
|
|
|
analysis_mode_selector.signal_changed().connect (sigc::mem_fun (*this, &RhythmFerret::analysis_mode_changed));
|
2008-09-10 11:03:30 -04:00
|
|
|
|
|
|
|
onset_function_strings = I18N (_onset_function_strings);
|
|
|
|
Gtkmm2ext::set_popdown_strings (onset_detection_function_selector, onset_function_strings);
|
2009-10-14 12:10:01 -04:00
|
|
|
/* Onset plugin uses complex domain as default function
|
2008-09-10 11:03:30 -04:00
|
|
|
XXX there should be a non-hacky way to set this
|
|
|
|
*/
|
|
|
|
onset_detection_function_selector.set_active_text (onset_function_strings[3]);
|
2011-03-02 07:43:44 -05:00
|
|
|
detection_threshold_scale.set_digits (3);
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
Table* t = manage (new Table (7, 3));
|
|
|
|
t->set_spacings (12);
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
int n = 0;
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
t->attach (*manage (new Label (_("Mode"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
|
|
|
t->attach (analysis_mode_selector, 1, 2, n, n + 1, FILL);
|
|
|
|
++n;
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
t->attach (*manage (new Label (_("Detection function"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
|
|
|
t->attach (onset_detection_function_selector, 1, 2, n, n + 1, FILL);
|
|
|
|
++n;
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2016-05-01 12:48:27 -04:00
|
|
|
t->attach (*manage (new Label (_("Trigger gap (postproc)"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
2010-04-30 09:29:14 -04:00
|
|
|
t->attach (trigger_gap_spinner, 1, 2, n, n + 1, FILL);
|
|
|
|
t->attach (*manage (new Label (_("ms"))), 2, 3, n, n + 1, FILL);
|
|
|
|
++n;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
t->attach (*manage (new Label (_("Peak threshold"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
|
|
|
t->attach (peak_picker_threshold_scale, 1, 2, n, n + 1, FILL);
|
|
|
|
++n;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
t->attach (*manage (new Label (_("Silence threshold"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
|
|
|
t->attach (silence_threshold_scale, 1, 2, n, n + 1, FILL);
|
|
|
|
t->attach (*manage (new Label (_("dB"))), 2, 3, n, n + 1, FILL);
|
|
|
|
++n;
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2016-05-01 12:48:27 -04:00
|
|
|
#ifdef HAVE_AUBIO4
|
|
|
|
t->attach (*manage (new Label (_("Min Inter-Onset Time"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
|
|
|
t->attach (minioi_scale, 1, 2, n, n + 1, FILL);
|
|
|
|
t->attach (*manage (new Label (_("ms"))), 2, 3, n, n + 1, FILL);
|
|
|
|
++n;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
t->attach (*manage (new Label (_("Sensitivity"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
|
|
|
t->attach (sensitivity_scale, 1, 2, n, n + 1, FILL);
|
|
|
|
++n;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-05-01 12:48:27 -04:00
|
|
|
t->attach (*manage (new Label (_("Cut Pos Threshold"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
|
|
|
t->attach (detection_threshold_scale, 1, 2, n, n + 1, FILL);
|
|
|
|
t->attach (*manage (new Label (_("dB"))), 2, 3, n, n + 1, FILL);
|
|
|
|
++n;
|
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
t->attach (*manage (new Label (_("Operation"), 1, 0.5)), 0, 1, n, n + 1, FILL);
|
|
|
|
t->attach (operation_selector, 1, 2, n, n + 1, FILL);
|
|
|
|
++n;
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
analyze_button.signal_clicked().connect (sigc::mem_fun (*this, &RhythmFerret::run_analysis));
|
2009-12-11 18:29:48 -05:00
|
|
|
action_button.signal_clicked().connect (sigc::mem_fun (*this, &RhythmFerret::do_action));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-02-01 22:57:35 -05:00
|
|
|
get_vbox()->set_border_width (6);
|
|
|
|
get_vbox()->set_spacing (6);
|
2010-04-30 09:29:14 -04:00
|
|
|
get_vbox()->pack_start (*t);
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
add_action_widget (analyze_button, 1);
|
|
|
|
add_action_widget (action_button, 0);
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2010-04-30 09:29:14 -04:00
|
|
|
show_all ();
|
|
|
|
analysis_mode_changed ();
|
2008-02-01 22:57:35 -05:00
|
|
|
}
|
|
|
|
|
2017-04-06 18:29:02 -04:00
|
|
|
void
|
|
|
|
RhythmFerret::on_response (int response_id)
|
|
|
|
{
|
|
|
|
Gtk::Dialog::on_response (response_id);
|
|
|
|
}
|
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
void
|
|
|
|
RhythmFerret::analysis_mode_changed ()
|
|
|
|
{
|
2010-04-30 09:29:14 -04:00
|
|
|
bool const perc = get_analysis_mode() == PercussionOnset;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2016-05-01 12:48:27 -04:00
|
|
|
// would be nice to actually hide/show the rows.
|
2010-04-30 09:29:14 -04:00
|
|
|
detection_threshold_scale.set_sensitive (perc);
|
|
|
|
sensitivity_scale.set_sensitive (perc);
|
2016-05-01 12:48:27 -04:00
|
|
|
trigger_gap_spinner.set_sensitive (!perc);
|
2010-04-30 09:29:14 -04:00
|
|
|
onset_detection_function_selector.set_sensitive (!perc);
|
|
|
|
peak_picker_threshold_scale.set_sensitive (!perc);
|
|
|
|
silence_threshold_scale.set_sensitive (!perc);
|
2016-05-01 12:48:27 -04:00
|
|
|
#ifdef HAVE_AUBIO4
|
|
|
|
minioi_scale.set_sensitive (!perc);
|
|
|
|
#endif
|
2008-09-10 11:03:30 -04:00
|
|
|
}
|
|
|
|
|
2008-02-01 22:57:35 -05:00
|
|
|
RhythmFerret::AnalysisMode
|
|
|
|
RhythmFerret::get_analysis_mode () const
|
|
|
|
{
|
|
|
|
string str = analysis_mode_selector.get_active_text ();
|
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
if (str == analysis_mode_strings[(int) NoteOnset]) {
|
2008-02-01 22:57:35 -05:00
|
|
|
return NoteOnset;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-02-01 22:57:35 -05:00
|
|
|
|
|
|
|
return PercussionOnset;
|
|
|
|
}
|
|
|
|
|
|
|
|
RhythmFerret::Action
|
|
|
|
RhythmFerret::get_action () const
|
|
|
|
{
|
2010-04-30 09:29:14 -04:00
|
|
|
if (operation_selector.get_active_row_number() == 1) {
|
2011-01-19 13:35:11 -05:00
|
|
|
return SnapRegionsToGrid;
|
2010-04-30 09:29:14 -04:00
|
|
|
} else if (operation_selector.get_active_row_number() == 2) {
|
2008-02-01 22:57:35 -05:00
|
|
|
return ConformRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SplitRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RhythmFerret::run_analysis ()
|
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
if (!_session) {
|
2008-02-01 22:57:35 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-28 20:33:49 -05:00
|
|
|
clear_transients ();
|
|
|
|
|
2023-10-30 23:31:08 -04:00
|
|
|
for (auto const& rv : editor.get_selection().regions) {
|
|
|
|
regions_with_transients.push_back (rv->region ());
|
|
|
|
}
|
2008-02-01 22:57:35 -05:00
|
|
|
|
|
|
|
current_results.clear ();
|
|
|
|
|
2010-12-28 20:33:49 -05:00
|
|
|
if (regions_with_transients.empty()) {
|
2008-02-01 22:57:35 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-30 23:31:08 -04:00
|
|
|
for (auto const& r : regions_with_transients) {
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2023-10-30 23:31:08 -04:00
|
|
|
std::shared_ptr<AudioReadable> rd = std::static_pointer_cast<AudioRegion> (r);
|
2008-02-01 22:57:35 -05:00
|
|
|
|
|
|
|
switch (get_analysis_mode()) {
|
|
|
|
case PercussionOnset:
|
2023-10-30 23:31:08 -04:00
|
|
|
run_percussion_onset_analysis (rd, r->position_sample(), current_results);
|
2008-02-01 22:57:35 -05:00
|
|
|
break;
|
2008-09-10 11:03:30 -04:00
|
|
|
case NoteOnset:
|
2023-10-30 23:31:08 -04:00
|
|
|
run_note_onset_analysis (rd, r->position_sample(), current_results);
|
2008-09-10 11:03:30 -04:00
|
|
|
break;
|
2008-02-01 22:57:35 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2023-10-30 23:31:08 -04:00
|
|
|
r->set_onsets (current_results);
|
2010-07-06 07:33:27 -04:00
|
|
|
current_results.clear();
|
2008-02-01 22:57:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2023-02-16 18:33:28 -05:00
|
|
|
RhythmFerret::run_percussion_onset_analysis (std::shared_ptr<AudioReadable> readable, sampleoffset_t /*offset*/, AnalysisFeatureList& results)
|
2008-02-01 22:57:35 -05:00
|
|
|
{
|
2017-02-04 07:58:33 -05:00
|
|
|
try {
|
2017-09-18 12:39:17 -04:00
|
|
|
TransientDetector t (_session->sample_rate());
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2017-02-04 07:58:33 -05:00
|
|
|
for (uint32_t i = 0; i < readable->n_channels(); ++i) {
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2017-02-04 07:58:33 -05:00
|
|
|
AnalysisFeatureList these_results;
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2017-02-04 07:58:33 -05:00
|
|
|
t.reset ();
|
|
|
|
float dB = detection_threshold_adjustment.get_value();
|
|
|
|
float coeff = dB > -80.0f ? pow (10.0f, dB * 0.05f) : 0.0f;
|
|
|
|
t.set_threshold (coeff);
|
|
|
|
t.set_sensitivity (4, sensitivity_adjustment.get_value());
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2017-02-04 07:58:33 -05:00
|
|
|
if (t.run ("", readable.get(), i, these_results)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* merge */
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2017-02-04 07:58:33 -05:00
|
|
|
results.insert (results.end(), these_results.begin(), these_results.end());
|
|
|
|
these_results.clear ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2017-02-04 07:58:33 -05:00
|
|
|
t.update_positions (readable.get(), i, results);
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-02-04 07:58:33 -05:00
|
|
|
} catch (failed_constructor& err) {
|
|
|
|
error << "Could not load percussion onset detection plugin" << endmsg;
|
|
|
|
return -1;
|
2008-02-01 22:57:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
int
|
|
|
|
RhythmFerret::get_note_onset_function ()
|
|
|
|
{
|
|
|
|
string txt = onset_detection_function_selector.get_active_text();
|
|
|
|
|
|
|
|
for (int n = 0; _onset_function_strings[n]; ++n) {
|
|
|
|
/* compare translated versions */
|
|
|
|
if (txt == onset_function_strings[n]) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal note onset function string"), txt)
|
|
|
|
<< endmsg;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-11-14 04:47:43 -05:00
|
|
|
abort(); /*NOTREACHED*/
|
2008-09-10 11:03:30 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2023-02-16 18:33:28 -05:00
|
|
|
RhythmFerret::run_note_onset_analysis (std::shared_ptr<AudioReadable> readable, sampleoffset_t /*offset*/, AnalysisFeatureList& results)
|
2008-09-10 11:03:30 -04:00
|
|
|
{
|
|
|
|
try {
|
2017-09-18 12:39:17 -04:00
|
|
|
OnsetDetector t (_session->sample_rate());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
for (uint32_t i = 0; i < readable->n_channels(); ++i) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
AnalysisFeatureList these_results;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
t.set_function (get_note_onset_function());
|
|
|
|
t.set_silence_threshold (silence_threshold_adjustment.get_value());
|
|
|
|
t.set_peak_threshold (peak_picker_threshold_adjustment.get_value());
|
2016-05-01 12:48:27 -04:00
|
|
|
#ifdef HAVE_AUBIO4
|
|
|
|
t.set_minioi (minioi_adjustment.get_value());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// aubio-vamp only picks up new settings on reset.
|
|
|
|
t.reset ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
if (t.run ("", readable.get(), i, these_results)) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
/* merge */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
results.insert (results.end(), these_results.begin(), these_results.end());
|
|
|
|
these_results.clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (failed_constructor& err) {
|
|
|
|
error << "Could not load note onset detection plugin" << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!results.empty()) {
|
2017-09-18 12:39:17 -04:00
|
|
|
OnsetDetector::cleanup_onsets (results, _session->sample_rate(), trigger_gap_adjustment.get_value());
|
2008-09-10 11:03:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-01 22:57:35 -05:00
|
|
|
void
|
|
|
|
RhythmFerret::do_action ()
|
|
|
|
{
|
2010-07-06 07:33:27 -04:00
|
|
|
if (!_session) {
|
2008-02-01 22:57:35 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (get_action()) {
|
|
|
|
case SplitRegion:
|
|
|
|
do_split_action ();
|
|
|
|
break;
|
2011-01-19 13:35:11 -05:00
|
|
|
case SnapRegionsToGrid:
|
2016-05-01 12:48:27 -04:00
|
|
|
// split first, select all.. ?!
|
2011-01-19 13:35:11 -05:00
|
|
|
editor.snap_regions_to_grid();
|
|
|
|
break;
|
2010-07-06 07:33:27 -04:00
|
|
|
case ConformRegion:
|
|
|
|
editor.close_region_gaps();
|
|
|
|
break;
|
2008-02-01 22:57:35 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RhythmFerret::do_split_action ()
|
|
|
|
{
|
2011-01-19 13:35:11 -05:00
|
|
|
/* XXX: this is quite a special-case; (currently) the only operation which is
|
|
|
|
performed on the selection only (without entered_regionview or the edit point
|
|
|
|
being considered)
|
|
|
|
*/
|
2013-04-05 17:16:33 -04:00
|
|
|
RegionSelection regions = editor.selection->regions;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2008-02-01 22:57:35 -05:00
|
|
|
if (regions.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2016-04-08 13:21:13 -04:00
|
|
|
editor.EditorFreeze(); /* Emit signal */
|
|
|
|
|
2014-12-14 08:13:38 -05:00
|
|
|
editor.begin_reversible_command (_("split regions (rhythm ferret)"));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-06 07:33:27 -04:00
|
|
|
/* Merge the transient positions for regions in consideration */
|
|
|
|
AnalysisFeatureList merged_features;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-06 07:33:27 -04:00
|
|
|
for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
|
2011-03-02 07:43:44 -05:00
|
|
|
|
2010-07-06 07:33:27 -04:00
|
|
|
AnalysisFeatureList features;
|
2016-04-30 20:02:25 -04:00
|
|
|
(*i)->region()->transients(features);
|
2011-03-02 07:43:44 -05:00
|
|
|
|
2011-01-19 13:35:11 -05:00
|
|
|
merged_features.insert (merged_features.end(), features.begin(), features.end());
|
2010-07-06 07:33:27 -04:00
|
|
|
}
|
2011-03-02 07:43:44 -05:00
|
|
|
|
2010-07-06 07:33:27 -04:00
|
|
|
merged_features.sort();
|
|
|
|
merged_features.unique();
|
2008-02-01 22:57:35 -05:00
|
|
|
|
|
|
|
for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ) {
|
|
|
|
|
|
|
|
RegionSelection::iterator tmp;
|
|
|
|
|
|
|
|
tmp = i;
|
|
|
|
++tmp;
|
|
|
|
|
2011-03-02 07:43:44 -05:00
|
|
|
editor.split_region_at_points ((*i)->region(), merged_features, false, false);
|
2008-02-01 22:57:35 -05:00
|
|
|
|
|
|
|
/* i is invalid at this point */
|
|
|
|
i = tmp;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2014-12-14 08:13:38 -05:00
|
|
|
editor.commit_reversible_command ();
|
2016-04-08 13:21:13 -04:00
|
|
|
|
|
|
|
editor.EditorThaw(); /* Emit signal */
|
2008-02-01 22:57:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RhythmFerret::set_session (Session* s)
|
|
|
|
{
|
|
|
|
ArdourDialog::set_session (s);
|
|
|
|
current_results.clear ();
|
|
|
|
}
|
2008-03-17 16:54:03 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
RhythmFerret::on_hide ()
|
|
|
|
{
|
|
|
|
ArdourDialog::on_hide ();
|
2010-12-28 20:33:49 -05:00
|
|
|
clear_transients ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear any transients that we have added */
|
|
|
|
void
|
|
|
|
RhythmFerret::clear_transients ()
|
|
|
|
{
|
|
|
|
current_results.clear ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2023-10-30 23:31:08 -04:00
|
|
|
for (auto const& r : regions_with_transients) {
|
|
|
|
r->set_onsets (current_results);
|
2010-12-28 20:33:49 -05:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-12-28 20:33:49 -05:00
|
|
|
regions_with_transients.clear ();
|
2008-03-17 16:54:03 -04:00
|
|
|
}
|
|
|
|
|