Optimize automation-event process splitting
[ardour.git] / gtk2_ardour / quantize_dialog.cc
index 727f2b0db9251c2b9bf93ba674eac6bacd7404b2..b29e9f32613757e857c899ea163f11ee51034d5b 100644 (file)
 */
 
 #include <gtkmm/stock.h>
+#include <gtkmm/table.h>
 #include "gtkmm2ext/utils.h"
 
 #include "pbd/convert.h"
 #include "quantize_dialog.h"
 #include "public_editor.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace Gtk;
@@ -32,39 +33,50 @@ using namespace Gtkmm2ext;
 using namespace ARDOUR;
 
 static const gchar *_grid_strings[] = {
-       N_("main grid"),
-       N_("Beats/128"),
-       N_("Beats/64"),
-       N_("Beats/32"),
-       N_("Beats/16"),
-       N_("Beats/8"),
-       N_("Beats/4"),
-       N_("Beats/3"),
-       N_("Beats"),
+       N_("Main Grid"),
+       N_("1/4 Note"),
+       N_("1/8 Note"),
+       N_("1/16 Note"),
+       N_("1/32 Note"),
+       N_("1/64 Note"),
+       N_("1/128 Note"),
+       
+       N_("1/3 (8th triplet)"),
+       N_("1/6 (16th triplet)"),
+       N_("1/12 (32nd triplet)"),
+
+       N_("1/5 (8th quintuplet)"),
+       N_("1/10 (16th quintuplet)"),
+       N_("1/20 (32nd quintuplet)"),
+
+       N_("1/7 (8th septuplet)"),
+       N_("1/14 (16th septuplet)"),
+       N_("1/28 (32nd septuplet)"),
+
        0
 };
 
