5764a8d813d76c4c2d85a9af46ce9e37129b4b28
[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/label.h"
30 #include "gtkmm2ext/stateful_button.h"
31
32 #include "ardour/types.h"
33
34 class MidiChannelSelector : public Gtk::Table
35 {
36 public:
37         MidiChannelSelector(int n_rows = 4, int n_columns = 4, int start_row = 0, int start_column = 0);
38         virtual ~MidiChannelSelector() = 0;
39
40         sigc::signal<void> clicked;
41
42         void set_channel_colors(const uint32_t new_channel_colors[16]);
43         void set_default_channel_color();
44
45 protected:
46         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr) = 0;
47         Gtk::Label                      _button_labels[4][4];
48         Gtkmm2ext::StatefulToggleButton _buttons[4][4];
49         int                             _recursion_counter;
50
51         bool              was_clicked (GdkEventButton*);
52 };
53
54 class SingleMidiChannelSelector : public MidiChannelSelector
55 {
56 public:
57         SingleMidiChannelSelector(uint8_t active_channel = 0);
58
59         uint8_t get_active_channel() const { return _active_channel; }
60
61         sigc::signal<void, uint8_t> channel_selected;
62
63 protected:
64         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
65
66         Gtk::ToggleButton* _last_active_button;
67         uint8_t            _active_channel;
68 };
69
70 class MidiMultipleChannelSelector : public MidiChannelSelector
71 {
72 public:
73         MidiMultipleChannelSelector(ARDOUR::ChannelMode mode = ARDOUR::FilterChannels,
74                                     uint16_t initial_selection = 0xFFFF);
75
76         virtual ~MidiMultipleChannelSelector();
77
78         /** The channel mode or selected channel(s) has changed.
79          *  First parameter is the new channel mode, second parameter is a bitmask
80          *  of the currently selected channels.
81          */
82         sigc::signal<void, ARDOUR::ChannelMode, uint16_t> mode_changed;
83
84         void set_channel_mode(ARDOUR::ChannelMode mode, uint16_t mask);
85         ARDOUR::ChannelMode get_channel_mode () const { return _channel_mode; }
86
87         /**
88          * @return each bit in the returned word represents a midi channel, eg.
89          *         bit 0 represents channel 0 and bit 15 represents channel 15
90          *
91          */
92         uint16_t get_selected_channels() const;
93         void     set_selected_channels(uint16_t selected_channels);
94
95 protected:
96         ARDOUR::ChannelMode _channel_mode;
97         ARDOUR::NoteMode    _note_mode;
98
99         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
100         void force_channels_button_toggled();
101
102         void select_all(bool on);
103         void invert_selection(void);
104
105         Gtk::Button       _select_all;
106         Gtk::Button       _select_none;
107         Gtk::Button       _invert_selection;
108         Gtk::ToggleButton _force_channel;
109 };
110
111 #endif /*__ardour_ui_midi_channel_selector_h__*/