Fix various MIDI corruption bugs.
[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 #include "gtkmm/table.h"
27 #include "gtkmm/button.h"
28 #include "gtkmm/togglebutton.h"
29 #include "gtkmm/label.h"
30 #include <ardour/types.h>
31
32
33 class MidiChannelSelector : public Gtk::Table
34 {
35 public:
36         MidiChannelSelector(int no_rows = 4, int no_columns = 4, int start_row = 0, int start_column = 0);
37         virtual ~MidiChannelSelector() = 0;
38         
39         sigc::signal<void, ARDOUR::ChannelMode, uint16_t> mode_changed;
40         
41 protected:
42         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr) = 0;
43         Gtk::Label        _button_labels[4][4];
44         Gtk::ToggleButton _buttons[4][4];
45         int               _recursion_counter;
46 };
47
48 class SingleMidiChannelSelector : public MidiChannelSelector
49 {
50 public:
51         SingleMidiChannelSelector(uint8_t active_channel = 0);
52         
53         const uint8_t get_active_channel() const { return _active_channel; }
54         
55         sigc::signal<void, uint8_t> channel_selected;
56         
57 protected:
58         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
59
60         Gtk::ToggleButton* _last_active_button;
61         uint8_t            _active_channel;
62 };
63
64 class MidiMultipleChannelSelector : public MidiChannelSelector
65 {
66 public:
67         MidiMultipleChannelSelector(ARDOUR::ChannelMode mode = ARDOUR::FilterChannels,
68                                     uint16_t initial_selection = 0xFFFF);
69         
70         virtual ~MidiMultipleChannelSelector();
71         
72         void set_channel_mode(ARDOUR::ChannelMode mode, uint8_t mask);
73
74         /**
75          * @return each bit in the returned word represents a midi channel, eg. 
76          *         bit 0 represents channel 0 and bit 15 represents channel 15
77          *          
78          */
79         const uint16_t get_selected_channels() const;
80         void           set_selected_channels(uint16_t selected_channels);
81         
82 protected:
83         ARDOUR::ChannelMode _channel_mode;
84         ARDOUR::NoteMode    _note_mode;
85         
86         virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
87         void force_channels_button_toggled();
88         
89         void select_all(bool on);
90         void invert_selection(void);
91         
92         Gtk::Button       _select_all;
93         Gtk::Button       _select_none;
94         Gtk::Button       _invert_selection;
95         Gtk::ToggleButton _force_channel;
96 };
97
98 #endif /*__ardour_ui_midi_channel_selector_h__*/