+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;
+ }
+ }
+ 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> readable, nframes64_t offset, AnalysisFeatureList& results)
+{
+ try {
+ OnsetDetector t (session->frame_rate());
+
+ for (uint32_t i = 0; i < readable->n_channels(); ++i) {
+
+ AnalysisFeatureList these_results;
+
+ t.reset ();
+
+ 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());
+
+ if (t.run ("", readable.get(), i, these_results)) {
+ 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 ();
+ }
+
+ } catch (failed_constructor& err) {
+ error << "Could not load note onset detection plugin" << endmsg;
+ return -1;
+ }
+
+ if (!results.empty()) {
+ OnsetDetector::cleanup_onsets (results, session->frame_rate(), trigger_gap_adjustment.get_value());
+ }
+
+ return 0;
+}
+