Note selector dialog for note controls.
authorDavid Robillard <d@drobilla.net>
Mon, 3 Nov 2014 21:37:19 +0000 (16:37 -0500)
committerDavid Robillard <d@drobilla.net>
Mon, 3 Nov 2014 21:37:19 +0000 (16:37 -0500)
gtk2_ardour/automation_controller.cc
gtk2_ardour/automation_controller.h
gtk2_ardour/gtk_pianokeyboard.c
gtk2_ardour/gtk_pianokeyboard.h
gtk2_ardour/note_select_dialog.cc [new file with mode: 0644]
gtk2_ardour/note_select_dialog.h [new file with mode: 0644]
gtk2_ardour/wscript

index c4cc93386f6f98f9982add6d17b7d51502fc33f4..4fa7f67ccdefbb41eb20c9bee55e8e71cf8ba8f8 100644 (file)
@@ -30,6 +30,7 @@
 #include "ardour_ui.h"
 #include "automation_controller.h"
 #include "gui_thread.h"
+#include "note_select_dialog.h"
 
 #include "i18n.h"
 
@@ -52,6 +53,9 @@ AutomationController::AutomationController(boost::shared_ptr<Automatable>
        StartGesture.connect (sigc::mem_fun(*this, &AutomationController::start_touch));
        StopGesture.connect (sigc::mem_fun(*this, &AutomationController::end_touch));
 
+       signal_button_release_event().connect(
+               sigc::mem_fun(*this, &AutomationController::on_button_release));
+
        _adjustment->signal_value_changed().connect (
                        sigc::mem_fun(*this, &AutomationController::value_adjusted));
 
@@ -144,6 +148,32 @@ AutomationController::end_touch ()
        }
 }
 
+void
+AutomationController::run_note_select_dialog()
+{
+       NoteSelectDialog* dialog = new NoteSelectDialog();
+       if (dialog->run() == Gtk::RESPONSE_ACCEPT) {
+               _controllable->set_value(dialog->note_number());
+       }
+       delete dialog;
+}
+
+bool
+AutomationController::on_button_release(GdkEventButton* ev)
+{
+       using namespace Gtk::Menu_Helpers;
+
+       if (ev->button == 3 && _controllable->desc().unit == ARDOUR::ParameterDescriptor::MIDI_NOTE) {
+               Gtk::Menu* menu  = manage(new Menu());
+               MenuList&  items = menu->items();
+               items.push_back(MenuElem(_("Select Note..."),
+                                        sigc::mem_fun(*this, &AutomationController::run_note_select_dialog)));
+               menu->popup(1, ev->time);
+               return true;
+       }
+       return false;
+}
+
 void
 AutomationController::value_changed ()
 {
index e5799cc519d612cc95efa6e0ca5e0c4b2bf26e29..fcc3904e495ef7f98527de40e9aae8c1daba608e 100644 (file)
@@ -71,6 +71,9 @@ private:
        void start_touch();
        void end_touch();
 
+       void run_note_select_dialog();
+       bool on_button_release(GdkEventButton* ev);
+
        void value_changed();
 
        bool                                         _ignore_change;
index de12de043bc5827d112943f7010c9def3e7ff098..8917017960ea0aa94b827b425a3767d2c86ce432 100644 (file)
@@ -155,6 +155,13 @@ press_key(PianoKeyboard *pk, int key)
        else
                pk->notes[key].sustained = 0;
 
+       if (pk->monophonic && pk->last_key != key) {
+               pk->notes[pk->last_key].pressed   = 0;
+               pk->notes[pk->last_key].sustained = 0;
+               queue_note_draw(pk, pk->last_key);
+       }
+       pk->last_key = key;
+
        pk->notes[key].pressed = 1;
 
        g_signal_emit_by_name(GTK_WIDGET(pk), "note-on", key);
@@ -677,6 +684,8 @@ piano_keyboard_new(void)
        pk->enable_keyboard_cue = 0;
        pk->octave = 4;
        pk->note_being_pressed_using_mouse = -1;
+       pk->last_key = 0;
+       pk->monophonic = FALSE;
        memset((void *)pk->notes, 0, sizeof(struct PKNote) * NNOTES);
        pk->key_bindings = g_hash_table_new(g_str_hash, g_str_equal);
        bind_keys_qwerty(pk);
@@ -690,6 +699,12 @@ piano_keyboard_set_keyboard_cue(PianoKeyboard *pk, int enabled)
        pk->enable_keyboard_cue = enabled;
 }
 
