Merge branch 'patches' of https://github.com/jdekozak/ardour
[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/button.h"
29 #include "gtkmm/radiobutton.h"
30 #include "gtkmm/label.h"
31 #include "gtkmm2ext/stateful_button.h"
32
33 #include "ardour/types.h"
34
35 #include "ardour_window.h"
36
37 namespace ARDOUR {
38         class MidiTrack;
39 }
40
41 class MidiChannelSelector : public Gtk::Table
42 {
43   public:
44     MidiChannelSelector(int n_rows = 4, int n_columns = 4, int start_row = 0, int start_column = 0);
45     virtual ~MidiChannelSelector() = 0;
46
47     sigc::signal<void> clicked;
48
49     void set_channel_colors(const uint32_t new_channel_colors[16]);
50     void set_default_channel_color();
51
52   protected:
53     virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr) = 0;
54     Gtk::Label                      _button_labels[4][4];
55     Gtkmm2ext::StatefulToggleButton _buttons[4][4];
56     int                             _recursion_counter;
57
58     bool              was_clicked (GdkEventButton*);
59 };
60
61 class SingleMidiChannelSelector : public MidiChannelSelector
62 {
63   public:
64     SingleMidiChannelSelector(uint8_t active_channel = 0);
65
66     uint8_t get_active_channel() const { return _active_channel; }
67
68     sigc::signal<void, uint8_t> channel_selected;
69
70   protected:
71     virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
72
73     Gtk::ToggleButton* _last_active_button;
74     uint8_t            _active_channel;
75 };
76
77 class MidiMultipleChannelSelector : public MidiChannelSelector
78 {
79   public:
80     MidiMultipleChannelSelector(ARDOUR::ChannelMode mode = ARDOUR::FilterChannels,
81                                 uint16_t initial_selection = 0xFFFF);
82
83     virtual ~MidiMultipleChannelSelector();
84
85     /** The channel mode or selected channel(s) has changed.
86      *  First parameter is the new channel mode, second parameter is a bitmask
87      *  of the currently selected channels.
88      */
89     sigc::signal<void, ARDOUR::ChannelMode, uint16_t> mode_changed;
90
91     void set_channel_mode(ARDOUR::ChannelMode mode, uint16_t mask);
92     ARDOUR::ChannelMode get_channel_mode () const { return _channel_mode; }
93
94     /**
95      * @return each bit in the returned word represents a midi channel, eg.
96      *         bit 0 represents channel 0 and bit 15 represents channel 15
97      *
98      */
99     uint16_t get_selected_channels() const;
100     void     set_selected_channels(uint16_t selected_channels);
101
102   protected:
103     ARDOUR::ChannelMode _channel_mode;
104     ARDOUR::NoteMode    _note_mode;
105
106     virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
107     void force_channels_button_toggled();
108
109     void select_all(bool on);
110     void invert_selection(void);
111
112     Gtk::Button       _select_all;
113     Gtk::Button       _select_none;
114     Gtk::Button       _invert_selection;
115     Gtk::ToggleButton _force_channel;
116 };
117
118 class MidiChannelSelectorWindow : public ArdourWindow, public PBD::ScopedConnectionList
119 {
120   public:
121     MidiChannelSelectorWindow (boost::shared_ptr<ARDOUR::MidiTrack>);
122     ~MidiChannelSelectorWindow ();
123
124     void set_channel_colors (const uint32_t new_channel_colors[16]);
125     void set_default_channel_color();
126
127   private:
128     boost::shared_ptr<ARDOUR::MidiTrack> track;
129     std::vector<Gtk::ToggleButton*> playback_buttons;
130     std::vector<Gtk::ToggleButton*> capture_buttons;
131
132     std::vector<Gtk::Widget*> playback_mask_controls;
133     std::vector<Gtk::Widget*> capture_mask_controls;
134
135     Gtk::HBox         capture_mask_box;
136     Gtk::HBox         playback_mask_box;
137     Gtk::RadioButtonGroup playback_button_group;
138     Gtk::RadioButton playback_all_button;
139     Gtk::RadioButton playback_filter_button;
140     Gtk::RadioButton playback_force_button;
141     Gtk::RadioButtonGroup capture_button_group;
142     Gtk::RadioButton capture_all_button;
143     Gtk::RadioButton capture_filter_button;
144     Gtk::RadioButton capture_force_button;
145
146     ARDOUR::ChannelMode last_drawn_capture_mode;
147     ARDOUR::ChannelMode last_drawn_playback_mode;
148
149     void build();
150     void set_capture_selected_channels (uint16_t);
151     void set_playback_selected_channels (uint16_t);
152
153     void fill_playback_mask ();
154     void zero_playback_mask ();
155     void invert_playback_mask ();
156
157     void fill_capture_mask ();
158     void zero_capture_mask ();
159     void invert_capture_mask ();
160
161     void playback_mask_changed ();
162     void capture_mask_changed ();
163     void playback_mode_changed ();
164     void capture_mode_changed ();
165
166     void playback_channel_clicked (uint16_t);
167     void capture_channel_clicked (uint16_t);
168
169     void playback_all_clicked();
170     void playback_none_clicked();
171     void playback_invert_clicked();
172
173     void capture_all_clicked();
174     void capture_none_clicked();
175     void capture_invert_clicked();
176
177     void capture_mode_toggled (ARDOUR::ChannelMode);
178     void playback_mode_toggled (ARDOUR::ChannelMode);
179 };
180
181 #endif /*__ardour_ui_midi_channel_selector_h__*/