Fix editor sizing issue introduced in 4dc65e66
[ardour.git] / gtk2_ardour / midi_channel_selector.cc
index b51584aef50d1a109160a913ce62d22a22e5c31d..d800e846c5262adac398b4fc35a29f3633ce88ab 100644 (file)
@@ -27,6 +27,7 @@
 #include <gtkmm/table.h>
 
 #include "pbd/compose.h"
+#include "pbd/ffs.h"
 
 #include "gtkmm2ext/gtk_ui.h"
 #include "gtkmm2ext/gui_thread.h"
 #include "midi_channel_selector.h"
 #include "rgb_macros.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace Gtk;
 using namespace ARDOUR;
 
 MidiChannelSelector::MidiChannelSelector(int n_rows, int n_columns, int start_row, int start_column)
-       : Table(n_rows, n_columns, true)
+       : Table(std::max(4, std::max(n_rows,    start_row    + 4)),
+               std::max(4, std::max(n_columns, start_column + 4)),
+               true)
        , _recursion_counter(0)
 {
-       n_rows    = std::max(4, n_rows);
-       n_rows    = std::max(4, start_row + 4);
-       n_columns = std::max(4, n_columns);
-       n_columns = std::max(4, start_column + 4);
-
        property_column_spacing() = 0;
        property_row_spacing() = 0;
 
@@ -87,8 +85,8 @@ MidiChannelSelector::~MidiChannelSelector()
 bool
 MidiChannelSelector::was_clicked (GdkEventButton*)
 {
-        clicked ();
-        return false;
+       clicked ();
+       return false;
 }
 
 void
@@ -346,10 +344,10 @@ MidiChannelSelectorWindow::MidiChannelSelectorWindow (boost::shared_ptr<MidiTrac
        playback_mask_changed ();
        capture_mask_changed ();
 
-       track->PlaybackChannelMaskChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&MidiChannelSelectorWindow::playback_mask_changed, this), gui_context());
-       track->PlaybackChannelModeChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&MidiChannelSelectorWindow::playback_mode_changed, this), gui_context());
-       track->CaptureChannelMaskChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&MidiChannelSelectorWindow::capture_mask_changed, this), gui_context());
-       track->CaptureChannelModeChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&MidiChannelSelectorWindow::capture_mode_changed, this), gui_context());
+       track->playback_filter().ChannelMaskChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&MidiChannelSelectorWindow::playback_mask_changed, this), gui_context());
+       track->playback_filter().ChannelModeChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&MidiChannelSelectorWindow::playback_mode_changed, this), gui_context());
+       track->capture_filter().ChannelMaskChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&MidiChannelSelectorWindow::capture_mask_changed, this), gui_context());
+       track->capture_filter().ChannelModeChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&MidiChannelSelectorWindow::capture_mode_changed, this), gui_context());
 }
 
 MidiChannelSelectorWindow::~MidiChannelSelectorWindow()
@@ -362,66 +360,62 @@ MidiChannelSelectorWindow::build ()
        VBox* vpacker;
        HBox* capture_controls;
        HBox* playback_controls;
-        Button* b;
-        Label* l;
+       Button* b;
+       Label* l;
 
-        vpacker = manage (new VBox);
-        vpacker->set_spacing (6);
-        vpacker->set_border_width (12);
+       vpacker = manage (new VBox);
+       vpacker->set_spacing (6);
+       vpacker->set_border_width (12);
 
-       l = manage (new Label (string_compose (("<span size=\"larger\" weight=\"bold\">%1: %2</span>"), _("MIDI Channel Control"), track->name())));
+       l = manage (new Label (string_compose ("<span size=\"large\" weight=\"bold\">%1</span>", _("Inbound"))));
        l->set_use_markup (true);
-       l->set_alignment (0.5, 0.0);
-
        vpacker->pack_start (*l, true, true);
 
-        l = manage (new Label (string_compose ("<span size=\"large\" weight=\"bold\">%1</span>", _("Inbound"))));
-       l->set_use_markup (true);
-        vpacker->pack_start (*l);
-
-
        vpacker->pack_start (capture_all_button);
        capture_all_button.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &MidiChannelSelectorWindow::capture_mode_toggled), AllChannels));
