properly track step edit status in editor & mixer windows
[ardour.git] / gtk2_ardour / step_entry.cc
index aa81fead3d36e09900a34fd9bd872b95287d5b4b..18fa5c773093d5a47df778173bd8f73f88151daf 100644 (file)
 
 */
 
+#include <iostream>
+
+#include "gtkmm2ext/keyboard.h"
+
 #include "midi_time_axis.h"
 #include "step_entry.h"
 #include "utils.h"
@@ -31,9 +35,14 @@ _note_off_event_handler (GtkWidget* widget, int note, gpointer arg)
         ((StepEntry*)arg)->note_off_event_handler (note);
 }
 
+static void
+_rest_event_handler (GtkWidget* widget, gpointer arg)
+{
+        ((StepEntry*)arg)->rest_event_handler ();
+}
 
 StepEntry::StepEntry (MidiTimeAxisView& mtv)
-        : ArdourDialog (_("Step Entry Editor"))
+        : ArdourDialog (string_compose (_("Step Entry: %1"), mtv.name()))
         , triplet_button ("3")
         , sustain_button ("sustain")
         , rest_button ("rest")
@@ -166,9 +175,15 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv)
         _piano = (PianoKeyboard*) piano_keyboard_new ();
         piano = Glib::wrap ((GtkWidget*) _piano);
 
-       g_signal_connect(G_OBJECT(_piano), "note-off", G_CALLBACK(_note_off_event_handler), this);
+        piano->set_flags (Gtk::CAN_FOCUS);
+        piano->signal_enter_notify_event().connect (sigc::mem_fun (*this, &StepEntry::piano_enter_notify_event), false);
 
+        g_signal_connect(G_OBJECT(_piano), "note-off", G_CALLBACK(_note_off_event_handler), this);
+        g_signal_connect(G_OBJECT(_piano), "rest", G_CALLBACK(_rest_event_handler), this);
+        
         rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::rest_click));
+        chord_button.signal_toggled().connect (sigc::mem_fun (*this, &StepEntry::chord_toggled));
+        triplet_button.signal_toggled().connect (sigc::mem_fun (*this, &StepEntry::triplet_toggled));
 
         packer.set_spacing (6);
         packer.pack_start (upper_box, false, false);
@@ -182,6 +197,28 @@ StepEntry::~StepEntry()
 {
 }
 
+bool
+StepEntry::on_key_press_event (GdkEventKey* ev)
+{
+        int ret;
+        g_signal_emit_by_name (G_OBJECT(_piano), "key-press-event", ev, &ret);
+        return ret;
+}
+
+bool
+StepEntry::on_key_release_event (GdkEventKey* ev)
+{
+        int ret;
+        g_signal_emit_by_name (G_OBJECT(_piano), "key-release-event", ev, &ret);
+        return ret;
+}
+
+void
+StepEntry::rest_event_handler ()
+{
+        _mtv->step_edit_rest();
+}
+
 void
 StepEntry::note_off_event_handler (int note)
 {
@@ -226,14 +263,11 @@ StepEntry::note_off_event_handler (int note)
                 velocity = 127;
         }
 
-        if (!triplet_button.get_active()) {
-                _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
-        } else {
+        if (_mtv->step_edit_within_triplet()) {
                 length *= 2.0/3.0;
-                _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
-                _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
-                _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
         }
+
+        _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
 }
 
 void
@@ -241,3 +275,27 @@ StepEntry::rest_click ()
 {
         _mtv->step_edit_rest ();
 }
+
+void
+StepEntry::triplet_toggled ()
+{
+        if (triplet_button.get_active () != _mtv->step_edit_within_triplet()) {
+                _mtv->step_edit_toggle_triplet ();
+        }
+}
+
+void
+StepEntry::chord_toggled ()
+{
+        if (chord_button.get_active() != _mtv->step_edit_within_chord ()) {
+                _mtv->step_edit_toggle_chord ();
+        }
+}
+
+bool
+StepEntry::piano_enter_notify_event (GdkEventCrossing *ev)
+{
+        piano->grab_focus ();
+        return false;
+}
+