+void
+piano_keyboard_set_monophonic(PianoKeyboard *pk, gboolean monophonic)
+{
+       pk->monophonic = monophonic;
+}
+
 void
 piano_keyboard_sustain_press(PianoKeyboard *pk)
 {
index f4407fae5fbae89a4446956f942bd172bc254067..73b7781dbf131f4b0040de27b6850ebc94b3ebb6 100644 (file)
@@ -59,6 +59,8 @@ struct _PianoKeyboard
        int                     octave;
        int                     widget_margin;
        int                     note_being_pressed_using_mouse;
+       int         last_key;
+       gboolean    monophonic;
        volatile struct PKNote  notes[NNOTES];
        /* Table used to translate from PC keyboard character to MIDI note number. */
        GHashTable              *key_bindings;
@@ -76,6 +78,7 @@ void          piano_keyboard_sustain_release  (PianoKeyboard *pk);
 void           piano_keyboard_set_note_on      (PianoKeyboard *pk, int note);
 void           piano_keyboard_set_note_off     (PianoKeyboard *pk, int note);
 void           piano_keyboard_set_keyboard_cue (PianoKeyboard *pk, int enabled);
+void           piano_keyboard_set_monophonic (PianoKeyboard *pk, gboolean monophonic);
 void           piano_keyboard_set_octave (PianoKeyboard *pk, int octave);
 gboolean       piano_keyboard_set_keyboard_layout (PianoKeyboard *pk, const char *layout);
 
diff --git a/gtk2_ardour/note_select_dialog.cc b/gtk2_ardour/note_select_dialog.cc
new file mode 100644 (file)
index 0000000..14d45cc
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+  Copyright (C) 2014 Paul Davis
+  Author: David Robillard
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <gtkmm/stock.h>
+
+#include "note_select_dialog.h"
+
+#include "i18n.h"
+
+static void
+_note_on_event_handler(GtkWidget* /*widget*/, int note, gpointer arg)
+{
+       ((NoteSelectDialog*)arg)->note_on_event_handler(note);
+}
+
+NoteSelectDialog::NoteSelectDialog()
+       : ArdourDialog (_("Select Note"))
+       , _piano((PianoKeyboard*)piano_keyboard_new())
+       , _pianomm(Glib::wrap((GtkWidget*)_piano))
+       , _note_number(60)
+{
+       _pianomm->set_flags(Gtk::CAN_FOCUS);
+       _pianomm->show();
+       g_signal_connect(G_OBJECT(_piano), "note-on", G_CALLBACK(_note_on_event_handler), this);
+       piano_keyboard_set_monophonic(_piano, TRUE);
+       piano_keyboard_sustain_press(_piano);
+
+       get_vbox()->pack_start(*_pianomm);
+       add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+       add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
+       set_default_response(Gtk::RESPONSE_ACCEPT);
+}
+
+void
+NoteSelectDialog::note_on_event_handler(int note)
+{
+       printf("NOTE: %d\n", note);
+       _note_number = note;
+}
diff --git a/gtk2_ardour/note_select_dialog.h b/gtk2_ardour/note_select_dialog.h
new file mode 100644 (file)
index 0000000..607dbe1
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+  Copyright (C) 2014 Paul Davis
+  Author: David Robillard
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __gtk2_ardour_note_select_dialog_h__
+#define __gtk2_ardour_note_select_dialog_h__
+
+#include "ardour_dialog.h"
+#include "gtk_pianokeyboard.h"
+
+class NoteSelectDialog : public ArdourDialog
+{
+public:
+       NoteSelectDialog();
+
+       uint8_t note_number() const { return _note_number; }
+
+       void note_on_event_handler(int note);
+
+private:
+       PianoKeyboard* _piano;
+       Gtk::Widget*   _pianomm;
+       uint8_t        _note_number;
+};
+
+#endif /* __gtk2_ardour_note_select_dialog_h__ */
index acdb1eba62640c8030975589d4981006e10fae20..16b1a0a3930cb8afe96779d634665acba35fbfcf 100644 (file)
@@ -153,6 +153,7 @@ gtk2_ardour_sources = [
         'note.cc',
         'note_base.cc',
         'note_player.cc',
+        'note_select_dialog.cc',
         'nsm.cc',
         'nsmclient.cc',
         'option_editor.cc',