-       
+
        vpacker->pack_start (capture_filter_button);
        capture_filter_button.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &MidiChannelSelectorWindow::capture_mode_toggled), FilterChannels));
-       
+
        vpacker->pack_start (capture_force_button);
        capture_force_button.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &MidiChannelSelectorWindow::capture_mode_toggled), ForceChannel));
 
-        vpacker->pack_start (capture_mask_box);
-       
+       vpacker->pack_start (capture_mask_box);
+
        capture_controls = manage (new HBox);
        capture_controls->set_spacing (6);
 
-        b = manage (new Button (_("All")));
+       b = manage (new Button (_("All")));
        Gtkmm2ext::UI::instance()->set_tip (*b, _("Click to enable recording all channels"));
        capture_controls->pack_start (*b);
        capture_mask_controls.push_back (b);
-       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::fill_capture_mask)); 
-        b = manage (new Button (_("None")));
+       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::fill_capture_mask));
+       b = manage (new Button (_("None")));
        Gtkmm2ext::UI::instance()->set_tip (*b, _("Click to disable recording all channels"));
        capture_controls->pack_start (*b);
        capture_mask_controls.push_back (b);
-       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::zero_capture_mask)); 
-        b = manage (new Button (_("Invert")));
+       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::zero_capture_mask));
+       b = manage (new Button (_("Invert")));
        Gtkmm2ext::UI::instance()->set_tip (*b, _("Click to invert currently selected recording channels"));
        capture_controls->pack_start (*b);
        capture_mask_controls.push_back (b);
-       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::invert_capture_mask)); 
+       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::invert_capture_mask));
 
-        vpacker->pack_start (*capture_controls);
+       vpacker->pack_start (*capture_controls);
 
-        l = manage (new Label (string_compose ("<span size=\"large\" weight=\"bold\">%1</span>", _("Playback"))));
+       Gtk::HSeparator *hseparator2 = manage(new Gtk::HSeparator);
+       vpacker->pack_start (*hseparator2, false, false, 6);
+
+       l = manage (new Label (string_compose ("<span size=\"large\" weight=\"bold\">%1</span>", _("Playback"))));
        l->set_use_markup (true);
-        vpacker->pack_start (*l);
+       vpacker->pack_start (*l);
 
        vpacker->pack_start (playback_all_button);
        playback_all_button.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &MidiChannelSelectorWindow::playback_mode_toggled), AllChannels));
-       
+
        vpacker->pack_start (playback_filter_button);
        playback_filter_button.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &MidiChannelSelectorWindow::playback_mode_toggled), FilterChannels));
-       
+
        vpacker->pack_start (playback_force_button);
        playback_force_button.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &MidiChannelSelectorWindow::playback_mode_toggled), ForceChannel));
 
@@ -430,25 +424,25 @@ MidiChannelSelectorWindow::build ()
        playback_controls = manage (new HBox);
        playback_controls->set_spacing (6);
 
-        b = manage (new Button (_("All")));
+       b = manage (new Button (_("All")));
        Gtkmm2ext::UI::instance()->set_tip (*b, _("Click to enable playback of all channels"));
        playback_controls->pack_start (*b);
        playback_mask_controls.push_back (b);
-       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::fill_playback_mask)); 
-        b = manage (new Button (_("None")));
+       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::fill_playback_mask));
+       b = manage (new Button (_("None")));
        Gtkmm2ext::UI::instance()->set_tip (*b, _("Click to disable playback of all channels"));
        playback_controls->pack_start (*b);
        playback_mask_controls.push_back (b);
-       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::zero_playback_mask)); 
+       b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::zero_playback_mask));
        b = manage (new Button (_("Invert")));
        Gtkmm2ext::UI::instance()->set_tip (*b, _("Click to invert current selected playback channels"));
        playback_controls->pack_start (*b);
        playback_mask_controls.push_back (b);
        b->signal_clicked().connect (sigc::mem_fun (*this, &MidiChannelSelectorWindow::invert_playback_mask));
 
-        vpacker->pack_start (*playback_controls);
+       vpacker->pack_start (*playback_controls);
 
