lots of MIDI editing stuff. to be explained on the website when its done
[ardour.git] / gtk2_ardour / ardour_ui2.cc
index eec94b525f4dd7e82d02be1262848b165048d99e..0394d8be8cd012dc4d8be0c4813198a34182a8a6 100644 (file)
 #include <cmath>
 
 #include <sigc++/bind.h>
-#include <pbd/error.h>
-#include <pbd/basename.h>
-#include <pbd/fastlog.h>
+#include "pbd/error.h"
+#include "pbd/basename.h"
+#include "pbd/fastlog.h"
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/click_box.h>
 #include <gtkmm2ext/tearoff.h>
 
-#include <ardour/audioengine.h>
-#include <ardour/ardour.h>
-#include <ardour/route.h>
+#include "ardour/audioengine.h"
+#include "ardour/ardour.h"
+#include "ardour/profile.h"
+#include "ardour/route.h"
 
 #include "ardour_ui.h"
 #include "keyboard.h"
@@ -42,7 +43,7 @@
 #include "audio_clock.h"
 #include "actions.h"
 #include "utils.h"
-#include "color_manager.h"
+#include "theme_manager.h"
 
 #include "i18n.h"
 
@@ -75,16 +76,56 @@ ARDOUR_UI::setup_windows ()
        setup_transport();
        build_menu_bar ();
 
