summaryrefslogtreecommitdiff
path: root/gtk2_ardour/midi_channel_selector.cc
blob: 327b9d74ae5a9574aee265b0a73c555d6d2ceb43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "midi_channel_selector.h"
#include <sstream>

using namespace std;

MidiChannelSelector::MidiChannelSelector() :
	Gtk::Table(4,4,true)
{
	property_column_spacing() = 0;
	property_row_spacing() = 0;
	
	uint8_t channel_nr = 0;
	for(int row = 0; row < 4; ++row) {
		for(int column = 0; column < 4; ++column) {
			ostringstream channel;
			channel << int(++channel_nr);
			_button_labels[row][column].set_text(channel.str());
			_button_labels[row][column].set_justify(Gtk::JUSTIFY_RIGHT);
			_buttons[row][column].add(_button_labels[row][column]);
			_buttons[row][column].signal_toggled().connect(
				sigc::bind(
					sigc::mem_fun(this, &MidiChannelSelector::button_toggled),
					&_buttons[row][column],
					channel_nr - 1));
			attach(_buttons[row][column], column, column + 1, row, row + 1);
		}
	}
}

MidiChannelSelector::~MidiChannelSelector()
{
}

SingleMidiChannelSelector::SingleMidiChannelSelector(uint8_t active_channel)
	: MidiChannelSelector()
{
	_active_button = 0;
	Gtk::ToggleButton *button = &_buttons[active_channel / 4][active_channel % 4];
	button->set_active(true);
	_active_button = button;
	_active_channel = active_channel;
}

void
SingleMidiChannelSelector::button_toggled(Gtk::ToggleButton *button, uint8_t channel)
{
	if(button->get_active()) {
		if(_active_button) {
			_active_button->set_active(false);
		}
		_active_button = button;
		_active_channel = channel;
		channel_selected.emit(channel);
	} 
}

void
MidiMultipleChannelSelector::button_toggled(Gtk::ToggleButton *button, uint8_t channel)
{
	if(button->get_active()) {
		_selected_channels.insert(channel);
	} else {
		_selected_channels.erase(channel);
	}
}