-        add (*vpacker);
+       add (*vpacker);
 }
 
 void
@@ -498,7 +492,7 @@ MidiChannelSelectorWindow::invert_capture_mask ()
                track->set_capture_channel_mask (~track->get_capture_channel_mask());
        }
 }
-               
+
 void
 MidiChannelSelectorWindow::set_playback_selected_channels (uint16_t mask)
 {
@@ -512,7 +506,7 @@ MidiChannelSelectorWindow::set_playback_selected_channels (uint16_t mask)
                        playback_buttons[i]->set_active ((1<<i) & mask);
                }
                break;
-               
+
        case ForceChannel:
                /* only set the lowest set channel in the mask as active */
                for (uint16_t i = 0; i < 16; i++) {
@@ -535,7 +529,7 @@ MidiChannelSelectorWindow::set_capture_selected_channels (uint16_t mask)
                        capture_buttons[i]->set_active ((1<<i) & mask);
                }
                break;
-               
+
        case ForceChannel:
                /* only set the lowest set channel in the mask as active */
                for (uint16_t i = 0; i < 16; i++) {
@@ -607,10 +601,10 @@ MidiChannelSelectorWindow::playback_mode_changed ()
        if (playback_buttons.empty()) {
 
                Gtkmm2ext::container_clear (playback_mask_box);
-               
+
                ToggleButton* tb;
                RadioButtonGroup group;
-               
+
                for (uint32_t n = 0; n < 16; ++n) {
                        char buf[3];
                        snprintf (buf, sizeof (buf), "%d", n+1);
@@ -640,7 +634,7 @@ MidiChannelSelectorWindow::playback_mode_changed ()
                                tb->set_sensitive (false);
                        }
                }
-               
+
                if (mode != ForceChannel) {
                        set_playback_selected_channels (track->get_playback_channel_mask());
                }
@@ -652,6 +646,8 @@ MidiChannelSelectorWindow::playback_mode_changed ()
                }
        }
 
+       playback_mask_changed(); // update buttons
+
        last_drawn_playback_mode = mode;
 }
 
@@ -705,10 +701,10 @@ MidiChannelSelectorWindow::capture_mode_changed ()
        if (capture_buttons.empty()) {
 
                Gtkmm2ext::container_clear (capture_mask_box);
-               
+
                ToggleButton* tb;
                RadioButtonGroup group;
-               
+
                for (uint32_t n = 0; n < 16; ++n) {
                        char buf[3];
                        snprintf (buf, sizeof (buf), "%d", n+1);
@@ -738,10 +734,10 @@ MidiChannelSelectorWindow::capture_mode_changed ()
                                tb->set_sensitive (false);
                        }
                }
-               
+
                if (mode != ForceChannel) {
                        set_capture_selected_channels (track->get_capture_channel_mask());
-               } 
+               }
        }
 
        if (mode == AllChannels) {
@@ -750,6 +746,8 @@ MidiChannelSelectorWindow::capture_mode_changed ()
                }
        }
 
+       capture_mask_changed (); // udpate buttons
+
        last_drawn_capture_mode = mode;
 }
 
@@ -805,7 +803,7 @@ MidiChannelSelectorWindow::capture_mode_toggled (ChannelMode mode)
           so we take action only if the button is active (i.e it is the one
           just clicked on)
        */
-       
+
        switch (mode) {
        case AllChannels:
                if (capture_all_button.get_active()) {
@@ -835,7 +833,7 @@ MidiChannelSelectorWindow::playback_mode_toggled (ChannelMode mode)
           so we take action only if the button is active (i.e it is the one
           just clicked on)
        */
-       
+
        switch (mode) {
        case AllChannels:
                if (playback_all_button.get_active()) {
@@ -862,7 +860,7 @@ MidiChannelSelectorWindow::set_channel_colors (const uint32_t new_channel_colors
 
                char color_normal[8];
                char color_active[8];
-               
+
                snprintf(color_normal, 8, "#%x", UINT_INTERPOLATE(new_channel_colors[n], 0x000000ff, 0.6));
                snprintf(color_active, 8, "#%x", new_channel_colors[n]);