* first working version of editing MIDI channels of individual notes, see: http:...
[ardour.git] / gtk2_ardour / midi_channel_selector.cc
1 #include "midi_channel_selector.h"
2 #include <sstream>
3
4 using namespace std;
5
6 MidiChannelSelector::MidiChannelSelector() :
7         Gtk::Table(4,4,true)
8 {
9         property_column_spacing() = 0;
10         property_row_spacing() = 0;
11         
12         uint8_t channel_nr = 0;
13         for(int row = 0; row < 4; ++row) {
14                 for(int column = 0; column < 4; ++column) {
15                         ostringstream channel;
16                         channel << int(++channel_nr);
17                         _button_labels[row][column].set_text(channel.str());
18                         _button_labels[row][column].set_justify(Gtk::JUSTIFY_RIGHT);
19                         _buttons[row][column].add(_button_labels[row][column]);
20                         _buttons[row][column].signal_toggled().connect(
21                                 sigc::bind(
22                                         sigc::mem_fun(this, &MidiChannelSelector::button_toggled),
23                                         &_buttons[row][column],
24                                         channel_nr - 1));
25                         attach(_buttons[row][column], column, column + 1, row, row + 1);
26                 }
27         }
28 }
29
30 MidiChannelSelector::~MidiChannelSelector()
31 {
32 }
33
34 SingleMidiChannelSelector::SingleMidiChannelSelector(uint8_t active_channel)
35         : MidiChannelSelector()
36 {
37         _active_button = 0;
38         Gtk::ToggleButton *button = &_buttons[active_channel / 4][active_channel % 4];
39         button->set_active(true);
40         _active_button = button;
41         _active_channel = active_channel;
42 }
43
44 void
45 SingleMidiChannelSelector::button_toggled(Gtk::ToggleButton *button, uint8_t channel)
46 {
47         if(button->get_active()) {
48                 if(_active_button) {
49                         _active_button->set_active(false);
50                 }
51                 _active_button = button;
52                 _active_channel = channel;
53                 channel_selected.emit(channel);
54         } 
55 }
56
57 void
58 MidiMultipleChannelSelector::button_toggled(Gtk::ToggleButton *button, uint8_t channel)
59 {
60         if(button->get_active()) {
61                 _selected_channels.insert(channel);
62         } else {
63                 _selected_channels.erase(channel);
64         }
65 }