Tidy up the region menu a bit, and hopefully clarify what regions will be
[ardour.git] / gtk2_ardour / rhythm_ferret.cc
index 8c67ceae21afd7c52033d5edfd0e78c45239a765..da31feca3c8fc6f81f3ae3f7489138fbec86301d 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "rhythm_ferret.h"
 #include "audio_region_view.h"
-#include "public_editor.h"
+#include "editor.h"
 #include "utils.h"
 #include "time_axis_view.h"
 
@@ -53,7 +53,7 @@ static const gchar * _operation_strings[] = {
        0
 };
 
-RhythmFerret::RhythmFerret (PublicEditor& e)
+RhythmFerret::RhythmFerret (Editor& e)
        : ArdourDialog (_("Rhythm Ferret"))
        , editor (e)
        , detection_threshold_adjustment (3, 0, 20, 1, 4)
@@ -205,17 +205,14 @@ RhythmFerret::run_analysis ()
                default:
                        break;
                }
-
-       }
-
-       for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
-               (*i)->get_time_axis_view().show_feature_lines (current_results);
+               
+               (*i)->region()->set_transients (current_results);
+               current_results.clear();
        }
-
 }
 
 int
-RhythmFerret::run_percussion_onset_analysis (boost::shared_ptr<Readable> readable, nframes64_t offset, AnalysisFeatureList& results)
+RhythmFerret::run_percussion_onset_analysis (boost::shared_ptr<Readable> readable, framepos_t /*offset*/, AnalysisFeatureList& results)
 {
        TransientDetector t (_session->frame_rate());
 
@@ -233,9 +230,9 @@ RhythmFerret::run_percussion_onset_analysis (boost::shared_ptr<Readable> readabl
 
                /* translate all transients to give absolute position */
 
-               for (AnalysisFeatureList::iterator x = these_results.begin(); x != these_results.end(); ++x) {
-                       (*x) += offset;
-               }
+               //for (AnalysisFeatureList::iterator x = these_results.begin(); x != these_results.end(); ++x) {
+               //      (*x) += offset;
+               //}
 
                /* merge */
 
@@ -268,7 +265,7 @@ RhythmFerret::get_note_onset_function ()
 }
 
 int
-RhythmFerret::run_note_onset_analysis (boost::shared_ptr<Readable> readable, nframes64_t offset, AnalysisFeatureList& results)
+RhythmFerret::run_note_onset_analysis (boost::shared_ptr<Readable> readable, framepos_t /*offset*/, AnalysisFeatureList& results)
 {
        try {
                OnsetDetector t (_session->frame_rate());
@@ -289,9 +286,9 @@ RhythmFerret::run_note_onset_analysis (boost::shared_ptr<Readable> readable, nfr
 
                        /* translate all transients to give absolute position */
 
-                       for (AnalysisFeatureList::iterator x = these_results.begin(); x != these_results.end(); ++x) {
-                               (*x) += offset;
-                       }
+                       //for (AnalysisFeatureList::iterator x = these_results.begin(); x != these_results.end(); ++x) {
+                       //      (*x) += offset;
+                       //}
 
                        /* merge */
 
@@ -314,7 +311,7 @@ RhythmFerret::run_note_onset_analysis (boost::shared_ptr<Readable> readable, nfr
 void
 RhythmFerret::do_action ()
 {
-       if (!_session || current_results.empty()) {
+       if (!_session) {
                return;
        }
 
@@ -322,7 +319,9 @@ RhythmFerret::do_action ()
        case SplitRegion:
                do_split_action ();
                break;
-
+       case ConformRegion:
+               editor.close_region_gaps();
+               break;
        default:
                break;
        }
@@ -331,15 +330,27 @@ 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);
-
+       
        if (regions.empty()) {
                return;
        }
 
        _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.sort();
+       merged_features.unique();
 
        for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ) {
 
@@ -348,9 +359,9 @@ RhythmFerret::do_split_action ()
                tmp = i;
                ++tmp;
 
-               (*i)->get_time_axis_view().hide_feature_lines ();
-
-               editor.split_region_at_points ((*i)->region(), current_results, false);
+               AnalysisFeatureList features;
+               features = (*i)->region()->transients();
+               editor.split_region_at_points ((*i)->region(), merged_features, false);
 
                /* i is invalid at this point */
 
@@ -367,15 +378,9 @@ RhythmFerret::set_session (Session* s)
        current_results.clear ();
 }
 
-static void hide_time_axis_features (TimeAxisView& tav)
-{
-       tav.hide_feature_lines ();
-}
-
 void
 RhythmFerret::on_hide ()
 {
-       editor.foreach_time_axis_view (sigc::ptr_fun (hide_time_axis_features));
        ArdourDialog::on_hide ();
 }