change appearance of panner data popup slightly (fixed width font so it doesn't bounc...
[ardour.git] / gtk2_ardour / rhythm_ferret.cc
index de18fe7b5d907d3c75e67d3c8c0ce8c45209bfda..0eb9e9640654fd2e4000dfe600a6befc91e9d985 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"
 
@@ -46,55 +46,32 @@ static const gchar * _onset_function_strings[] = {
        0
 };
 
-RhythmFerret::RhythmFerret (PublicEditor& e)
+static const gchar * _operation_strings[] = {
+       N_("Split region"),
+       N_("Snap regions"),
+       N_("Conform regions"),
+       0
+};
+
+RhythmFerret::RhythmFerret (Editor& e)
        : ArdourDialog (_("Rhythm Ferret"))
        , editor (e)
-       , operation_frame (_("Operation"))
-       , selection_frame (_("Selection"))
-       , ferret_frame (_("Analysis"))
-       , logo (0)
-       , region_split_button (operation_button_group, _("Split region"))
-       , tempo_button (operation_button_group, _("Set tempo map"))
-       , region_conform_button (operation_button_group, _("Conform region"))
-       , analysis_mode_label (_("Mode"))
        , detection_threshold_adjustment (3, 0, 20, 1, 4)
        , detection_threshold_scale (detection_threshold_adjustment)
-       , detection_threshold_label (_("Threshold"))
        , sensitivity_adjustment (40, 0, 100, 1, 10)
        , sensitivity_scale (sensitivity_adjustment)
-       , sensitivity_label (_("Sensitivity"))
        , analyze_button (_("Analyze"))
-       , onset_function_label (_("Detection function"))
        , peak_picker_threshold_adjustment (0.3, 0.0, 1.0, 0.01, 0.1)
        , peak_picker_threshold_scale (peak_picker_threshold_adjustment)
-       , peak_picker_label (_("Peak Threshold"))
        , silence_threshold_adjustment (-90.0, -120.0, 0.0, 1, 10)
        , silence_threshold_scale (silence_threshold_adjustment)
-       , silence_label (_("Silent Threshold (dB)"))
        , trigger_gap_adjustment (3, 0, 100, 1, 10)
        , trigger_gap_spinner (trigger_gap_adjustment)
-       , trigger_gap_label (_("Trigger gap (msecs)"))
        , action_button (Stock::APPLY)
-
 {
-       upper_hpacker.set_spacing (6);
-
-       upper_hpacker.pack_start (ferret_frame, true, true);
-       upper_hpacker.pack_start (selection_frame, true, true);
-       upper_hpacker.pack_start (operation_frame, true, true);
-
-       op_packer.pack_start (region_split_button, false, false);
-       op_packer.pack_start (tempo_button, false, false);
-       op_packer.pack_start (region_conform_button, false, false);
-
-       operation_frame.add (op_packer);
-
-       HBox* box;
-
-       ferret_packer.set_spacing (6);
-       ferret_packer.set_border_width (6);
-
-       vector<string> strings;
+       operation_strings = I18N (_operation_strings);
+       Gtkmm2ext::set_popdown_strings (operation_selector, operation_strings);
+       operation_selector.set_active (0);
 
        analysis_mode_strings = I18N (_analysis_mode_strings);
        Gtkmm2ext::set_popdown_strings (analysis_mode_selector, analysis_mode_strings);
@@ -108,100 +85,71 @@ RhythmFerret::RhythmFerret (PublicEditor& e)
         */
        onset_detection_function_selector.set_active_text (onset_function_strings[3]);
 
-       box = manage (new HBox);
-       box->set_spacing (6);
-       box->pack_start (analysis_mode_label, false, false);
-       box->pack_start (analysis_mode_selector, true, true);
-       ferret_packer.pack_start (*box, false, false);
+       Table* t = manage (new Table (7, 3));
+       t->set_spacings (12);
 
-       ferret_packer.pack_start (analysis_packer, false, false);
+       int n = 0;
 
-       box = manage (new HBox);
-       box->set_spacing (6);
-       box->pack_start (trigger_gap_label, false, false);
-       box->pack_start (trigger_gap_spinner, false, false);
-       ferret_packer.pack_start (*box, false, false);
+       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;
 
-       ferret_packer.pack_start (analyze_button, false, false);
+       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;
 
-       analyze_button.signal_clicked().connect (sigc::mem_fun (*this, &RhythmFerret::run_analysis));
+       t->attach (*manage (new Label (_("Trigger gap"), 1, 0.5)), 0, 1, n, n + 1, FILL);
+       t->attach (trigger_gap_spinner, 1, 2, n, n + 1, FILL);
+       t->attach (*manage (new Label (_("ms"))), 2, 3, n, n + 1, FILL);
+       ++n;
 
-       box = manage (new HBox);
-       box->set_spacing (6);
-       box->pack_start (detection_threshold_label, false, false);
-       box->pack_start (detection_threshold_scale, true, true);
-       perc_onset_packer.pack_start (*box, false, false);
-
-       box = manage (new HBox);
-       box->set_spacing (6);
-       box->pack_start (sensitivity_label, false, false);
-       box->pack_start (sensitivity_scale, true, true);
-       perc_onset_packer.pack_start (*box, false, false);
-
-       box = manage (new HBox);
-       box->set_spacing (6);
-       box->pack_start (onset_function_label, false, false);
-       box->pack_start (onset_detection_function_selector, true, true);
-       note_onset_packer.pack_start (*box, false, false);
-
-       box = manage (new HBox);
-       box->set_spacing (6);
-       box->pack_start (peak_picker_label, false, false);
-       box->pack_start (peak_picker_threshold_scale, true, true);
-       note_onset_packer.pack_start (*box, false, false);
-
-       box = manage (new HBox);
-       box->set_spacing (6);
-       box->pack_start (silence_label, false, false);
-       box->pack_start (silence_threshold_scale, true, true);
-       note_onset_packer.pack_start (*box, false, false);
+       t->attach (*manage (new Label (_("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;
 
-       analysis_mode_changed ();
-
-       ferret_frame.add (ferret_packer);
+       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);
+       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);
+       ++n;
 
-       logo = manage (new Gtk::Image (::get_icon (X_("ferret_02"))));
+       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;
 
-       if (logo) {
-               lower_hpacker.pack_start (*logo, false, false);
-       }
-
-       lower_hpacker.pack_start (operation_clarification_label, true, true);
-       lower_hpacker.pack_start (action_button, false, false);
-       lower_hpacker.set_border_width (6);
-       lower_hpacker.set_spacing (6);
+       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;
 
+       analyze_button.signal_clicked().connect (sigc::mem_fun (*this, &RhythmFerret::run_analysis));
        action_button.signal_clicked().connect (sigc::mem_fun (*this, &RhythmFerret::do_action));
 
        get_vbox()->set_border_width (6);
        get_vbox()->set_spacing (6);
-       get_vbox()->pack_start (upper_hpacker, true, true);
-       get_vbox()->pack_start (lower_hpacker, false, false);
+       get_vbox()->pack_start (*t);
 
-       show_all ();
-}
+       add_action_widget (analyze_button, 1);
+       add_action_widget (action_button, 0);
 
-RhythmFerret::~RhythmFerret()
-{
-       delete logo;
+       show_all ();
+       analysis_mode_changed ();
 }
 
 void
 RhythmFerret::analysis_mode_changed ()
 {
-       analysis_packer.children().clear ();
-
-       switch (get_analysis_mode()) {
-       case PercussionOnset:
-               analysis_packer.pack_start (perc_onset_packer);
-               break;
-
-       case NoteOnset:
-               analysis_packer.pack_start (note_onset_packer);
-               break;
-       }
-
-       analysis_packer.show_all ();
+       bool const perc = get_analysis_mode() == PercussionOnset;
+       
+       detection_threshold_scale.set_sensitive (perc);
+       sensitivity_scale.set_sensitive (perc);
+       onset_detection_function_selector.set_sensitive (!perc);
+       peak_picker_threshold_scale.set_sensitive (!perc);
+       silence_threshold_scale.set_sensitive (!perc);
 }
 
 RhythmFerret::AnalysisMode
@@ -219,9 +167,9 @@ RhythmFerret::get_analysis_mode () const
 RhythmFerret::Action
 RhythmFerret::get_action () const
 {
-       if (tempo_button.get_active()) {
-               return DefineTempoMap;
-       } else if (region_conform_button.get_active()) {
+       if (operation_selector.get_active_row_number() == 1) {
+               return SnapRegionsToGrid;
+       } else if (operation_selector.get_active_row_number() == 2) {
                return ConformRegion;
        }
 
@@ -235,15 +183,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());
 
@@ -257,17 +207,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());
 
@@ -285,9 +232,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 */
 
@@ -320,7 +267,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());
@@ -341,9 +288,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 */
 
@@ -366,7 +313,7 @@ RhythmFerret::run_note_onset_analysis (boost::shared_ptr<Readable> readable, nfr
 void
 RhythmFerret::do_action ()
 {
-       if (!_session || current_results.empty()) {
+       if (!_session) {
                return;
        }
 
@@ -374,7 +321,12 @@ RhythmFerret::do_action ()
        case SplitRegion:
                do_split_action ();
                break;
-
+       case SnapRegionsToGrid:
+               editor.snap_regions_to_grid();
+               break;
+       case ConformRegion:
+               editor.close_region_gaps();
+               break;
        default:
                break;
        }
@@ -383,15 +335,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);
-
+       /* 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;
        }
 
        _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(); ) {
 
@@ -400,9 +368,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, true);
 
                /* i is invalid at this point */
 
@@ -419,15 +387,21 @@ RhythmFerret::set_session (Session* s)
        current_results.clear ();
 }
 
-static void hide_time_axis_features (TimeAxisView& tav)
+void
+RhythmFerret::on_hide ()
 {
-       tav.hide_feature_lines ();
+       ArdourDialog::on_hide ();
+       clear_transients ();
 }
 
+/* Clear any transients that we have added */
 void
-RhythmFerret::on_hide ()
+RhythmFerret::clear_transients ()
 {
-       editor.foreach_time_axis_view (sigc::ptr_fun (hide_time_axis_features));
-       ArdourDialog::on_hide ();
+       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 ();
 }