-static const gchar *_type_strings[] = {
-       N_("Grid"),
-       N_("Legato"),
-       N_("Groove"),
+static const int _grid_beats[] = {
+       0,
+       1, 2, 4, 8, 16, 32,
+       3, 6, 12,
+       5, 10, 20,
+       7, 14, 28,
        0
 };
 
 std::vector<std::string> QuantizeDialog::grid_strings;
-std::vector<std::string> QuantizeDialog::type_strings;
 
 QuantizeDialog::QuantizeDialog (PublicEditor& e)
        : ArdourDialog (_("Quantize"), false, false)
        , editor (e)
-       , type_label (_("Quantize Type"))
        , strength_adjustment (100.0, 0.0, 100.0, 1.0, 10.0)
        , strength_spinner (strength_adjustment)
        , strength_label (_("Strength"))
        , swing_adjustment (100.0, -130.0, 130.0, 1.0, 10.0)
        , swing_spinner (swing_adjustment)
        , swing_button (_("Swing"))
-       , threshold_adjustment (0.0, -1920.0, 1920.0, 1.0, 10.0) // XXX MAGIC TICK NUMBER FIX ME
+       , threshold_adjustment (0.0, -Timecode::BBT_Time::ticks_per_beat, Timecode::BBT_Time::ticks_per_beat, 1.0, 10.0)
        , threshold_spinner (threshold_adjustment)
        , threshold_label (_("Threshold (ticks)"))
        , snap_start_button (_("Snap note start"))
@@ -72,7 +84,6 @@ QuantizeDialog::QuantizeDialog (PublicEditor& e)
 {
        if (grid_strings.empty()) {
                grid_strings =  I18N (_grid_strings);
-               type_strings =  I18N (_type_strings);
        }
 
        set_popdown_strings (start_grid_combo, grid_strings);
@@ -80,78 +91,41 @@ QuantizeDialog::QuantizeDialog (PublicEditor& e)
        set_popdown_strings (end_grid_combo, grid_strings);
        end_grid_combo.set_active_text (grid_strings.front());
 
-       set_popdown_strings (type_combo, type_strings);
-       type_combo.set_active_text (type_strings.front());
-
-       get_vbox()->set_border_width (12);
-
-       HBox* hbox;
-
-       hbox = manage (new HBox);
-       hbox->set_spacing (12);
-       hbox->set_border_width (6);
-       hbox->pack_start (type_label);
-       hbox->pack_start (type_combo);
-       hbox->show ();
-       type_label.show ();
-       type_combo.show ();
-       get_vbox()->pack_start (*hbox);
-
-       hbox = manage (new HBox);
-       hbox->set_spacing (12);
-       hbox->set_border_width (6);
-       hbox->pack_start (snap_start_button);
-       hbox->pack_start (start_grid_combo);
-       hbox->show ();
-       snap_start_button.show ();
-       start_grid_combo.show ();
-       get_vbox()->pack_start (*hbox);
-
-       hbox = manage (new HBox);
-       hbox->set_spacing (12);
-       hbox->set_border_width (6);
-       hbox->pack_start (snap_end_button);
-       hbox->pack_start (end_grid_combo);
-       hbox->show ();
-       snap_end_button.show ();
-       end_grid_combo.show ();
-       get_vbox()->pack_start (*hbox);
-
-       hbox = manage (new HBox);
-       hbox->set_spacing (12);
-       hbox->set_border_width (6);
-       hbox->pack_start (threshold_label);
-       hbox->pack_start (threshold_spinner);
-       hbox->show ();
-       threshold_label.show ();
-       threshold_spinner.show ();
-       get_vbox()->pack_start (*hbox);
-
-       hbox = manage (new HBox);
-       hbox->set_spacing (12);
-       hbox->set_border_width (6);
-       hbox->pack_start (strength_label);
-       hbox->pack_start (strength_spinner);
-       hbox->show ();
-       strength_label.show ();
-       strength_spinner.show ();
-       get_vbox()->pack_start (*hbox);
-
-       hbox = manage (new HBox);
-       hbox->set_spacing (12);
-       hbox->set_border_width (6);
-       hbox->pack_start (swing_button);
-       hbox->pack_start (swing_spinner);
-       hbox->show ();
-       swing_button.show ();
-       swing_spinner.show ();
-       get_vbox()->pack_start (*hbox);
+       Table* table = manage (new Table (6, 2));
+       table->set_spacings (12);
+       table->set_border_width (12);
+
+       int r = 0;
+
+       table->attach (snap_start_button, 0, 1, r, r + 1);
+       table->attach (start_grid_combo, 1, 2, r, r + 1);
+       ++r;
+
+       table->attach (snap_end_button, 0, 1, r, r + 1);
+       table->attach (end_grid_combo, 1, 2, r, r + 1);
+       ++r;
+
+       threshold_label.set_alignment (0, 0.5);
+       table->attach (threshold_label, 0, 1, r, r + 1);
+       table->attach (threshold_spinner, 1, 2, r, r + 1);
+       ++r;
+
+       strength_label.set_alignment (0, 0.5);
+       table->attach (strength_label, 0, 1, r, r + 1);
+       table->attach (strength_spinner, 1, 2, r, r + 1);
+       ++r;
+
+       table->attach (swing_button, 0, 1, r, r + 1);
+       table->attach (swing_spinner, 1, 2, r, r + 1);
 
        snap_start_button.set_active (true);
        snap_end_button.set_active (false);
 
+       get_vbox()->pack_start (*table);
+       get_vbox()->show_all ();
+
        add_button (Stock::CANCEL, RESPONSE_CANCEL);
-       add_button (Stock::OK, RESPONSE_OK);
+       add_button (_("Quantize"), RESPONSE_OK);
 }
 
 QuantizeDialog::~QuantizeDialog()
@@ -167,41 +141,33 @@ QuantizeDialog::start_grid_size () const
 double
 QuantizeDialog::end_grid_size () const
 {
-       return grid_size_to_musical_time (start_grid_combo.get_active_text ());
+       return grid_size_to_musical_time (end_grid_combo.get_active_text ());
 }
 
 double
 QuantizeDialog::grid_size_to_musical_time (const string& txt) const
 {
-       if (txt == "main_grid") {
+       if ( txt == _grid_strings[0] ) {  //"Main Grid"
                bool success;
 
-               Evoral::MusicalTime b = editor.get_grid_type_as_beats (success, 0);
+               Temporal::Beats b = editor.get_grid_type_as_beats (success, 0);
                if (!success) {
                        return 1.0;
                }
-               return (double) b;
+               return b.to_double();
        }
 
-       if (txt == _("Beats/128")) {
-               return 1.0/128.0;
-       } else if (txt == _("Beats/64")) {
-               return 1.0/64.0;
-       } else if (txt == _("Beats/32")) {
-               return 1.0/32.0;
-       } else if (txt == _("Beats/16")) {
-               return 1.0/16.0;
-       } if (txt == _("Beats/8")) {
-               return 1.0/8.0;
-       } else if (txt == _("Beats/4")) {
-               return 1.0/4.0;
-       } else if (txt == _("Beats/3")) {
-               return 1.0/3.0;
-       } else if (txt == _("Beats")) {
-               return 1.0;
+
+       double divisor = 1.0;
+       for (size_t i = 1; i < grid_strings.size(); ++i) {
+               if (txt == grid_strings[i]) {
+                       assert (_grid_beats[i] != 0);
+                       divisor = 1.0 / _grid_beats[i];
+                       break;
+               }
        }
 
-       return 1.0;
+       return divisor;
 }
 
 float