Optimize automation-event process splitting
[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 #include "midi++/midnam_patch.h"
28
29 #include "ardour/route.h"
30
31 #include "widgets/ardour_button.h"
32 #include "widgets/ardour_dropdown.h"
33
34 #include "ardour_dialog.h"
35 #include "gtk_pianokeyboard.h"
36
37 class PatchChangeWidget : public Gtk::VBox
38 {
39 public:
40         PatchChangeWidget (boost::shared_ptr<ARDOUR::Route>);
41         ~PatchChangeWidget ();
42
43         void refresh ();
44
45 protected:
46         int bank (uint8_t) const;
47         uint8_t program (uint8_t) const;
48
49         void on_show ();
50         void on_hide ();
51
52 private:
53         boost::shared_ptr<ARDOUR::Route> _route;
54
55         ArdourWidgets::ArdourDropdown _channel_select;
56         ArdourWidgets::ArdourDropdown _bank_select;
57         Gtk::SpinButton               _bank_msb_spin;
58         Gtk::SpinButton               _bank_lsb_spin;
59         ArdourWidgets::ArdourButton   _program_btn[128];
60         Gtk::Table                    _program_table;
61
62         uint8_t _channel;
63         bool    _ignore_spin_btn_signals;
64         bool    _no_notifications;
65
66         void select_channel (uint8_t);
67         void select_bank (uint32_t);
68         void select_bank_spin ();
69         void select_program (uint8_t);
70
71         void bank_changed ();
72         void program_changed ();
73         void bankpatch_changed (uint8_t);
74
75         void refill_banks ();
76         void refill_program_list ();
77
78         void instrument_info_changed ();
79         void processors_changed ();
80
81         PBD::ScopedConnection _info_changed_connection;
82         PBD::ScopedConnection _route_connection;
83         PBD::ScopedConnectionList _ac_connections;
84
85         ARDOUR::InstrumentInfo& _info;
86         boost::shared_ptr<MIDI::Name::PatchBank> _current_patch_bank;
87
88         void audition_toggle ();
89         void check_note_range (bool);
90         void audition ();
91         void cancel_audition ();
92         bool audition_next ();
93         sigc::connection _note_queue_connection;
94
95         ArdourWidgets::ArdourButton _audition_enable;
96         Gtk::SpinButton             _audition_start_spin; // Consider a click-box w/note-names
97         Gtk::SpinButton             _audition_end_spin;
98         Gtk::SpinButton             _audition_velocity;
99         uint8_t                     _audition_note_num;
100         bool                        _audition_note_on;
101
102         PianoKeyboard* _piano;
103         Gtk::Widget*   _pianomm;
104
105         static void _note_on_event_handler (GtkWidget*, int, gpointer);
106         static void _note_off_event_handler (GtkWidget*, int, gpointer);
107         void note_on_event_handler (int, bool for_audition);
108         void note_off_event_handler (int);
109 };
110
111 class PatchChangeGridDialog : public ArdourDialog
112 {
113 public:
114         PatchChangeGridDialog (boost::shared_ptr<ARDOUR::Route>);
115         void on_hide () { w.hide (); ArdourDialog::on_hide (); }
116         void on_show () { w.show (); ArdourDialog::on_show (); }
117         void refresh () { w.refresh (); }
118
119 private:
120         void route_property_changed (const PBD::PropertyChange&, boost::weak_ptr<ARDOUR::Route>);
121         PBD::ScopedConnection _route_connection;
122         PatchChangeWidget w;
123 };
124
125 #endif