-       color_manager->signal_unmap().connect (bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleColorManager")));
+       theme_manager->signal_unmap().connect (bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleThemeManager")));
 
-       top_packer.pack_start (menu_bar_base, false, false);
-       top_packer.pack_start (transport_frame, false, false);
+#ifdef TOP_MENUBAR
+       HBox* status_bar_packer = manage (new HBox);
+       
+       status_bar_label.set_size_request (300, -1);
+       status_bar_packer->pack_start (status_bar_label, true, true, 6);
+       status_bar_packer->pack_start (error_log_button, false, false);
+       
+       error_log_button.signal_clicked().connect (mem_fun (*this, &UI::toggle_errors));
+
+       editor->get_status_bar_packer().pack_start (*status_bar_packer, true, true);
+       editor->get_status_bar_packer().pack_start (menu_bar_base, false, false, 6);
+#else
+       top_packer.pack_start (menu_bar_base, false, false);
+#endif 
+
+       top_packer.pack_start (transport_frame, false, false);
 
        editor->add_toplevel_controls (top_packer);
 
        return 0;
 }
 
+ void
+ARDOUR_UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
+{
+       ustring text;
+
+       UI::display_message (prefix, prefix_len, ptag, mtag, msg);
+#ifdef TOP_MENUBAR
+
+       if (strcmp (prefix, _("[ERROR]: ")) == 0) {
+               text = "<span color=\"red\" weight=\"bold\">";
+       } else if (strcmp (prefix, _("[WARNING]: ")) == 0) {
+               text = "<span color=\"yellow\" weight=\"bold\">";
+       } else if (strcmp (prefix, _("[INFO]: ")) == 0) {
+               text = "<span color=\"green\" weight=\"bold\">";
+       } else {
+               text = "<span color=\"white\" weight=\"bold\">???";
+       }
+
+       text += prefix;
+       text += "</span>";
+       text += msg;
+
+       status_bar_label.set_markup (text);
+#endif
+}
+
 void
 ARDOUR_UI::transport_stopped ()
 {
@@ -150,6 +191,11 @@ ARDOUR_UI::setup_transport ()
 {
        transport_tearoff = manage (new TearOff (transport_tearoff_hbox));
        transport_tearoff->set_name ("TransportBase");
+       transport_tearoff->tearoff_window().signal_key_press_event().connect (bind (sigc::ptr_fun (relay_key_press), &transport_tearoff->tearoff_window()), false);
+
+       if (Profile->get_sae()) {
+               transport_tearoff->set_can_be_torn_off (false);
+       }
 
        transport_hbox.pack_start (*transport_tearoff, true, false);
 
@@ -270,11 +316,12 @@ ARDOUR_UI::setup_transport ()
 
        /* clocks, etc. */
 
-       ARDOUR_UI::Clock.connect (bind (mem_fun (primary_clock, &AudioClock::set), false));
-       ARDOUR_UI::Clock.connect (bind (mem_fun (secondary_clock, &AudioClock::set), false));
+       ARDOUR_UI::Clock.connect (bind (mem_fun (primary_clock, &AudioClock::set), 'p'));
+       ARDOUR_UI::Clock.connect (bind (mem_fun (secondary_clock, &AudioClock::set), 's'));
 
        primary_clock.ValueChanged.connect (mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed));
        secondary_clock.ValueChanged.connect (mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed));
+       big_clock.ValueChanged.connect (mem_fun(*this, &ARDOUR_UI::big_clock_value_changed));
 
        ARDOUR_UI::instance()->tooltips().set_tip (primary_clock, _("Primary clock"));
        ARDOUR_UI::instance()->tooltips().set_tip (secondary_clock, _("secondary clock"));
@@ -325,16 +372,17 @@ ARDOUR_UI::setup_transport ()
 
        speed_display_box.add (speed_display_label);
        speed_display_box.set_name (X_("ShuttleDisplay"));
+       set_size_request_to_display_given_text (speed_display_label, X_("> 24.0"), 2, 2);
 
        shuttle_units_button.set_name (X_("ShuttleButton"));
        shuttle_units_button.signal_clicked().connect (mem_fun(*this, &ARDOUR_UI::shuttle_unit_clicked));
        
-       shuttle_style_button.set_name (X_("ShuttleButton"));
+       shuttle_style_button.set_name (X_("ShuttleStyleButton"));
 
        vector<string> shuttle_strings;
        shuttle_strings.push_back (_("sprung"));
        shuttle_strings.push_back (_("wheel"));
-       set_popdown_strings (shuttle_style_button, shuttle_strings);
+       set_popdown_strings (shuttle_style_button, shuttle_strings, true);
        shuttle_style_button.signal_changed().connect (mem_fun (*this, &ARDOUR_UI::shuttle_style_changed));
 
        Frame* sdframe = manage (new Frame);
@@ -344,8 +392,9 @@ ARDOUR_UI::setup_transport ()
 
        mtc_port_changed ();
        sync_option_combo.signal_changed().connect (mem_fun (*this, &ARDOUR_UI::sync_option_changed));
-       const guint32 FUDGE = 25; // Combo's are stupid - they steal space from the entry for the button
-       set_size_request_to_display_given_text (sync_option_combo, X_("Igternal"), 2+FUDGE, 10);
+       // XXX HOW TO USE set_popdown_strings() and combo_fudge with this when we don't know
+       // the real strings till later?
+       set_size_request_to_display_given_text (sync_option_combo, X_("Igternal"), 4+COMBO_FUDGE, 10);
 
        shbox->pack_start (*sdframe, false, false);
        shbox->pack_start (shuttle_units_button, true, true);
@@ -357,20 +406,28 @@ ARDOUR_UI::setup_transport ()
        transport_tearoff_hbox.pack_start (*svbox, false, false, 3);
 
        transport_tearoff_hbox.pack_start (auto_loop_button, false, false);
-       transport_tearoff_hbox.pack_start (play_selection_button, false, false);
+       if (!Profile->get_sae()) {
+               transport_tearoff_hbox.pack_start (play_selection_button, false, false);
+       }
        transport_tearoff_hbox.pack_start (roll_button, false, false);
        transport_tearoff_hbox.pack_start (stop_button, false, false);
        transport_tearoff_hbox.pack_start (rec_button, false, false, 6);
 
        HBox* clock_box = manage (new HBox);
        clock_box->pack_start (primary_clock, false, false);
-       clock_box->pack_start (secondary_clock, false, false);
-       VBox* time_controls_box = manage (new VBox);
-       time_controls_box->pack_start (sync_option_combo, false, false);
-       time_controls_box->pack_start (time_master_button, false, false);
-       clock_box->pack_start (*time_controls_box, false, false, 1);
+       if (!ARDOUR::Profile->get_small_screen()) {
+               clock_box->pack_start (secondary_clock, false, false);
+       }
+
+       if (!Profile->get_sae()) {
+               VBox* time_controls_box = manage (new VBox);
+               time_controls_box->pack_start (sync_option_combo, false, false);
+               time_controls_box->pack_start (time_master_button, false, false);
+               clock_box->pack_start (*time_controls_box, false, false, 1);
+       }
+
        transport_tearoff_hbox.pack_start (*clock_box, false, false, 0);
-       
+
        HBox* toggle_box = manage(new HBox);
        
        VBox* punch_box = manage (new VBox);
@@ -400,6 +457,11 @@ ARDOUR_UI::setup_transport ()
 
        transport_tearoff_hbox.pack_start (*toggle_box, false, false, 4);
        transport_tearoff_hbox.pack_start (alert_box, false, false);
+       
+       if (Profile->get_sae()) {
+               Image* img = manage (new Image ((::get_icon (X_("sae")))));
+               transport_tearoff_hbox.pack_end (*img, false, false, 6);
+       }
 }
 
 void
