From 35672fb80a2258b01da60ba9514266b94c1493ff Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 3 Nov 2014 16:37:19 -0500 Subject: Note selector dialog for note controls. --- gtk2_ardour/automation_controller.cc | 30 ++++++++++++++++++++ gtk2_ardour/automation_controller.h | 3 ++ gtk2_ardour/gtk_pianokeyboard.c | 15 ++++++++++ gtk2_ardour/gtk_pianokeyboard.h | 3 ++ gtk2_ardour/note_select_dialog.cc | 55 ++++++++++++++++++++++++++++++++++++ gtk2_ardour/note_select_dialog.h | 41 +++++++++++++++++++++++++++ gtk2_ardour/wscript | 1 + 7 files changed, 148 insertions(+) create mode 100644 gtk2_ardour/note_select_dialog.cc create mode 100644 gtk2_ardour/note_select_dialog.h diff --git a/gtk2_ardour/automation_controller.cc b/gtk2_ardour/automation_controller.cc index c4cc93386f..4fa7f67ccd 100644 --- a/gtk2_ardour/automation_controller.cc +++ b/gtk2_ardour/automation_controller.cc @@ -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 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 () { diff --git a/gtk2_ardour/automation_controller.h b/gtk2_ardour/automation_controller.h index e5799cc519..fcc3904e49 100644 --- a/gtk2_ardour/automation_controller.h +++ b/gtk2_ardour/automation_controller.h @@ -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; diff --git a/gtk2_ardour/gtk_pianokeyboard.c b/gtk2_ardour/gtk_pianokeyboard.c index de12de043b..8917017960 100644 --- a/gtk2_ardour/gtk_pianokeyboard.c +++ b/gtk2_ardour/gtk_pianokeyboard.c @@ -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) { diff --git a/gtk2_ardour/gtk_pianokeyboard.h b/gtk2_ardour/gtk_pianokeyboard.h index f4407fae5f..73b7781dbf 100644 --- a/gtk2_ardour/gtk_pianokeyboard.h +++ b/gtk2_ardour/gtk_pianokeyboard.h @@ -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 index 0000000000..14d45ccf5a --- /dev/null +++ b/gtk2_ardour/note_select_dialog.cc @@ -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 + +#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 index 0000000000..607dbe1506 --- /dev/null +++ b/gtk2_ardour/note_select_dialog.h @@ -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__ */ diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index acdb1eba62..16b1a0a393 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -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', -- cgit v1.2.3