replace ::cast_dynamic() with relevant ActionManager::get_*_action() calls
[ardour.git] / gtk2_ardour / midi_channel_selector.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Hans Baier
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __ardour_ui_midi_channel_selector_h__
21 #define __ardour_ui_midi_channel_selector_h__
22
23 #include <set>
24 #include "boost/shared_ptr.hpp"
25 #include "sigc++/trackable.h"
26
27 #include "gtkmm/table.h"
28 #include "gtkmm/box.h"
29 #include "gtkmm/button.h"
30 #include "gtkmm/radiobutton.h"
31 #include "gtkmm/label.h"
32
33 #include "widgets/stateful_button.h"
34
35 #include "ardour/types.h"
36
37 #include "ardour_window.h"
38
39 namespace ARDOUR {
40         class MidiTrack;
41 }
42
43 class MidiChannelSelector : public Gtk::Table
44 {
45 public:
46         MidiChannelSelector(int n_rows = 4, int n_columns = 4, int start_row = 0, int start_column = 0);
47         virtual ~MidiChannelSelector() = 0;
48
49         sigc::signal<void> clicked;
50
51         void set_channel_colors(const uint32_t new_channel_colors[16]);
52         void set_default_channel_color();
53
54 protected:
55         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr) = 0;
56         Gtk::Label                          _button_labels[4][4];
57         ArdourWidgets::StatefulToggleButton _buttons[4][4];
58         int                                 _recursion_counter;
59
60         bool was_clicked (GdkEventButton*);
61 };
62
63 class SingleMidiChannelSelector : public MidiChannelSelector
64 {
65 public:
66         SingleMidiChannelSelector(uint8_t active_channel = 0);
67
68         uint8_t get_active_channel() const { return _active_channel; }
69
70         sigc::signal<void, uint8_t> channel_selected;
71
72 protected:
73         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
74
75         Gtk::ToggleButton* _last_active_button;
76         uint8_t            _active_channel;
77 };
78
79 class MidiMultipleChannelSelector : public MidiChannelSelector
80 {
81 public:
82         MidiMultipleChannelSelector(ARDOUR::ChannelMode mode = ARDOUR::FilterChannels,
83                         uint16_t initial_selection = 0xFFFF);
84
85         virtual ~MidiMultipleChannelSelector();
86
87         /** The channel mode or selected channel(s) has changed.
88          *  First parameter is the new channel mode, second parameter is a bitmask
89          *  of the currently selected channels.
90          */
91         sigc::signal<void, ARDOUR::ChannelMode, uint16_t> mode_changed;
92
93         void set_channel_mode(ARDOUR::ChannelMode mode, uint16_t mask);
94         ARDOUR::ChannelMode get_channel_mode () const { return _channel_mode; }
95
96         /**
97          * @return each bit in the returned word represents a midi channel, eg.
98          *         bit 0 represents channel 0 and bit 15 represents channel 15
99          *
100          */
101         uint16_t get_selected_channels() const;
102         void     set_selected_channels(uint16_t selected_channels);
103
104 protected:
105         ARDOUR::ChannelMode _channel_mode;
106         ARDOUR::NoteMode    _note_mode;
107
108         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
109         void force_channels_button_toggled();
110
111         void select_all(bool on);
112         void invert_selection(void);
113
114         Gtk::Button       _select_all;
115         Gtk::Button       _select_none;
116         Gtk::Button       _invert_selection;
117         Gtk::ToggleButton _force_channel;
118 };
119
120 class MidiChannelSelectorWindow : public ArdourWindow, public PBD::ScopedConnectionList
121 {
122 public:
123         MidiChannelSelectorWindow (boost::shared_ptr<ARDOUR::MidiTrack>);
124         ~MidiChannelSelectorWindow ();
125
126         void set_channel_colors (const uint32_t new_channel_colors[16]);
127         void set_default_channel_color();
128
129 private:
130         boost::shared_ptr<ARDOUR::MidiTrack> track;
131         std::vector<Gtk::ToggleButton*> playback_buttons;
132         std::vector<Gtk::ToggleButton*> capture_buttons;
133
134         std::vector<Gtk::Widget*> playback_mask_controls;
135         std::vector<Gtk::Widget*> capture_mask_controls;
136
137         Gtk::HBox         capture_mask_box;
138         Gtk::HBox         playback_mask_box;
139         Gtk::RadioButtonGroup playback_button_group;
140         Gtk::RadioButton playback_all_button;
141         Gtk::RadioButton playback_filter_button;
142         Gtk::RadioButton playback_force_button;
143         Gtk::RadioButtonGroup capture_button_group;
144         Gtk::RadioButton capture_all_button;
145         Gtk::RadioButton capture_filter_button;
146         Gtk::RadioButton capture_force_button;
147
148         ARDOUR::ChannelMode last_drawn_capture_mode;
149         ARDOUR::ChannelMode last_drawn_playback_mode;
150
151         void build();
152         void set_capture_selected_channels (uint16_t);
153         void set_playback_selected_channels (uint16_t);
154
155         void fill_playback_mask ();
156         void zero_playback_mask ();
157         void invert_playback_mask ();
158
159         void fill_capture_mask ();
160         void zero_capture_mask ();
161         void invert_capture_mask ();
162
163         void playback_mask_changed ();
164         void capture_mask_changed ();
165         void playback_mode_changed ();
166         void capture_mode_changed ();
167
168         void playback_channel_clicked (uint16_t);
169         void capture_channel_clicked (uint16_t);
170
171         void playback_all_clicked();
172         void playback_none_clicked();
173         void playback_invert_clicked();
174
175         void capture_all_clicked();
176         void capture_none_clicked();
177         void capture_invert_clicked();
178
179         void capture_mode_toggled (ARDOUR::ChannelMode);
180         void playback_mode_toggled (ARDOUR::ChannelMode);
181 };
182
183 #endif /*__ardour_ui_midi_channel_selector_h__*/