@@ -603,7 +665,7 @@ ARDOUR_UI::shuttle_box_button_release (GdkEventButton* ev)
                shuttle_grabbed = false;
                shuttle_box.remove_modal_grab ();
                if (Config->get_shuttle_behaviour() == Sprung) {
-                       if (Config->get_auto_play() || roll_button.get_state()) {
+                       if (session->config.get_auto_play() || roll_button.get_visual_state()) {
                                shuttle_fract = SHUTTLE_FRACT_SPEED1;                           
                                session->request_transport_speed (1.0);
                                stop_button.set_visual_state (0);
@@ -629,14 +691,9 @@ ARDOUR_UI::shuttle_box_button_release (GdkEventButton* ev)
                return true;
 
        case 3:
+       default:
                return true;
-               
-       case 4:
-               shuttle_fract += 0.005;
-               break;
-       case 5:
-               shuttle_fract -= 0.005;
-               break;
+
        }
 
        use_shuttle_fract (true);
@@ -706,31 +763,45 @@ ARDOUR_UI::set_shuttle_fract (double f)
 void
 ARDOUR_UI::use_shuttle_fract (bool force)
 {
-       struct timeval now;
-       struct timeval diff;
+       microseconds_t now = get_microseconds();
        
        /* do not attempt to submit a motion-driven transport speed request
           more than once per process cycle.
         */
 
-       gettimeofday (&now, 0);
-       timersub (&now, &last_shuttle_request, &diff);
-
-       if (!force && (diff.tv_usec + (diff.tv_sec * 1000000)) < engine->usecs_per_cycle()) {
+       if (!force && (last_shuttle_request - now) < (microseconds_t) engine->usecs_per_cycle()) {
                return;
        }
        
        last_shuttle_request = now;
 
-       bool neg = (shuttle_fract < 0.0);
+       if (Config->get_shuttle_units() == Semitones) {
+
+               const double step = 1.0 / 24.0; // range is 24 semitones up & down
+               double semitones;
+               double speed;
 
-       double fract = 1 - sqrt (1 - (shuttle_fract * shuttle_fract)); // Formula A1
+               semitones = round (shuttle_fract / step);
+               speed = pow (2.0, (semitones / 12.0));
 
-       if (neg) {
-               fract = -fract;
+               session->request_transport_speed (speed);
+
+       } else {
+
+               bool neg;
+               double fract;
+               
+               neg = (shuttle_fract < 0.0);
+
+               fract = 1 - sqrt (1 - (shuttle_fract * shuttle_fract)); // Formula A1
+
+               if (neg) {
+                       fract = -fract;
+               }
+
+               session->request_transport_speed (shuttle_max_speed * fract);
        }
 
-       session->request_transport_speed (shuttle_max_speed * fract); // Formula A2
        shuttle_box.queue_draw ();
 }
 
@@ -801,10 +872,11 @@ ARDOUR_UI::update_speed_display ()
                        if (Config->get_shuttle_units() == Percentage) {
                                snprintf (buf, sizeof (buf), "%.2f", x);
                        } else {
+
                                if (x < 0) {
-                                       snprintf (buf, sizeof (buf), "< %.1f", 12.0 * fast_log2 (-x));
+                                       snprintf (buf, sizeof (buf), "< %d", (int) round (12.0 * fast_log2 (-x)));
                                } else {
-                                       snprintf (buf, sizeof (buf), "> %.1f", 12.0 * fast_log2 (x));
+                                       snprintf (buf, sizeof (buf), "> %d", (int) round (12.0 * fast_log2 (x)));
                                }
                        }
                        speed_display_label.set_text (buf);
@@ -829,15 +901,17 @@ ARDOUR_UI::editor_realized ()
        Config->map_parameters (mem_fun (*this, &ARDOUR_UI::parameter_changed));
 
        set_size_request_to_display_given_text (speed_display_box, _("-0.55"), 2, 2);
-       const guint32 FUDGE = 25; // Combo's are stupid - they steal space from the entry for the button
-       set_size_request_to_display_given_text (shuttle_style_button, _("sprung"), 2+FUDGE, 10);
+       reset_dpi ();
 }
 
 void
 ARDOUR_UI::sync_option_changed ()
 {
        if (session) {
-               session->request_slave_source (string_to_slave_source (sync_option_combo.get_active_text()));
+               ustring txt = sync_option_combo.get_active_text ();
+               if (txt.length()) {
+                       session->request_slave_source (string_to_slave_source (txt));
+               }
        }
 }