Add a PianoKeyboard to GenericUI (on a MIDI track)
[ardour.git] / gtk2_ardour / patch_change_widget.h
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #ifndef __gtkardour_patch_change_widget_h__
20 #define __gtkardour_patch_change_widget_h__
21
22 #include <gtkmm/box.h>
23 #include <gtkmm/spinbutton.h>
24 #include <gtkmm/table.h>
25
26 #include "pbd/signals.h"
27
28 #include "ardour/route.h"
29
30 #include "widgets/ardour_button.h"
31 #include "widgets/ardour_dropdown.h"
32
33 #include "ardour_dialog.h"
34 #include "gtk_pianokeyboard.h"
35
36 class PatchChangeWidget : public Gtk::VBox
37 {
38 public:
39         PatchChangeWidget (boost::shared_ptr<ARDOUR::Route>);
40         ~PatchChangeWidget ();
41
42         void refresh ();
43
44 protected:
45         int bank (uint8_t) const;
46         uint8_t program (uint8_t) const;
47
48         void on_show ();
49         void on_hide ();
50
51 private:
52         boost::shared_ptr<ARDOUR::Route> _route;
53
54         ArdourWidgets::ArdourDropdown _channel_select;
55         ArdourWidgets::ArdourDropdown _bank_select;
56         Gtk::SpinButton               _bank_msb_spin;
57         Gtk::SpinButton               _bank_lsb_spin;
58         ArdourWidgets::ArdourButton   _program_btn[128];
59         Gtk::Table                    _program_table;
60
61         uint8_t _channel;
62         bool    _ignore_spin_btn_signals;
63
64         void select_channel (uint8_t);
65         void select_bank (uint32_t);
66         void select_bank_spin ();
67         void select_program (uint8_t);
68
69         void bank_changed ();
70         void program_changed ();
71
72         void refill_banks ();
73         void refill_program_list ();
74
75         void instrument_info_changed ();
76
77         PBD::ScopedConnection _info_changed_connection;
78         PBD::ScopedConnection _route_connection;
79         PBD::ScopedConnectionList _ac_connections;
80
81         ARDOUR::InstrumentInfo& _info;
82         boost::shared_ptr<MIDI::Name::PatchBank> _current_patch_bank;
83
84         void audition_toggle ();
85         void check_note_range (bool);
86         void audition ();
87         void cancel_audition ();
88         bool audition_next ();
89         sigc::connection _note_queue_connection;
90
91         ArdourWidgets::ArdourButton _audition_enable;
92         Gtk::SpinButton             _audition_start_spin; // Consider a click-box w/note-names
93         Gtk::SpinButton             _audition_end_spin;
94         Gtk::SpinButton             _audition_velocity;
95         uint8_t                     _audition_note_num;
96         bool                        _audition_note_on;
97
98         PianoKeyboard* _piano;
99         Gtk::Widget*   _pianomm;
100
101         static void _note_on_event_handler (GtkWidget*, int, gpointer);
102         static void _note_off_event_handler (GtkWidget*, int, gpointer);
103         void note_on_event_handler (int);
104         void note_off_event_handler (int);
105 };
106
107 class PatchChangeGridDialog : public ArdourDialog
108 {
109 public:
110         PatchChangeGridDialog (boost::shared_ptr<ARDOUR::Route>);
111         void on_hide () { w.hide (); ArdourDialog::on_hide (); }
112         void on_show () { w.show (); ArdourDialog::on_show (); }
113         void refresh () { w.refresh (); }
114
115 private:
116         void route_property_changed (const PBD::PropertyChange&, boost::weak_ptr<ARDOUR::Route>);
117         PBD::ScopedConnection _route_connection;
118         PatchChangeWidget w;
119 };
120
121 #endif