X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Frhythm_ferret.cc;h=5a59b5ce5dfc3979e6e06c37e2387626e52f8a83;hb=e0533e9dd7df504236892fe0d8693e7ad9a6a278;hp=cba0042cfea6a9c0d5e115d5ae6f36fdee3c52a1;hpb=2f9184d65395da75a43ea21ffb5f11b8d577d27a;p=ardour.git diff --git a/gtk2_ardour/rhythm_ferret.cc b/gtk2_ardour/rhythm_ferret.cc index cba0042cfe..5a59b5ce5d 100644 --- a/gtk2_ardour/rhythm_ferret.cc +++ b/gtk2_ardour/rhythm_ferret.cc @@ -1,16 +1,32 @@ +/* + Copyright (C) 2012 Paul Davis + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #include #include #include "pbd/memento_command.h" #include "pbd/convert.h" -#include "ardour/transient_detector.h" -#include "ardour/onset_detector.h" -#include "ardour/audiosource.h" #include "ardour/audioregion.h" -#include "ardour/playlist.h" -#include "ardour/region_factory.h" +#include "ardour/onset_detector.h" #include "ardour/session.h" +#include "ardour/transient_detector.h" #include "rhythm_ferret.h" #include "audio_region_view.h" @@ -48,15 +64,15 @@ static const gchar * _onset_function_strings[] = { static const gchar * _operation_strings[] = { N_("Split region"), - N_("Set tempo map"), - N_("Conform region"), + N_("Snap regions"), + N_("Conform regions"), 0 }; RhythmFerret::RhythmFerret (Editor& e) : ArdourDialog (_("Rhythm Ferret")) , editor (e) - , detection_threshold_adjustment (3, 0, 20, 1, 4) + , detection_threshold_adjustment (0.015, 0.0, 0.1, 0.001, 0.1) , detection_threshold_scale (detection_threshold_adjustment) , sensitivity_adjustment (40, 0, 100, 1, 10) , sensitivity_scale (sensitivity_adjustment) @@ -84,6 +100,7 @@ RhythmFerret::RhythmFerret (Editor& e) XXX there should be a non-hacky way to set this */ onset_detection_function_selector.set_active_text (onset_function_strings[3]); + detection_threshold_scale.set_digits (3); Table* t = manage (new Table (7, 3)); t->set_spacings (12); @@ -112,7 +129,7 @@ RhythmFerret::RhythmFerret (Editor& e) t->attach (peak_picker_threshold_scale, 1, 2, n, n + 1, FILL); t->attach (*manage (new Label (_("dB"))), 2, 3, n, n + 1, FILL); ++n; - + 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); @@ -144,7 +161,8 @@ void RhythmFerret::analysis_mode_changed () { bool const perc = get_analysis_mode() == PercussionOnset; - + + trigger_gap_spinner.set_sensitive (!perc); detection_threshold_scale.set_sensitive (perc); sensitivity_scale.set_sensitive (perc); onset_detection_function_selector.set_sensitive (!perc); @@ -168,7 +186,7 @@ RhythmFerret::Action RhythmFerret::get_action () const { if (operation_selector.get_active_row_number() == 1) { - return DefineTempoMap; + return SnapRegionsToGrid; } else if (operation_selector.get_active_row_number() == 2) { return ConformRegion; } @@ -183,15 +201,17 @@ RhythmFerret::run_analysis () return; } - RegionSelection& regions (editor.get_selection().regions); + clear_transients (); + + regions_with_transients = editor.get_selection().regions; current_results.clear (); - if (regions.empty()) { + if (regions_with_transients.empty()) { return; } - for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) { + for (RegionSelection::iterator i = regions_with_transients.begin(); i != regions_with_transients.end(); ++i) { boost::shared_ptr rd = boost::static_pointer_cast ((*i)->region()); @@ -205,14 +225,14 @@ RhythmFerret::run_analysis () default: break; } - + (*i)->region()->set_transients (current_results); current_results.clear(); } } int -RhythmFerret::run_percussion_onset_analysis (boost::shared_ptr readable, nframes64_t offset, AnalysisFeatureList& results) +RhythmFerret::run_percussion_onset_analysis (boost::shared_ptr readable, frameoffset_t /*offset*/, AnalysisFeatureList& results) { TransientDetector t (_session->frame_rate()); @@ -228,20 +248,12 @@ RhythmFerret::run_percussion_onset_analysis (boost::shared_ptr readabl continue; } - /* translate all transients to give absolute position */ - - //for (AnalysisFeatureList::iterator x = these_results.begin(); x != these_results.end(); ++x) { - // (*x) += offset; - //} - /* merge */ results.insert (results.end(), these_results.begin(), these_results.end()); these_results.clear (); - } - if (!results.empty()) { - TransientDetector::cleanup_transients (results, _session->frame_rate(), trigger_gap_adjustment.get_value()); + t.update_positions (readable.get(), i, results); } return 0; @@ -258,14 +270,16 @@ RhythmFerret::get_note_onset_function () return n; } } + fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal note onset function string"), txt) << endmsg; + /*NOTREACHED*/ return -1; } int -RhythmFerret::run_note_onset_analysis (boost::shared_ptr readable, nframes64_t offset, AnalysisFeatureList& results) +RhythmFerret::run_note_onset_analysis (boost::shared_ptr readable, frameoffset_t /*offset*/, AnalysisFeatureList& results) { try { OnsetDetector t (_session->frame_rate()); @@ -284,12 +298,6 @@ RhythmFerret::run_note_onset_analysis (boost::shared_ptr readable, nfr continue; } - /* translate all transients to give absolute position */ - - //for (AnalysisFeatureList::iterator x = these_results.begin(); x != these_results.end(); ++x) { - // (*x) += offset; - //} - /* merge */ results.insert (results.end(), these_results.begin(), these_results.end()); @@ -319,6 +327,9 @@ RhythmFerret::do_action () case SplitRegion: do_split_action (); break; + case SnapRegionsToGrid: + editor.snap_regions_to_grid(); + break; case ConformRegion: editor.close_region_gaps(); break; @@ -330,29 +341,31 @@ RhythmFerret::do_action () void RhythmFerret::do_split_action () { - /* this can/will change the current selection, so work with a copy */ - - //RegionSelection& regions (editor.get_selection().regions); - RegionSelection regions; - editor.get_regions_for_action(regions); + /* 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) + */ + RegionSelection regions = editor.selection->regions; if (regions.empty()) { return; } + editor.EditorFreeze(); /* Emit signal */ + _session->begin_reversible_command (_("split regions (rhythm ferret)")); - + /* Merge the transient positions for regions in consideration */ AnalysisFeatureList merged_features; - + for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) { - + AnalysisFeatureList features; features = (*i)->region()->transients(); - - merged_features.insert (merged_features.end(), features.begin(), features.end()); + + merged_features.insert (merged_features.end(), features.begin(), features.end()); } - + merged_features.sort(); merged_features.unique(); @@ -363,16 +376,15 @@ RhythmFerret::do_split_action () tmp = i; ++tmp; - AnalysisFeatureList features; - features = (*i)->region()->transients(); - editor.split_region_at_points ((*i)->region(), merged_features, false); + editor.split_region_at_points ((*i)->region(), merged_features, false, false); /* i is invalid at this point */ - i = tmp; } _session->commit_reversible_command (); + + editor.EditorThaw(); /* Emit signal */ } void @@ -386,5 +398,19 @@ void RhythmFerret::on_hide () { ArdourDialog::on_hide (); + clear_transients (); +} + +/* Clear any transients that we have added */ +void +RhythmFerret::clear_transients () +{ + current_results.clear (); + + for (RegionSelection::iterator i = regions_with_transients.begin(); i != regions_with_transients.end(); ++i) { + (*i)->region()->set_transients (current_results); + } + + regions_with_transients.clear (); }