diff --git a/libs/surfaces/push2/buttons.cc b/libs/surfaces/push2/buttons.cc index f4f05562e7..0c443cb1ec 100644 --- a/libs/surfaces/push2/buttons.cc +++ b/libs/surfaces/push2/buttons.cc @@ -593,13 +593,19 @@ Push2::start_press_timeout (Button& button, ButtonID id) void Push2::button_octave_down () { - octave_shift = (max (-4, octave_shift - 1)); - build_pad_table (); + int os = (max (-4, octave_shift - 1)); + if (os != octave_shift) { + octave_shift = os; + build_pad_table (); + } } void Push2::button_octave_up () { - octave_shift = (max (4, octave_shift + 1)); - build_pad_table (); + int os = (min (4, octave_shift + 1)); + if (os != octave_shift) { + octave_shift = os; + build_pad_table (); + } } diff --git a/libs/surfaces/push2/gui.cc b/libs/surfaces/push2/gui.cc index e061bfc2c9..2606418eab 100644 --- a/libs/surfaces/push2/gui.cc +++ b/libs/surfaces/push2/gui.cc @@ -64,14 +64,14 @@ Push2::tear_down_gui () delete w; } } - delete static_cast (gui); + delete gui; gui = 0; } void Push2::build_gui () { - gui = (void*) new P2GUI (*this); + gui = new P2GUI (*this); } /*--------------------*/ @@ -139,6 +139,7 @@ P2GUI::P2GUI (Push2& p) /* catch future changes to connection state */ // p2.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&P2GUI::connection_handler, this), gui_context()); + p2.PadChange.connect (p2_connections, invalidator (*this), boost::bind (&P2GUI::build_pad_table, this), gui_context()); } P2GUI::~P2GUI () @@ -407,14 +408,15 @@ P2GUI::active_port_changed (Gtk::ComboBox* combo, bool for_input) void P2GUI::build_pad_table () { - Gtk::Label* l; + container_clear (pad_table); for (int row = 0; row < 8; ++row) { for (int col = 0; col < 8; ++col) { - l = manage (new Label); - l->set_text (string_compose ("%1", (int) p2.pad_note (row, col))); - l->show (); - pad_table.attach (*l, col, col+1, row, row + 1); + + Gtk::Button* b = manage (new Button (string_compose ("%1", (int) p2.pad_note (row, col)))); + b->show (); + + pad_table.attach (*b, col, col+1, row, row + 1); } } } diff --git a/libs/surfaces/push2/gui.h b/libs/surfaces/push2/gui.h index d4cc98e635..314e8081c6 100644 --- a/libs/surfaces/push2/gui.h +++ b/libs/surfaces/push2/gui.h @@ -44,8 +44,11 @@ public: P2GUI (Push2&); ~P2GUI (); + void build_pad_table (); + private: Push2& p2; + PBD::ScopedConnectionList p2_connections; Gtk::HBox hpacker; Gtk::Table table; Gtk::Table action_table; @@ -91,7 +94,6 @@ private: /* Pads */ Gtk::Table pad_table; - void build_pad_table (); }; } diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index ae814d287a..17890e30c4 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -42,6 +42,7 @@ #include "ardour/tempo.h" #include "push2.h" +#include "gui.h" using namespace ARDOUR; using namespace std; @@ -1596,13 +1597,17 @@ Push2::build_pad_table () { for (int row = 0; row < 8; ++row ) { for (int col = 0; col < 8; ++col) { + /* top left pad sends note number 92 by default */ + int note_number = 92 - (row*8+col); note_number += (octave_shift * 12); note_number = max (0, min (127, note_number)); pad_table[row][col] = note_number; } } + + PadChange (); /* emit signal */ } uint8_t diff --git a/libs/surfaces/push2/push2.h b/libs/surfaces/push2/push2.h index 71c1573c22..467fbe83b7 100644 --- a/libs/surfaces/push2/push2.h +++ b/libs/surfaces/push2/push2.h @@ -64,6 +64,8 @@ public: ~Push2Request () {} }; +class P2GUI; + class Push2 : public ARDOUR::ControlProtocol , public AbstractUI { @@ -88,6 +90,7 @@ class Push2 : public ARDOUR::ControlProtocol boost::shared_ptr output_port(); uint8_t pad_note (int row, int col) const; + PBD::Signal0 PadChange; private: libusb_device_handle *handle; @@ -480,7 +483,7 @@ class Push2 : public ARDOUR::ControlProtocol /* GUI */ - mutable void *gui; + mutable P2GUI* gui; void build_gui (); /* pad mapping */