2008-05-11 22:40:48 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2008 Paul Davis
|
|
|
|
Author: Hans Baier
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sstream>
|
2008-04-14 02:23:11 -04:00
|
|
|
#include "midi_channel_selector.h"
|
2008-04-17 06:27:03 -04:00
|
|
|
#include "gtkmm/separator.h"
|
|
|
|
#include "i18n.h"
|
2008-12-25 04:28:57 -05:00
|
|
|
#include "rgb_macros.h"
|
2008-04-14 02:23:11 -04:00
|
|
|
|
|
|
|
using namespace std;
|
2008-04-19 06:30:38 -04:00
|
|
|
using namespace Gtk;
|
|
|
|
using namespace sigc;
|
2008-05-11 22:40:48 -04:00
|
|
|
using namespace ARDOUR;
|
2008-04-14 02:23:11 -04:00
|
|
|
|
2009-02-16 00:13:05 -05:00
|
|
|
MidiChannelSelector::MidiChannelSelector(int n_rows, int n_columns, int start_row, int start_column)
|
|
|
|
: Table(n_rows, n_columns, true)
|
|
|
|
, _recursion_counter(0)
|
2008-04-17 06:27:03 -04:00
|
|
|
{
|
2009-02-16 00:13:05 -05:00
|
|
|
assert(n_rows >= 4);
|
|
|
|
assert(n_rows >= start_row + 4);
|
|
|
|
assert(n_columns >=4);
|
|
|
|
assert(n_columns >= start_column + 4);
|
2008-04-17 06:27:03 -04:00
|
|
|
|
2008-04-14 02:23:11 -04:00
|
|
|
property_column_spacing() = 0;
|
|
|
|
property_row_spacing() = 0;
|
|
|
|
|
|
|
|
uint8_t channel_nr = 0;
|
2008-05-11 22:40:48 -04:00
|
|
|
for (int row = 0; row < 4; ++row) {
|
|
|
|
for (int column = 0; column < 4; ++column) {
|
2008-04-14 02:23:11 -04:00
|
|
|
ostringstream channel;
|
|
|
|
channel << int(++channel_nr);
|
|
|
|
_button_labels[row][column].set_text(channel.str());
|
2008-04-19 06:30:38 -04:00
|
|
|
_button_labels[row][column].set_justify(JUSTIFY_RIGHT);
|
2008-04-14 02:23:11 -04:00
|
|
|
_buttons[row][column].add(_button_labels[row][column]);
|
|
|
|
_buttons[row][column].signal_toggled().connect(
|
2008-04-19 06:30:38 -04:00
|
|
|
bind(
|
|
|
|
mem_fun(this, &MidiChannelSelector::button_toggled),
|
2008-04-14 02:23:11 -04:00
|
|
|
&_buttons[row][column],
|
|
|
|
channel_nr - 1));
|
2008-04-17 06:27:03 -04:00
|
|
|
|
|
|
|
int table_row = start_row + row;
|
|
|
|
int table_column = start_column + column;
|
|
|
|
attach(_buttons[row][column], table_column, table_column + 1, table_row, table_row + 1);
|
2008-04-14 02:23:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MidiChannelSelector::~MidiChannelSelector()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-25 04:28:57 -05:00
|
|
|
void
|
|
|
|
MidiChannelSelector::set_channel_colors(const uint32_t new_channel_colors[16])
|
|
|
|
{
|
|
|
|
for (int row = 0; row < 4; ++row) {
|
|
|
|
for (int column = 0; column < 4; ++column) {
|
|
|
|
char color_normal[8];
|
|
|
|
char color_active[8];
|
|
|
|
snprintf(color_normal, 8, "#%x", UINT_INTERPOLATE(new_channel_colors[row * 4 + column], 0x000000ff, 0.6));
|
|
|
|
snprintf(color_active, 8, "#%x", new_channel_colors[row * 4 + column]);
|
|
|
|
_buttons[row][column].modify_bg(STATE_NORMAL, Gdk::Color(color_normal));
|
|
|
|
_buttons[row][column].modify_bg(STATE_ACTIVE, Gdk::Color(color_active));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiChannelSelector::set_default_channel_color()
|
|
|
|
{
|
|
|
|
for (int row = 0; row < 4; ++row) {
|
|
|
|
for (int column = 0; column < 4; ++column) {
|
|
|
|
_buttons[row][column].unset_bg(STATE_NORMAL);
|
|
|
|
_buttons[row][column].unset_bg(STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 02:23:11 -04:00
|
|
|
SingleMidiChannelSelector::SingleMidiChannelSelector(uint8_t active_channel)
|
|
|
|
: MidiChannelSelector()
|
|
|
|
{
|
2008-04-21 05:39:05 -04:00
|
|
|
_last_active_button = 0;
|
2008-05-11 22:40:48 -04:00
|
|
|
ToggleButton* button = &_buttons[active_channel / 4][active_channel % 4];
|
2008-04-14 02:23:11 -04:00
|
|
|
_active_channel = active_channel;
|
2008-04-21 05:39:05 -04:00
|
|
|
button->set_active(true);
|
|
|
|
_last_active_button = button;
|
2008-04-14 02:23:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-05-11 22:40:48 -04:00
|
|
|
SingleMidiChannelSelector::button_toggled(ToggleButton* button, uint8_t channel)
|
2008-04-21 05:39:05 -04:00
|
|
|
{
|
|
|
|
++_recursion_counter;
|
2008-05-11 22:40:48 -04:00
|
|
|
if (_recursion_counter == 1) {
|
2008-04-21 05:39:05 -04:00
|
|
|
// if the current button is active it must
|
|
|
|
// be different from the first one
|
2008-05-11 22:40:48 -04:00
|
|
|
if (button->get_active()) {
|
|
|
|
if (_last_active_button) {
|
2008-04-21 05:39:05 -04:00
|
|
|
_last_active_button->set_active(false);
|
|
|
|
_active_channel = channel;
|
|
|
|
_last_active_button = button;
|
2008-05-09 07:28:14 -04:00
|
|
|
channel_selected.emit(channel);
|
2008-04-21 05:39:05 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if not, the user pressed the already active button
|
|
|
|
button->set_active(true);
|
|
|
|
_active_channel = channel;
|
2008-04-14 02:23:11 -04:00
|
|
|
}
|
2008-04-21 05:39:05 -04:00
|
|
|
}
|
|
|
|
--_recursion_counter;
|
2008-04-14 02:23:11 -04:00
|
|
|
}
|
|
|
|
|
2008-05-11 22:40:48 -04:00
|
|
|
MidiMultipleChannelSelector::MidiMultipleChannelSelector(ChannelMode mode, uint16_t mask)
|
|
|
|
: MidiChannelSelector(4, 6, 0, 0)
|
|
|
|
, _channel_mode(mode)
|
2008-04-17 06:27:03 -04:00
|
|
|
{
|
2008-04-19 06:30:38 -04:00
|
|
|
_select_all.add(*manage(new Label(_("All"))));
|
2008-04-17 06:27:03 -04:00
|
|
|
_select_all.signal_clicked().connect(
|
2008-04-19 06:30:38 -04:00
|
|
|
bind(mem_fun(this, &MidiMultipleChannelSelector::select_all), true));
|
2008-04-17 06:27:03 -04:00
|
|
|
|
2008-04-19 06:30:38 -04:00
|
|
|
_select_none.add(*manage(new Label(_("None"))));
|
2008-04-17 06:27:03 -04:00
|
|
|
_select_none.signal_clicked().connect(
|
2008-04-19 06:30:38 -04:00
|
|
|
bind(mem_fun(this, &MidiMultipleChannelSelector::select_all), false));
|
2008-04-17 06:27:03 -04:00
|
|
|
|
2008-04-19 06:30:38 -04:00
|
|
|
_invert_selection.add(*manage(new Label(_("Invert"))));
|
2008-04-17 06:27:03 -04:00
|
|
|
_invert_selection.signal_clicked().connect(
|
2008-04-19 06:30:38 -04:00
|
|
|
mem_fun(this, &MidiMultipleChannelSelector::invert_selection));
|
|
|
|
|
|
|
|
_force_channel.add(*manage(new Label(_("Force"))));
|
2008-04-21 05:39:05 -04:00
|
|
|
_force_channel.signal_toggled().connect(
|
|
|
|
mem_fun(this, &MidiMultipleChannelSelector::force_channels_button_toggled));
|
2008-04-17 06:27:03 -04:00
|
|
|
|
|
|
|
set_homogeneous(false);
|
2008-04-19 06:30:38 -04:00
|
|
|
attach(*manage(new VSeparator()), 4, 5, 0, 4, SHRINK, FILL, 0, 0);
|
|
|
|
//set_row_spacing(4, -5);
|
|
|
|
attach(_select_all, 5, 6, 0, 1);
|
|
|
|
attach(_select_none, 5, 6, 1, 2);
|
|
|
|
attach(_invert_selection, 5, 6, 2, 3);
|
|
|
|
attach(_force_channel, 5, 6, 3, 4);
|
2008-04-17 06:27:03 -04:00
|
|
|
|
2008-05-11 22:40:48 -04:00
|
|
|
set_selected_channels(mask);
|
2008-04-21 05:39:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MidiMultipleChannelSelector::~MidiMultipleChannelSelector()
|
|
|
|
{
|
2008-05-11 22:40:48 -04:00
|
|
|
mode_changed.clear();
|
2008-04-21 05:39:05 -04:00
|
|
|
}
|
|
|
|
|
2008-05-11 22:40:48 -04:00
|
|
|
void
|
2008-12-28 19:19:18 -05:00
|
|
|
MidiMultipleChannelSelector::set_channel_mode(ChannelMode mode, uint16_t mask)
|
2008-04-21 05:39:05 -04:00
|
|
|
{
|
2008-05-11 22:40:48 -04:00
|
|
|
switch (mode) {
|
|
|
|
case AllChannels:
|
|
|
|
_force_channel.set_active(false);
|
|
|
|
set_selected_channels(0xFFFF);
|
|
|
|
break;
|
|
|
|
case FilterChannels:
|
|
|
|
_force_channel.set_active(false);
|
|
|
|
set_selected_channels(mask);
|
|
|
|
break;
|
|
|
|
case ForceChannel:
|
|
|
|
_force_channel.set_active(true);
|
|
|
|
for (uint16_t i = 0; i < 16; i++) {
|
|
|
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
|
|
|
button->set_active(i == mask);
|
2008-04-21 05:39:05 -04:00
|
|
|
}
|
2008-04-21 11:10:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
uint16_t
|
2008-04-21 05:39:05 -04:00
|
|
|
MidiMultipleChannelSelector::get_selected_channels() const
|
|
|
|
{
|
|
|
|
uint16_t selected_channels = 0;
|
2008-05-11 22:40:48 -04:00
|
|
|
for (uint16_t i = 0; i < 16; i++) {
|
|
|
|
const ToggleButton* button = &_buttons[i / 4][i % 4];
|
|
|
|
if (button->get_active()) {
|
2008-04-21 05:39:05 -04:00
|
|
|
selected_channels |= (1L << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return selected_channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiMultipleChannelSelector::set_selected_channels(uint16_t selected_channels)
|
|
|
|
{
|
2008-05-11 22:40:48 -04:00
|
|
|
for (uint16_t i = 0; i < 16; i++) {
|
|
|
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
|
|
|
if (selected_channels & (1L << i)) {
|
2008-04-17 06:27:03 -04:00
|
|
|
button->set_active(true);
|
|
|
|
} else {
|
|
|
|
button->set_active(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 02:23:11 -04:00
|
|
|
void
|
2008-04-19 06:30:38 -04:00
|
|
|
MidiMultipleChannelSelector::button_toggled(ToggleButton *button, uint8_t channel)
|
2008-04-14 02:23:11 -04:00
|
|
|
{
|
2008-04-21 05:39:05 -04:00
|
|
|
++_recursion_counter;
|
2008-05-11 22:40:48 -04:00
|
|
|
if (_recursion_counter == 1) {
|
|
|
|
if (_channel_mode == ForceChannel) {
|
|
|
|
mode_changed.emit(_channel_mode, channel);
|
2008-04-21 05:39:05 -04:00
|
|
|
set_selected_channels(1 << channel);
|
2008-05-11 22:40:48 -04:00
|
|
|
} else {
|
|
|
|
mode_changed.emit(_channel_mode, get_selected_channels());
|
2008-04-21 05:39:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--_recursion_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiMultipleChannelSelector::force_channels_button_toggled()
|
|
|
|
{
|
2008-05-11 22:40:48 -04:00
|
|
|
if (_force_channel.get_active()) {
|
|
|
|
_channel_mode = ForceChannel;
|
2008-04-21 05:39:05 -04:00
|
|
|
bool found_first_active = false;
|
|
|
|
// leave only the first button enabled
|
2008-05-11 22:40:48 -04:00
|
|
|
uint16_t active_channel = 0;
|
|
|
|
for (int i = 0; i <= 15; i++) {
|
|
|
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
|
|
|
if (button->get_active()) {
|
|
|
|
if (found_first_active) {
|
2008-04-21 05:39:05 -04:00
|
|
|
++_recursion_counter;
|
|
|
|
button->set_active(false);
|
|
|
|
--_recursion_counter;
|
|
|
|
} else {
|
|
|
|
found_first_active = true;
|
2008-05-11 22:40:48 -04:00
|
|
|
active_channel = i;
|
2008-04-21 05:39:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-11 22:40:48 -04:00
|
|
|
if (!found_first_active) {
|
2008-04-21 05:39:05 -04:00
|
|
|
_buttons[0][0].set_active(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
_select_all.set_sensitive(false);
|
|
|
|
_select_none.set_sensitive(false);
|
|
|
|
_invert_selection.set_sensitive(false);
|
2008-05-11 22:40:48 -04:00
|
|
|
mode_changed.emit(_channel_mode, active_channel);
|
2008-04-21 05:39:05 -04:00
|
|
|
} else {
|
2008-05-11 22:40:48 -04:00
|
|
|
_channel_mode = FilterChannels;
|
2008-04-21 05:39:05 -04:00
|
|
|
_select_all.set_sensitive(true);
|
|
|
|
_select_none.set_sensitive(true);
|
|
|
|
_invert_selection.set_sensitive(true);
|
2008-05-11 22:40:48 -04:00
|
|
|
mode_changed.emit(FilterChannels, get_selected_channels());
|
2008-04-21 05:39:05 -04:00
|
|
|
}
|
2008-04-17 06:27:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiMultipleChannelSelector::select_all(bool on)
|
|
|
|
{
|
2008-05-11 22:40:48 -04:00
|
|
|
if (_channel_mode == ForceChannel)
|
|
|
|
return;
|
|
|
|
|
2008-04-21 05:39:05 -04:00
|
|
|
++_recursion_counter;
|
2008-05-11 22:40:48 -04:00
|
|
|
for (uint16_t i = 0; i < 16; i++) {
|
|
|
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
2008-04-17 06:27:03 -04:00
|
|
|
button->set_active(on);
|
2008-04-14 02:23:11 -04:00
|
|
|
}
|
2008-04-21 05:39:05 -04:00
|
|
|
--_recursion_counter;
|
2008-05-11 22:40:48 -04:00
|
|
|
mode_changed.emit(_channel_mode, get_selected_channels());
|
2008-04-14 02:23:11 -04:00
|
|
|
}
|
2008-04-17 06:27:03 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
MidiMultipleChannelSelector::invert_selection(void)
|
|
|
|
{
|
2008-05-11 22:40:48 -04:00
|
|
|
if (_channel_mode == ForceChannel)
|
|
|
|
return;
|
|
|
|
|
2008-04-21 05:39:05 -04:00
|
|
|
++_recursion_counter;
|
2008-05-11 22:40:48 -04:00
|
|
|
for (uint16_t i = 0; i < 16; i++) {
|
|
|
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
|
|
|
if (button->get_active()) {
|
2008-04-17 06:27:03 -04:00
|
|
|
button->set_active(false);
|
|
|
|
} else {
|
|
|
|
button->set_active(true);
|
|
|
|
}
|
|
|
|
}
|
2008-04-21 05:39:05 -04:00
|
|
|
--_recursion_counter;
|
2008-05-11 22:40:48 -04:00
|
|
|
mode_changed.emit(_channel_mode, get_selected_channels());
|
2008-04-17 06:27:03 -04:00
|
|
|
}
|
|
|
|
|