set ARDOUR_SURFACES_PATH for a bundle, just like ARDOUR_PANNER_PATH
[ardour.git] / gtk2_ardour / rhythm_ferret.cc
index da31feca3c8fc6f81f3ae3f7489138fbec86301d..8845a29313d2a211d483f9bb77ad90a5a0651eae 100644 (file)
@@ -48,15 +48,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 +84,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);
@@ -145,6 +146,7 @@ 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 +170,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 +185,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<Readable> rd = boost::static_pointer_cast<AudioRegion> ((*i)->region());
 
@@ -228,20 +232,12 @@ RhythmFerret::run_percussion_onset_analysis (boost::shared_ptr<Readable> 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,8 +254,10 @@ 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;
 }
@@ -284,12 +282,6 @@ RhythmFerret::run_note_onset_analysis (boost::shared_ptr<Readable> readable, fra
                                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 +311,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,11 +325,17 @@ RhythmFerret::do_action ()
 void
 RhythmFerret::do_split_action ()
 {
-       RegionSelection& regions (editor.get_selection().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.get_regions_from_selection();
        
        if (regions.empty()) {
                return;
        }
+       
+       editor.EditorFreeze(); /* Emit signal */
 
        _session->begin_reversible_command (_("split regions (rhythm ferret)"));
        
@@ -342,13 +343,13 @@ RhythmFerret::do_split_action ()
        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();
 
@@ -359,16 +360,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
@@ -382,5 +382,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 ();
 }