summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-05-12 02:40:48 +0000
committerDavid Robillard <d@drobilla.net>2008-05-12 02:40:48 +0000
commit8ca72c4eca3a712f5368680ba0fbce5beb831324 (patch)
tree65b29e7fe4bb0d28f8a113bf014e831d98c7d50b /gtk2_ardour
parenta76e2128efea2d48fd873e95fd7c0f0b6f6135b3 (diff)
Fix various MIDI corruption bugs.
Re-enable MIDI CC controller bars and other immediate output (hans commented out, tsk tsk). Write channel mode as textual enumeration instead of magic number. Better atomic (almost) channel mode switching on MIDI ring buffer (was a possible, if unlikely, source of corruption). Handle some cases of broken MIDI, and oversized events, more gracefully. git-svn-id: svn://localhost/ardour2/branches/3.0@3335 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/canvas-note-event.cc1
-rw-r--r--gtk2_ardour/midi_channel_selector.cc163
-rw-r--r--gtk2_ardour/midi_channel_selector.h62
-rw-r--r--gtk2_ardour/midi_region_view.cc113
-rw-r--r--gtk2_ardour/midi_region_view.h9
-rw-r--r--gtk2_ardour/midi_time_axis.cc10
-rw-r--r--gtk2_ardour/midi_time_axis.h7
7 files changed, 193 insertions, 172 deletions
diff --git a/gtk2_ardour/canvas-note-event.cc b/gtk2_ardour/canvas-note-event.cc
index bd402f8c08..0e758b5489 100644
--- a/gtk2_ardour/canvas-note-event.cc
+++ b/gtk2_ardour/canvas-note-event.cc
@@ -45,7 +45,6 @@ CanvasNoteEvent::CanvasNoteEvent(MidiRegionView& region, Item* item,
CanvasNoteEvent::~CanvasNoteEvent()
{
- cerr << "CanvasNoteEvent::~CanvasNoteEvent() " << int(_note->note()) << " velo " << int(_note->velocity()) << endl;
if (_text) {
_text->hide();
delete _text;
diff --git a/gtk2_ardour/midi_channel_selector.cc b/gtk2_ardour/midi_channel_selector.cc
index 0018c169ab..281c6f5e2d 100644
--- a/gtk2_ardour/midi_channel_selector.cc
+++ b/gtk2_ardour/midi_channel_selector.cc
@@ -1,14 +1,34 @@
+/*
+ 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>
#include "midi_channel_selector.h"
#include "gtkmm/separator.h"
#include "i18n.h"
-#include <sstream>
using namespace std;
using namespace Gtk;
using namespace sigc;
+using namespace ARDOUR;
-MidiChannelSelector::MidiChannelSelector(int no_rows, int no_columns, int start_row, int start_column) :
- Table(no_rows, no_columns, true), _recursion_counter(0)
+MidiChannelSelector::MidiChannelSelector(int no_rows, int no_columns, int start_row, int start_column) : Table(no_rows, no_columns, true)
+ , _recursion_counter(0)
{
assert(no_rows >= 4);
assert(no_rows >= start_row + 4);
@@ -19,8 +39,8 @@ MidiChannelSelector::MidiChannelSelector(int no_rows, int no_columns, int start_
property_row_spacing() = 0;
uint8_t channel_nr = 0;
- for(int row = 0; row < 4; ++row) {
- for(int column = 0; column < 4; ++column) {
+ 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());
@@ -47,21 +67,21 @@ SingleMidiChannelSelector::SingleMidiChannelSelector(uint8_t active_channel)
: MidiChannelSelector()
{
_last_active_button = 0;
- ToggleButton *button = &_buttons[active_channel / 4][active_channel % 4];
+ ToggleButton* button = &_buttons[active_channel / 4][active_channel % 4];
_active_channel = active_channel;
button->set_active(true);
_last_active_button = button;
}
void
-SingleMidiChannelSelector::button_toggled(ToggleButton *button, uint8_t channel)
+SingleMidiChannelSelector::button_toggled(ToggleButton* button, uint8_t channel)
{
++_recursion_counter;
- if(_recursion_counter == 1) {
+ if (_recursion_counter == 1) {
// if the current button is active it must
// be different from the first one
- if(button->get_active()) {
- if(_last_active_button) {
+ if (button->get_active()) {
+ if (_last_active_button) {
_last_active_button->set_active(false);
_active_channel = channel;
_last_active_button = button;
@@ -76,8 +96,9 @@ SingleMidiChannelSelector::button_toggled(ToggleButton *button, uint8_t channel)
--_recursion_counter;
}
-MidiMultipleChannelSelector::MidiMultipleChannelSelector(uint16_t initial_selection, int8_t force_channel)
- : MidiChannelSelector(4, 6, 0, 0), _mode(FILTERING_MULTIPLE_CHANNELS)
+MidiMultipleChannelSelector::MidiMultipleChannelSelector(ChannelMode mode, uint16_t mask)
+ : MidiChannelSelector(4, 6, 0, 0)
+ , _channel_mode(mode)
{
_select_all.add(*manage(new Label(_("All"))));
_select_all.signal_clicked().connect(
@@ -103,58 +124,42 @@ MidiMultipleChannelSelector::MidiMultipleChannelSelector(uint16_t initial_select
attach(_invert_selection, 5, 6, 2, 3);
attach(_force_channel, 5, 6, 3, 4);
- set_selected_channels(initial_selection);
+ set_selected_channels(mask);
}
MidiMultipleChannelSelector::~MidiMultipleChannelSelector()
{
- selection_changed.clear();
- force_channel_changed.clear();
+ mode_changed.clear();
}
-const int8_t
-MidiMultipleChannelSelector::get_force_channel() const
+void
+MidiMultipleChannelSelector::set_channel_mode(ChannelMode mode, uint8_t mask)
{
- if(_mode == FORCING_SINGLE_CHANNEL) {
- for(int8_t i = 0; i < 16; i++) {
- const ToggleButton *button = &_buttons[i / 4][i % 4];
- if(button->get_active()) {
- return i;
- }
+ 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);
}
-
- // this point should not be reached.
- assert(false);
- }
-
- return -1;
-}
-
-void
-MidiMultipleChannelSelector::set_force_channel(int8_t channel)
-{
- if(channel < 0) {
- // if forcing is already activated, deactivate
- if(_mode == FORCING_SINGLE_CHANNEL) {
- _force_channel.toggled();
- }
- // if not, nothing to do
- } else {
- // otherwise simulate activating force channels by pressing the
- // two buttons the user would press
- _force_channel.toggled();
- _buttons[channel / 4][channel % 4].toggled();
}
}
-
const uint16_t
MidiMultipleChannelSelector::get_selected_channels() const
{
uint16_t selected_channels = 0;
- for(uint16_t i = 0; i < 16; i++) {
- const ToggleButton *button = &_buttons[i / 4][i % 4];
- if(button->get_active()) {
+ for (uint16_t i = 0; i < 16; i++) {
+ const ToggleButton* button = &_buttons[i / 4][i % 4];
+ if (button->get_active()) {
selected_channels |= (1L << i);
}
}
@@ -165,9 +170,9 @@ MidiMultipleChannelSelector::get_selected_channels() const
void
MidiMultipleChannelSelector::set_selected_channels(uint16_t selected_channels)
{
- for(uint16_t i = 0; i < 16; i++) {
- ToggleButton *button = &_buttons[i / 4][i % 4];
- if(selected_channels & (1L << i)) {
+ for (uint16_t i = 0; i < 16; i++) {
+ ToggleButton* button = &_buttons[i / 4][i % 4];
+ if (selected_channels & (1L << i)) {
button->set_active(true);
} else {
button->set_active(false);
@@ -179,13 +184,13 @@ void
MidiMultipleChannelSelector::button_toggled(ToggleButton *button, uint8_t channel)
{
++_recursion_counter;
- if(_recursion_counter == 1) {
- if(_mode == FORCING_SINGLE_CHANNEL) {
+ if (_recursion_counter == 1) {
+ if (_channel_mode == ForceChannel) {
+ mode_changed.emit(_channel_mode, channel);
set_selected_channels(1 << channel);
+ } else {
+ mode_changed.emit(_channel_mode, get_selected_channels());
}
-
- force_channel_changed.emit(get_force_channel());
- selection_changed.emit(get_selected_channels());
}
--_recursion_counter;
}
@@ -193,67 +198,73 @@ MidiMultipleChannelSelector::button_toggled(ToggleButton *button, uint8_t channe
void
MidiMultipleChannelSelector::force_channels_button_toggled()
{
- if(_force_channel.get_active()) {
- _mode = FORCING_SINGLE_CHANNEL;
+ if (_force_channel.get_active()) {
+ _channel_mode = ForceChannel;
bool found_first_active = false;
// leave only the first button enabled
- for(int i = 0; i <= 15; i++) {
- ToggleButton *button = &_buttons[i / 4][i % 4];
- if(button->get_active()) {
- if(found_first_active) {
+ 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) {
++_recursion_counter;
button->set_active(false);
--_recursion_counter;
} else {
found_first_active = true;
+ active_channel = i;
}
}
}
- if(!found_first_active) {
+ if (!found_first_active) {
_buttons[0][0].set_active(true);
}
_select_all.set_sensitive(false);
_select_none.set_sensitive(false);
_invert_selection.set_sensitive(false);
- force_channel_changed.emit(get_force_channel());
- selection_changed.emit(get_selected_channels());
+ mode_changed.emit(_channel_mode, active_channel);
} else {
- _mode = FILTERING_MULTIPLE_CHANNELS;
+ _channel_mode = FilterChannels;
_select_all.set_sensitive(true);
_select_none.set_sensitive(true);
_invert_selection.set_sensitive(true);
- force_channel_changed.emit(get_force_channel());
- selection_changed.emit(get_selected_channels());
+ mode_changed.emit(FilterChannels, get_selected_channels());
}
}
void
MidiMultipleChannelSelector::select_all(bool on)
{
+ if (_channel_mode == ForceChannel)
+ return;
+
++_recursion_counter;
- for(uint16_t i = 0; i < 16; i++) {
- ToggleButton *button = &_buttons[i / 4][i % 4];
+ for (uint16_t i = 0; i < 16; i++) {
+ ToggleButton* button = &_buttons[i / 4][i % 4];
button->set_active(on);
}
--_recursion_counter;
- selection_changed.emit(get_selected_channels());
+ mode_changed.emit(_channel_mode, get_selected_channels());
}
void
MidiMultipleChannelSelector::invert_selection(void)
{
+ if (_channel_mode == ForceChannel)
+ return;
+
++_recursion_counter;
- for(uint16_t i = 0; i < 16; i++) {
- ToggleButton *button = &_buttons[i / 4][i % 4];
- if(button->get_active()) {
+ for (uint16_t i = 0; i < 16; i++) {
+ ToggleButton* button = &_buttons[i / 4][i % 4];
+ if (button->get_active()) {
button->set_active(false);
} else {
button->set_active(true);
}
}
--_recursion_counter;
- selection_changed.emit(get_selected_channels());
+ mode_changed.emit(_channel_mode, get_selected_channels());
}
diff --git a/gtk2_ardour/midi_channel_selector.h b/gtk2_ardour/midi_channel_selector.h
index 9ac95036d6..1f15f3eef5 100644
--- a/gtk2_ardour/midi_channel_selector.h
+++ b/gtk2_ardour/midi_channel_selector.h
@@ -1,13 +1,34 @@
+/*
+ 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.
+*/
+
#ifndef __ardour_ui_midi_channel_selector_h__
#define __ardour_ui_midi_channel_selector_h__
+#include <set>
#include "boost/shared_ptr.hpp"
-#include "gtkmm/table.h"
#include "sigc++/trackable.h"
+#include "gtkmm/table.h"
#include "gtkmm/button.h"
#include "gtkmm/togglebutton.h"
#include "gtkmm/label.h"
-#include <set>
+#include <ardour/types.h>
+
class MidiChannelSelector : public Gtk::Table
{
@@ -15,8 +36,10 @@ public:
MidiChannelSelector(int no_rows = 4, int no_columns = 4, int start_row = 0, int start_column = 0);
virtual ~MidiChannelSelector() = 0;
+ sigc::signal<void, ARDOUR::ChannelMode, uint16_t> mode_changed;
+
protected:
- virtual void button_toggled(Gtk::ToggleButton *button, uint8_t button_nr) = 0;
+ virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr) = 0;
Gtk::Label _button_labels[4][4];
Gtk::ToggleButton _buttons[4][4];
int _recursion_counter;
@@ -32,7 +55,7 @@ public:
sigc::signal<void, uint8_t> channel_selected;
protected:
- virtual void button_toggled(Gtk::ToggleButton *button, uint8_t button_nr);
+ virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
Gtk::ToggleButton* _last_active_button;
uint8_t _active_channel;
@@ -41,40 +64,35 @@ protected:
class MidiMultipleChannelSelector : public MidiChannelSelector
{
public:
- MidiMultipleChannelSelector(uint16_t initial_selection = 0xFFFF, int8_t force_channel = -1);
+ MidiMultipleChannelSelector(ARDOUR::ChannelMode mode = ARDOUR::FilterChannels,
+ uint16_t initial_selection = 0xFFFF);
+
virtual ~MidiMultipleChannelSelector();
+ void set_channel_mode(ARDOUR::ChannelMode mode, uint8_t mask);
+
/**
* @return each bit in the returned word represents a midi channel, eg.
* bit 0 represents channel 0 and bit 15 represents channel 15
*
*/
const uint16_t get_selected_channels() const;
- void set_selected_channels(uint16_t selected_channels);
-
- sigc::signal<void, uint16_t> selection_changed;
- sigc::signal<void, int8_t> force_channel_changed;
+ void set_selected_channels(uint16_t selected_channels);
- const int8_t get_force_channel() const;
- void set_force_channel(int8_t force_channel);
protected:
- enum Mode {
- FILTERING_MULTIPLE_CHANNELS,
- FORCING_SINGLE_CHANNEL
- };
-
- Mode _mode;
+ ARDOUR::ChannelMode _channel_mode;
+ ARDOUR::NoteMode _note_mode;
- virtual void button_toggled(Gtk::ToggleButton *button, uint8_t button_nr);
+ virtual void button_toggled(Gtk::ToggleButton* button, uint8_t button_nr);
void force_channels_button_toggled();
void select_all(bool on);
void invert_selection(void);
- Gtk::Button _select_all;
- Gtk::Button _select_none;
- Gtk::Button _invert_selection;
- Gtk::ToggleButton _force_channel;
+ Gtk::Button _select_all;
+ Gtk::Button _select_none;
+ Gtk::Button _invert_selection;
+ Gtk::ToggleButton _force_channel;
};
#endif /*__ardour_ui_midi_channel_selector_h__*/
diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc
index bc492b0e71..b83630e9fa 100644
--- a/gtk2_ardour/midi_region_view.cc
+++ b/gtk2_ardour/midi_region_view.cc
@@ -62,8 +62,8 @@ using namespace ArdourCanvas;
MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color)
: RegionView (parent, tv, r, spu, basic_color)
- , force_channel(-1)
- , last_channel_selection(0xFFFF)
+ , _force_channel(-1)
+ , _last_channel_selection(0xFFFF)
, _default_note_length(0.0)
, _active_notes(0)
, _note_group(new ArdourCanvas::Group(*parent))
@@ -79,8 +79,8 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &
MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
: RegionView (parent, tv, r, spu, basic_color, visibility)
- , force_channel(-1)
- , last_channel_selection(0xFFFF)
+ , _force_channel(-1)
+ , _last_channel_selection(0xFFFF)
, _default_note_length(0.0)
, _active_notes(0)
, _note_group(new ArdourCanvas::Group(*parent))
@@ -135,10 +135,8 @@ MidiRegionView::init (Gdk::Color& basic_color, bool wfd)
group->signal_event().connect (mem_fun (this, &MidiRegionView::canvas_event), false);
- midi_view()->signal_force_channel_changed().connect(
- mem_fun(this, &MidiRegionView::midi_force_channel_changed));
- midi_view()->signal_channel_selection_changed().connect(
- mem_fun(this, &MidiRegionView::midi_channel_selection_changed));
+ midi_view()->signal_channel_mode_changed().connect(
+ mem_fun(this, &MidiRegionView::midi_channel_mode_changed));
}
bool
@@ -324,7 +322,7 @@ MidiRegionView::canvas_event(GdkEvent* ev)
group->ungrab(ev->button.time);
event_frame = trackview.editor.pixel_to_frame(event_x);
- if(_pressed_button != 1) {
+ if (_pressed_button != 1) {
return false;
}
@@ -458,18 +456,17 @@ MidiRegionView::redisplay_model()
clear_events();
_model->read_lock();
- MidiModel::Notes notes = _model->notes();
- cerr << endl << "Model contains " << notes.size() << " Notes:" << endl;
- for(MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
- cerr << "MODEL: Note time: " << (*i)->time()
- << " pitch: " << int((*i)->note())
- << " duration: " << (*i)->duration()
- << " end-time: " << (*i)->end_time()
- << " velocity: " << int((*i)->velocity())
- //<< " Note-on: " << note.on_event().
- //<< " Note-off: " << note.off_event()
+ /*MidiModel::Notes notes = _model->notes();
+ cerr << endl << _model->midi_source()->name() << " : redisplaying " << notes.size() << " notes:" << endl;
+ for (MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
+ cerr << "NOTE time: " << (*i)->time()
+ << " pitch: " << int((*i)->note())
+ << " duration: " << (*i)->duration()
+ << " end-time: " << (*i)->end_time()
+ << " velocity: " << int((*i)->velocity())
<< endl;
- }
+ }*/
+
for (size_t i = 0; i < _model->n_notes(); ++i) {
add_note(_model->note_at(i));
@@ -479,10 +476,10 @@ MidiRegionView::redisplay_model()
control = _model->controls().begin();
control != _model->controls().end(); ++control) {
- if( control->first.type() == MidiPgmChangeAutomation ) {
+ if ( control->first.type() == MidiPgmChangeAutomation ) {
Glib::Mutex::Lock list_lock (control->second->list()->lock());
- for(AutomationList::const_iterator event = control->second->list()->begin();
+ for (AutomationList::const_iterator event = control->second->list()->begin();
event != control->second->list()->end(); ++event) {
boost::shared_ptr<MIDI::Event> midi_event(new MIDI::Event());
MidiControlIterator iter(control->second->list(), (*event)->when, (*event)->value);
@@ -594,14 +591,14 @@ MidiRegionView::set_y_position_and_height (double y, double h)
}
event->hide_velocity();
- if(CanvasNote* note = dynamic_cast<CanvasNote*>(event)) {
+ if (CanvasNote* note = dynamic_cast<CanvasNote*>(event)) {
const double y1 = midi_stream_view()->note_to_y(event->note()->note());
const double y2 = y1 + floor(midi_stream_view()->note_height());
note->property_y1() = y1;
note->property_y2() = y2;
}
- if(CanvasHit* hit = dynamic_cast<CanvasHit*>(event)) {
+ if (CanvasHit* hit = dynamic_cast<CanvasHit*>(event)) {
double x = trackview.editor.frame_to_pixel((nframes_t)
event->note()->time() - _region->start());
const double diamond_size = midi_stream_view()->note_height() / 2.0;
@@ -612,7 +609,7 @@ MidiRegionView::set_y_position_and_height (double y, double h)
hit->move(x-hit->x1(), y-hit->y1());
hit->show();
}
- if(event->selected()) {
+ if (event->selected()) {
event->show_velocity();
}
}
@@ -732,7 +729,7 @@ MidiRegionView::add_note(const boost::shared_ptr<Note> note)
assert(midi_view()->note_mode() == Sustained || midi_view()->note_mode() == Percussive);
// dont display notes beyond the region bounds
- if(
+ if (
note->time() - _region->start() >= _region->length() ||
note->time() < _region->start() ||
note->note() < midi_stream_view()->lowest_note() ||
@@ -805,11 +802,11 @@ MidiRegionView::add_note(const boost::shared_ptr<Note> note)
event = 0;
}
- if(event) {
- if(_marked_for_selection.find(event->note()) != _marked_for_selection.end()) {
+ if (event) {
+ if (_marked_for_selection.find(event->note()) != _marked_for_selection.end()) {
note_selected(event, true);
}
- event->on_channel_selection_change(last_channel_selection);
+ event->on_channel_selection_change(_last_channel_selection);
}
}
@@ -819,7 +816,7 @@ MidiRegionView::add_pgm_change(boost::shared_ptr<MIDI::Event> event)
assert(event->time() >= 0);
// dont display notes beyond the region bounds
- if(
+ if (
event->time() - _region->start() >= _region->length() ||
event->time() < _region->start()
) {
@@ -997,7 +994,7 @@ MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, uint8_t dnote)
new_note_time += dt;
// keep notes inside region if dragged beyond left region bound
- if(new_note_time < _region->start()) {
+ if (new_note_time < _region->start()) {
new_note_time = _region->start();
}
@@ -1014,7 +1011,7 @@ MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, uint8_t dnote)
clamp_0_to_127(new_pitch);
//notes which are dragged beyond the standard midi range snap back to their original place
- if((original_pitch != 0 && new_pitch == 0) || (original_pitch != 127 && new_pitch == 127)) {
+ if ((original_pitch != 0 && new_pitch == 0) || (original_pitch != 127 && new_pitch == 127)) {
new_pitch = original_pitch;
}
@@ -1032,7 +1029,7 @@ MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, uint8_t dnote)
apply_command();
// care about notes being moved beyond the upper/lower bounds on the canvas
- if(lowest_note_in_selection < midi_stream_view()->lowest_note() ||
+ if (lowest_note_in_selection < midi_stream_view()->lowest_note() ||
highest_note_in_selection > midi_stream_view()->highest_note()
) {
midi_stream_view()->set_note_range(MidiStreamView::ContentsRange);
@@ -1088,7 +1085,7 @@ MidiRegionView::begin_resizing(CanvasNote::NoteEnd note_end)
CanvasNote *note = dynamic_cast<CanvasNote *> (*i);
// only insert CanvasNotes into the map
- if(note) {
+ if (note) {
NoteResizeData *resize_data = new NoteResizeData();
resize_data->canvas_note = note;
@@ -1122,7 +1119,7 @@ MidiRegionView::begin_resizing(CanvasNote::NoteEnd note_end)
resize_data->resize_rect = resize_rect;
- if(note_end == CanvasNote::NOTE_ON) {
+ if (note_end == CanvasNote::NOTE_ON) {
resize_data->current_x = note->x1();
} else { // NOTE_OFF
resize_data->current_x = note->x2();
@@ -1142,7 +1139,7 @@ MidiRegionView::update_resizing(CanvasNote::NoteEnd note_end, double x, bool rel
const double region_start = get_position_pixels();
- if(relative) {
+ if (relative) {
(*i)->current_x = (*i)->current_x + x;
} else {
// x is in track relative, transform it to region relative
@@ -1151,7 +1148,7 @@ MidiRegionView::update_resizing(CanvasNote::NoteEnd note_end, double x, bool rel
double current_x = (*i)->current_x;
- if(note_end == CanvasNote::NOTE_ON) {
+ if (note_end == CanvasNote::NOTE_ON) {
resize_rect->property_x1() = snap_to_pixel(current_x);
resize_rect->property_x2() = canvas_note->x2();
} else {
@@ -1172,7 +1169,7 @@ MidiRegionView::commit_resizing(CanvasNote::NoteEnd note_end, double event_x, bo
double current_x = (*i)->current_x;
const double position = get_position_pixels();
- if(!relative) {
+ if (!relative) {
// event_x is in track relative, transform it to region relative
current_x = event_x - position;
}
@@ -1221,7 +1218,7 @@ MidiRegionView::change_velocity(uint8_t velocity, bool relative)
CanvasNoteEvent *event = *i;
const boost::shared_ptr<Note> copy(new Note(*(event->note().get())));
- if(relative) {
+ if (relative) {
uint8_t new_velocity = copy->velocity() + velocity;
clamp_0_to_127(new_velocity);
@@ -1238,7 +1235,7 @@ MidiRegionView::change_velocity(uint8_t velocity, bool relative)
}
// dont keep notes selected if tweaking a single note
- if(_marked_for_selection.size() == 1) {
+ if (_marked_for_selection.size() == 1) {
_marked_for_selection.clear();
}
@@ -1266,7 +1263,7 @@ MidiRegionView::change_channel(uint8_t channel)
}
// dont keep notes selected if tweaking a single note
- if(_marked_for_selection.size() == 1) {
+ if (_marked_for_selection.size() == 1) {
_marked_for_selection.clear();
}
@@ -1308,22 +1305,24 @@ MidiRegionView::set_frame_color()
}
void
-MidiRegionView::midi_force_channel_changed(int8_t channel)
-{
- force_channel = channel;
-}
-
-void
-MidiRegionView::midi_channel_selection_changed(uint16_t selection)
+MidiRegionView::midi_channel_mode_changed(ChannelMode mode, uint16_t mask)
{
- if(force_channel >= 0) {
- selection = 0xFFFF;
- }
-
- for(std::vector<ArdourCanvas::CanvasNoteEvent*>::iterator i = _events.begin();
- i != _events.end();
- ++i) {
- (*i)->on_channel_selection_change(selection);
+ switch (mode) {
+ case AllChannels:
+ case FilterChannels:
+ _force_channel = -1;
+ break;
+ case ForceChannel:
+ _force_channel = mask;
+ mask = 0xFFFF; // Show all notes as active (below)
+ };
+
+ // Update notes for selection
+ for (std::vector<ArdourCanvas::CanvasNoteEvent*>::iterator i = _events.begin();
+ i != _events.end(); ++i) {
+ (*i)->on_channel_selection_change(mask);
}
- last_channel_selection = selection;
+
+ _last_channel_selection = mask;
}
+
diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h
index 1a37205bef..4283483f04 100644
--- a/gtk2_ardour/midi_region_view.h
+++ b/gtk2_ardour/midi_region_view.h
@@ -241,16 +241,15 @@ class MidiRegionView : public RegionView
bool canvas_event(GdkEvent* ev);
bool note_canvas_event(GdkEvent* ev);
- int8_t force_channel;
- void midi_force_channel_changed(int8_t channel);
- uint16_t last_channel_selection;
- void midi_channel_selection_changed(uint16_t selection);
+ void midi_channel_mode_changed(ARDOUR::ChannelMode mode, uint16_t mask);
void clear_selection_except(ArdourCanvas::CanvasNoteEvent* ev);
void clear_selection() { clear_selection_except(NULL); }
void update_drag_selection(double last_x, double x, double last_y, double y);
- double _default_note_length;
+ int8_t _force_channel;
+ uint16_t _last_channel_selection;
+ double _default_note_length;
boost::shared_ptr<ARDOUR::MidiModel> _model;
std::vector<ArdourCanvas::CanvasNoteEvent*> _events;
diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc
index 95b77abaf4..f6d2993cfe 100644
--- a/gtk2_ardour/midi_time_axis.cc
+++ b/gtk2_ardour/midi_time_axis.cc
@@ -144,13 +144,11 @@ MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shar
mem_fun(this, &MidiTimeAxisView::channel_selector_toggled));
controls_vbox.pack_end(_midi_expander, SHRINK, 0);
boost::shared_ptr<MidiDiskstream> diskstream = midi_track()->midi_diskstream();
+
// restore channel selector settings
- _channel_selector.set_selected_channels(diskstream->get_channel_mask());
- _channel_selector.set_force_channel(diskstream->get_force_channel());
- _channel_selector.selection_changed.connect(
- mem_fun(*midi_track()->midi_diskstream(), &MidiDiskstream::set_channel_mask));
- _channel_selector.force_channel_changed.connect(
- mem_fun(*midi_track()->midi_diskstream(), &MidiDiskstream::set_force_channel));
+ _channel_selector.set_channel_mode(diskstream->get_channel_mode(), diskstream->get_channel_mask());
+ _channel_selector.mode_changed.connect(
+ mem_fun(*midi_track()->midi_diskstream(), &MidiDiskstream::set_channel_mode));
}
diff --git a/gtk2_ardour/midi_time_axis.h b/gtk2_ardour/midi_time_axis.h
index 98cc5bb0b7..cdbf6907e1 100644
--- a/gtk2_ardour/midi_time_axis.h
+++ b/gtk2_ardour/midi_time_axis.h
@@ -74,11 +74,8 @@ class MidiTimeAxisView : public RouteTimeAxisView
void update_range();
- sigc::signal<void, uint16_t>& signal_channel_selection_changed()
- { return _channel_selector.selection_changed; }
-
- sigc::signal<void, int8_t>& signal_force_channel_changed()
- { return _channel_selector.force_channel_changed; }
+ sigc::signal<void, ARDOUR::ChannelMode, uint16_t>& signal_channel_mode_changed()
+ { return _channel_selector.mode_changed; }
private: