mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-17 20:26:30 +01:00
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
This commit is contained in:
parent
a76e2128ef
commit
8ca72c4eca
17 changed files with 351 additions and 297 deletions
|
|
@ -45,7 +45,6 @@ CanvasNoteEvent::CanvasNoteEvent(MidiRegionView& region, Item* item,
|
||||||
|
|
||||||
CanvasNoteEvent::~CanvasNoteEvent()
|
CanvasNoteEvent::~CanvasNoteEvent()
|
||||||
{
|
{
|
||||||
cerr << "CanvasNoteEvent::~CanvasNoteEvent() " << int(_note->note()) << " velo " << int(_note->velocity()) << endl;
|
|
||||||
if (_text) {
|
if (_text) {
|
||||||
_text->hide();
|
_text->hide();
|
||||||
delete _text;
|
delete _text;
|
||||||
|
|
|
||||||
|
|
@ -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 "midi_channel_selector.h"
|
||||||
#include "gtkmm/separator.h"
|
#include "gtkmm/separator.h"
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Gtk;
|
using namespace Gtk;
|
||||||
using namespace sigc;
|
using namespace sigc;
|
||||||
|
using namespace ARDOUR;
|
||||||
|
|
||||||
MidiChannelSelector::MidiChannelSelector(int no_rows, int no_columns, int start_row, int start_column) :
|
MidiChannelSelector::MidiChannelSelector(int no_rows, int no_columns, int start_row, int start_column) : Table(no_rows, no_columns, true)
|
||||||
Table(no_rows, no_columns, true), _recursion_counter(0)
|
, _recursion_counter(0)
|
||||||
{
|
{
|
||||||
assert(no_rows >= 4);
|
assert(no_rows >= 4);
|
||||||
assert(no_rows >= start_row + 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;
|
property_row_spacing() = 0;
|
||||||
|
|
||||||
uint8_t channel_nr = 0;
|
uint8_t channel_nr = 0;
|
||||||
for(int row = 0; row < 4; ++row) {
|
for (int row = 0; row < 4; ++row) {
|
||||||
for(int column = 0; column < 4; ++column) {
|
for (int column = 0; column < 4; ++column) {
|
||||||
ostringstream channel;
|
ostringstream channel;
|
||||||
channel << int(++channel_nr);
|
channel << int(++channel_nr);
|
||||||
_button_labels[row][column].set_text(channel.str());
|
_button_labels[row][column].set_text(channel.str());
|
||||||
|
|
@ -47,21 +67,21 @@ SingleMidiChannelSelector::SingleMidiChannelSelector(uint8_t active_channel)
|
||||||
: MidiChannelSelector()
|
: MidiChannelSelector()
|
||||||
{
|
{
|
||||||
_last_active_button = 0;
|
_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;
|
_active_channel = active_channel;
|
||||||
button->set_active(true);
|
button->set_active(true);
|
||||||
_last_active_button = button;
|
_last_active_button = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SingleMidiChannelSelector::button_toggled(ToggleButton *button, uint8_t channel)
|
SingleMidiChannelSelector::button_toggled(ToggleButton* button, uint8_t channel)
|
||||||
{
|
{
|
||||||
++_recursion_counter;
|
++_recursion_counter;
|
||||||
if(_recursion_counter == 1) {
|
if (_recursion_counter == 1) {
|
||||||
// if the current button is active it must
|
// if the current button is active it must
|
||||||
// be different from the first one
|
// be different from the first one
|
||||||
if(button->get_active()) {
|
if (button->get_active()) {
|
||||||
if(_last_active_button) {
|
if (_last_active_button) {
|
||||||
_last_active_button->set_active(false);
|
_last_active_button->set_active(false);
|
||||||
_active_channel = channel;
|
_active_channel = channel;
|
||||||
_last_active_button = button;
|
_last_active_button = button;
|
||||||
|
|
@ -76,8 +96,9 @@ SingleMidiChannelSelector::button_toggled(ToggleButton *button, uint8_t channel)
|
||||||
--_recursion_counter;
|
--_recursion_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
MidiMultipleChannelSelector::MidiMultipleChannelSelector(uint16_t initial_selection, int8_t force_channel)
|
MidiMultipleChannelSelector::MidiMultipleChannelSelector(ChannelMode mode, uint16_t mask)
|
||||||
: MidiChannelSelector(4, 6, 0, 0), _mode(FILTERING_MULTIPLE_CHANNELS)
|
: MidiChannelSelector(4, 6, 0, 0)
|
||||||
|
, _channel_mode(mode)
|
||||||
{
|
{
|
||||||
_select_all.add(*manage(new Label(_("All"))));
|
_select_all.add(*manage(new Label(_("All"))));
|
||||||
_select_all.signal_clicked().connect(
|
_select_all.signal_clicked().connect(
|
||||||
|
|
@ -103,58 +124,42 @@ MidiMultipleChannelSelector::MidiMultipleChannelSelector(uint16_t initial_select
|
||||||
attach(_invert_selection, 5, 6, 2, 3);
|
attach(_invert_selection, 5, 6, 2, 3);
|
||||||
attach(_force_channel, 5, 6, 3, 4);
|
attach(_force_channel, 5, 6, 3, 4);
|
||||||
|
|
||||||
set_selected_channels(initial_selection);
|
set_selected_channels(mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
MidiMultipleChannelSelector::~MidiMultipleChannelSelector()
|
MidiMultipleChannelSelector::~MidiMultipleChannelSelector()
|
||||||
{
|
{
|
||||||
selection_changed.clear();
|
mode_changed.clear();
|
||||||
force_channel_changed.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
const int8_t
|
|
||||||
MidiMultipleChannelSelector::get_force_channel() const
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// this point should not be reached.
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MidiMultipleChannelSelector::set_force_channel(int8_t channel)
|
MidiMultipleChannelSelector::set_channel_mode(ChannelMode mode, uint8_t mask)
|
||||||
{
|
{
|
||||||
if(channel < 0) {
|
switch (mode) {
|
||||||
// if forcing is already activated, deactivate
|
case AllChannels:
|
||||||
if(_mode == FORCING_SINGLE_CHANNEL) {
|
_force_channel.set_active(false);
|
||||||
_force_channel.toggled();
|
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);
|
||||||
}
|
}
|
||||||
// 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
|
const uint16_t
|
||||||
MidiMultipleChannelSelector::get_selected_channels() const
|
MidiMultipleChannelSelector::get_selected_channels() const
|
||||||
{
|
{
|
||||||
uint16_t selected_channels = 0;
|
uint16_t selected_channels = 0;
|
||||||
for(uint16_t i = 0; i < 16; i++) {
|
for (uint16_t i = 0; i < 16; i++) {
|
||||||
const ToggleButton *button = &_buttons[i / 4][i % 4];
|
const ToggleButton* button = &_buttons[i / 4][i % 4];
|
||||||
if(button->get_active()) {
|
if (button->get_active()) {
|
||||||
selected_channels |= (1L << i);
|
selected_channels |= (1L << i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -165,9 +170,9 @@ MidiMultipleChannelSelector::get_selected_channels() const
|
||||||
void
|
void
|
||||||
MidiMultipleChannelSelector::set_selected_channels(uint16_t selected_channels)
|
MidiMultipleChannelSelector::set_selected_channels(uint16_t selected_channels)
|
||||||
{
|
{
|
||||||
for(uint16_t i = 0; i < 16; i++) {
|
for (uint16_t i = 0; i < 16; i++) {
|
||||||
ToggleButton *button = &_buttons[i / 4][i % 4];
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
||||||
if(selected_channels & (1L << i)) {
|
if (selected_channels & (1L << i)) {
|
||||||
button->set_active(true);
|
button->set_active(true);
|
||||||
} else {
|
} else {
|
||||||
button->set_active(false);
|
button->set_active(false);
|
||||||
|
|
@ -179,13 +184,13 @@ void
|
||||||
MidiMultipleChannelSelector::button_toggled(ToggleButton *button, uint8_t channel)
|
MidiMultipleChannelSelector::button_toggled(ToggleButton *button, uint8_t channel)
|
||||||
{
|
{
|
||||||
++_recursion_counter;
|
++_recursion_counter;
|
||||||
if(_recursion_counter == 1) {
|
if (_recursion_counter == 1) {
|
||||||
if(_mode == FORCING_SINGLE_CHANNEL) {
|
if (_channel_mode == ForceChannel) {
|
||||||
|
mode_changed.emit(_channel_mode, channel);
|
||||||
set_selected_channels(1 << 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;
|
--_recursion_counter;
|
||||||
}
|
}
|
||||||
|
|
@ -193,67 +198,73 @@ MidiMultipleChannelSelector::button_toggled(ToggleButton *button, uint8_t channe
|
||||||
void
|
void
|
||||||
MidiMultipleChannelSelector::force_channels_button_toggled()
|
MidiMultipleChannelSelector::force_channels_button_toggled()
|
||||||
{
|
{
|
||||||
if(_force_channel.get_active()) {
|
if (_force_channel.get_active()) {
|
||||||
_mode = FORCING_SINGLE_CHANNEL;
|
_channel_mode = ForceChannel;
|
||||||
bool found_first_active = false;
|
bool found_first_active = false;
|
||||||
// leave only the first button enabled
|
// leave only the first button enabled
|
||||||
for(int i = 0; i <= 15; i++) {
|
uint16_t active_channel = 0;
|
||||||
ToggleButton *button = &_buttons[i / 4][i % 4];
|
for (int i = 0; i <= 15; i++) {
|
||||||
if(button->get_active()) {
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
||||||
if(found_first_active) {
|
if (button->get_active()) {
|
||||||
|
if (found_first_active) {
|
||||||
++_recursion_counter;
|
++_recursion_counter;
|
||||||
button->set_active(false);
|
button->set_active(false);
|
||||||
--_recursion_counter;
|
--_recursion_counter;
|
||||||
} else {
|
} else {
|
||||||
found_first_active = true;
|
found_first_active = true;
|
||||||
|
active_channel = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found_first_active) {
|
if (!found_first_active) {
|
||||||
_buttons[0][0].set_active(true);
|
_buttons[0][0].set_active(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_select_all.set_sensitive(false);
|
_select_all.set_sensitive(false);
|
||||||
_select_none.set_sensitive(false);
|
_select_none.set_sensitive(false);
|
||||||
_invert_selection.set_sensitive(false);
|
_invert_selection.set_sensitive(false);
|
||||||
force_channel_changed.emit(get_force_channel());
|
mode_changed.emit(_channel_mode, active_channel);
|
||||||
selection_changed.emit(get_selected_channels());
|
|
||||||
} else {
|
} else {
|
||||||
_mode = FILTERING_MULTIPLE_CHANNELS;
|
_channel_mode = FilterChannels;
|
||||||
_select_all.set_sensitive(true);
|
_select_all.set_sensitive(true);
|
||||||
_select_none.set_sensitive(true);
|
_select_none.set_sensitive(true);
|
||||||
_invert_selection.set_sensitive(true);
|
_invert_selection.set_sensitive(true);
|
||||||
force_channel_changed.emit(get_force_channel());
|
mode_changed.emit(FilterChannels, get_selected_channels());
|
||||||
selection_changed.emit(get_selected_channels());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MidiMultipleChannelSelector::select_all(bool on)
|
MidiMultipleChannelSelector::select_all(bool on)
|
||||||
{
|
{
|
||||||
|
if (_channel_mode == ForceChannel)
|
||||||
|
return;
|
||||||
|
|
||||||
++_recursion_counter;
|
++_recursion_counter;
|
||||||
for(uint16_t i = 0; i < 16; i++) {
|
for (uint16_t i = 0; i < 16; i++) {
|
||||||
ToggleButton *button = &_buttons[i / 4][i % 4];
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
||||||
button->set_active(on);
|
button->set_active(on);
|
||||||
}
|
}
|
||||||
--_recursion_counter;
|
--_recursion_counter;
|
||||||
selection_changed.emit(get_selected_channels());
|
mode_changed.emit(_channel_mode, get_selected_channels());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MidiMultipleChannelSelector::invert_selection(void)
|
MidiMultipleChannelSelector::invert_selection(void)
|
||||||
{
|
{
|
||||||
|
if (_channel_mode == ForceChannel)
|
||||||
|
return;
|
||||||
|
|
||||||
++_recursion_counter;
|
++_recursion_counter;
|
||||||
for(uint16_t i = 0; i < 16; i++) {
|
for (uint16_t i = 0; i < 16; i++) {
|
||||||
ToggleButton *button = &_buttons[i / 4][i % 4];
|
ToggleButton* button = &_buttons[i / 4][i % 4];
|
||||||
if(button->get_active()) {
|
if (button->get_active()) {
|
||||||
button->set_active(false);
|
button->set_active(false);
|
||||||
} else {
|
} else {
|
||||||
button->set_active(true);
|
button->set_active(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--_recursion_counter;
|
--_recursion_counter;
|
||||||
selection_changed.emit(get_selected_channels());
|
mode_changed.emit(_channel_mode, get_selected_channels());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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__
|
#ifndef __ardour_ui_midi_channel_selector_h__
|
||||||
#define __ardour_ui_midi_channel_selector_h__
|
#define __ardour_ui_midi_channel_selector_h__
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include "boost/shared_ptr.hpp"
|
#include "boost/shared_ptr.hpp"
|
||||||
#include "gtkmm/table.h"
|
|
||||||
#include "sigc++/trackable.h"
|
#include "sigc++/trackable.h"
|
||||||
|
#include "gtkmm/table.h"
|
||||||
#include "gtkmm/button.h"
|
#include "gtkmm/button.h"
|
||||||
#include "gtkmm/togglebutton.h"
|
#include "gtkmm/togglebutton.h"
|
||||||
#include "gtkmm/label.h"
|
#include "gtkmm/label.h"
|
||||||
#include <set>
|
#include <ardour/types.h>
|
||||||
|
|
||||||
|
|
||||||
class MidiChannelSelector : public Gtk::Table
|
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);
|
MidiChannelSelector(int no_rows = 4, int no_columns = 4, int start_row = 0, int start_column = 0);
|
||||||
virtual ~MidiChannelSelector() = 0;
|
virtual ~MidiChannelSelector() = 0;
|
||||||
|
|
||||||
|
sigc::signal<void, ARDOUR::ChannelMode, uint16_t> mode_changed;
|
||||||
|
|
||||||
protected:
|
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::Label _button_labels[4][4];
|
||||||
Gtk::ToggleButton _buttons[4][4];
|
Gtk::ToggleButton _buttons[4][4];
|
||||||
int _recursion_counter;
|
int _recursion_counter;
|
||||||
|
|
@ -32,7 +55,7 @@ public:
|
||||||
sigc::signal<void, uint8_t> channel_selected;
|
sigc::signal<void, uint8_t> channel_selected;
|
||||||
|
|
||||||
protected:
|
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;
|
Gtk::ToggleButton* _last_active_button;
|
||||||
uint8_t _active_channel;
|
uint8_t _active_channel;
|
||||||
|
|
@ -41,40 +64,35 @@ protected:
|
||||||
class MidiMultipleChannelSelector : public MidiChannelSelector
|
class MidiMultipleChannelSelector : public MidiChannelSelector
|
||||||
{
|
{
|
||||||
public:
|
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();
|
virtual ~MidiMultipleChannelSelector();
|
||||||
|
|
||||||
|
void set_channel_mode(ARDOUR::ChannelMode mode, uint8_t mask);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return each bit in the returned word represents a midi channel, eg.
|
* @return each bit in the returned word represents a midi channel, eg.
|
||||||
* bit 0 represents channel 0 and bit 15 represents channel 15
|
* bit 0 represents channel 0 and bit 15 represents channel 15
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
const uint16_t get_selected_channels() const;
|
const uint16_t get_selected_channels() const;
|
||||||
void set_selected_channels(uint16_t selected_channels);
|
void set_selected_channels(uint16_t selected_channels);
|
||||||
|
|
||||||
sigc::signal<void, uint16_t> selection_changed;
|
|
||||||
sigc::signal<void, int8_t> force_channel_changed;
|
|
||||||
|
|
||||||
const int8_t get_force_channel() const;
|
|
||||||
void set_force_channel(int8_t force_channel);
|
|
||||||
protected:
|
protected:
|
||||||
enum Mode {
|
ARDOUR::ChannelMode _channel_mode;
|
||||||
FILTERING_MULTIPLE_CHANNELS,
|
ARDOUR::NoteMode _note_mode;
|
||||||
FORCING_SINGLE_CHANNEL
|
|
||||||
};
|
|
||||||
|
|
||||||
Mode _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 force_channels_button_toggled();
|
||||||
|
|
||||||
void select_all(bool on);
|
void select_all(bool on);
|
||||||
void invert_selection(void);
|
void invert_selection(void);
|
||||||
|
|
||||||
Gtk::Button _select_all;
|
Gtk::Button _select_all;
|
||||||
Gtk::Button _select_none;
|
Gtk::Button _select_none;
|
||||||
Gtk::Button _invert_selection;
|
Gtk::Button _invert_selection;
|
||||||
Gtk::ToggleButton _force_channel;
|
Gtk::ToggleButton _force_channel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*__ardour_ui_midi_channel_selector_h__*/
|
#endif /*__ardour_ui_midi_channel_selector_h__*/
|
||||||
|
|
|
||||||
|
|
@ -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)
|
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)
|
: RegionView (parent, tv, r, spu, basic_color)
|
||||||
, force_channel(-1)
|
, _force_channel(-1)
|
||||||
, last_channel_selection(0xFFFF)
|
, _last_channel_selection(0xFFFF)
|
||||||
, _default_note_length(0.0)
|
, _default_note_length(0.0)
|
||||||
, _active_notes(0)
|
, _active_notes(0)
|
||||||
, _note_group(new ArdourCanvas::Group(*parent))
|
, _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)
|
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)
|
: RegionView (parent, tv, r, spu, basic_color, visibility)
|
||||||
, force_channel(-1)
|
, _force_channel(-1)
|
||||||
, last_channel_selection(0xFFFF)
|
, _last_channel_selection(0xFFFF)
|
||||||
, _default_note_length(0.0)
|
, _default_note_length(0.0)
|
||||||
, _active_notes(0)
|
, _active_notes(0)
|
||||||
, _note_group(new ArdourCanvas::Group(*parent))
|
, _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);
|
group->signal_event().connect (mem_fun (this, &MidiRegionView::canvas_event), false);
|
||||||
|
|
||||||
midi_view()->signal_force_channel_changed().connect(
|
midi_view()->signal_channel_mode_changed().connect(
|
||||||
mem_fun(this, &MidiRegionView::midi_force_channel_changed));
|
mem_fun(this, &MidiRegionView::midi_channel_mode_changed));
|
||||||
midi_view()->signal_channel_selection_changed().connect(
|
|
||||||
mem_fun(this, &MidiRegionView::midi_channel_selection_changed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
@ -324,7 +322,7 @@ MidiRegionView::canvas_event(GdkEvent* ev)
|
||||||
group->ungrab(ev->button.time);
|
group->ungrab(ev->button.time);
|
||||||
event_frame = trackview.editor.pixel_to_frame(event_x);
|
event_frame = trackview.editor.pixel_to_frame(event_x);
|
||||||
|
|
||||||
if(_pressed_button != 1) {
|
if (_pressed_button != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -458,18 +456,17 @@ MidiRegionView::redisplay_model()
|
||||||
clear_events();
|
clear_events();
|
||||||
_model->read_lock();
|
_model->read_lock();
|
||||||
|
|
||||||
MidiModel::Notes notes = _model->notes();
|
/*MidiModel::Notes notes = _model->notes();
|
||||||
cerr << endl << "Model contains " << notes.size() << " Notes:" << endl;
|
cerr << endl << _model->midi_source()->name() << " : redisplaying " << notes.size() << " notes:" << endl;
|
||||||
for(MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
|
for (MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
|
||||||
cerr << "MODEL: Note time: " << (*i)->time()
|
cerr << "NOTE time: " << (*i)->time()
|
||||||
<< " pitch: " << int((*i)->note())
|
<< " pitch: " << int((*i)->note())
|
||||||
<< " duration: " << (*i)->duration()
|
<< " duration: " << (*i)->duration()
|
||||||
<< " end-time: " << (*i)->end_time()
|
<< " end-time: " << (*i)->end_time()
|
||||||
<< " velocity: " << int((*i)->velocity())
|
<< " velocity: " << int((*i)->velocity())
|
||||||
//<< " Note-on: " << note.on_event().
|
|
||||||
//<< " Note-off: " << note.off_event()
|
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
for (size_t i = 0; i < _model->n_notes(); ++i) {
|
for (size_t i = 0; i < _model->n_notes(); ++i) {
|
||||||
add_note(_model->note_at(i));
|
add_note(_model->note_at(i));
|
||||||
|
|
@ -479,10 +476,10 @@ MidiRegionView::redisplay_model()
|
||||||
control = _model->controls().begin();
|
control = _model->controls().begin();
|
||||||
control != _model->controls().end(); ++control) {
|
control != _model->controls().end(); ++control) {
|
||||||
|
|
||||||
if( control->first.type() == MidiPgmChangeAutomation ) {
|
if ( control->first.type() == MidiPgmChangeAutomation ) {
|
||||||
Glib::Mutex::Lock list_lock (control->second->list()->lock());
|
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) {
|
event != control->second->list()->end(); ++event) {
|
||||||
boost::shared_ptr<MIDI::Event> midi_event(new MIDI::Event());
|
boost::shared_ptr<MIDI::Event> midi_event(new MIDI::Event());
|
||||||
MidiControlIterator iter(control->second->list(), (*event)->when, (*event)->value);
|
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();
|
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 y1 = midi_stream_view()->note_to_y(event->note()->note());
|
||||||
const double y2 = y1 + floor(midi_stream_view()->note_height());
|
const double y2 = y1 + floor(midi_stream_view()->note_height());
|
||||||
|
|
||||||
note->property_y1() = y1;
|
note->property_y1() = y1;
|
||||||
note->property_y2() = y2;
|
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)
|
double x = trackview.editor.frame_to_pixel((nframes_t)
|
||||||
event->note()->time() - _region->start());
|
event->note()->time() - _region->start());
|
||||||
const double diamond_size = midi_stream_view()->note_height() / 2.0;
|
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->move(x-hit->x1(), y-hit->y1());
|
||||||
hit->show();
|
hit->show();
|
||||||
}
|
}
|
||||||
if(event->selected()) {
|
if (event->selected()) {
|
||||||
event->show_velocity();
|
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);
|
assert(midi_view()->note_mode() == Sustained || midi_view()->note_mode() == Percussive);
|
||||||
|
|
||||||
// dont display notes beyond the region bounds
|
// dont display notes beyond the region bounds
|
||||||
if(
|
if (
|
||||||
note->time() - _region->start() >= _region->length() ||
|
note->time() - _region->start() >= _region->length() ||
|
||||||
note->time() < _region->start() ||
|
note->time() < _region->start() ||
|
||||||
note->note() < midi_stream_view()->lowest_note() ||
|
note->note() < midi_stream_view()->lowest_note() ||
|
||||||
|
|
@ -805,11 +802,11 @@ MidiRegionView::add_note(const boost::shared_ptr<Note> note)
|
||||||
event = 0;
|
event = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event) {
|
if (event) {
|
||||||
if(_marked_for_selection.find(event->note()) != _marked_for_selection.end()) {
|
if (_marked_for_selection.find(event->note()) != _marked_for_selection.end()) {
|
||||||
note_selected(event, true);
|
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);
|
assert(event->time() >= 0);
|
||||||
|
|
||||||
// dont display notes beyond the region bounds
|
// dont display notes beyond the region bounds
|
||||||
if(
|
if (
|
||||||
event->time() - _region->start() >= _region->length() ||
|
event->time() - _region->start() >= _region->length() ||
|
||||||
event->time() < _region->start()
|
event->time() < _region->start()
|
||||||
) {
|
) {
|
||||||
|
|
@ -997,7 +994,7 @@ MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, uint8_t dnote)
|
||||||
new_note_time += dt;
|
new_note_time += dt;
|
||||||
|
|
||||||
// keep notes inside region if dragged beyond left region bound
|
// 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();
|
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);
|
clamp_0_to_127(new_pitch);
|
||||||
|
|
||||||
//notes which are dragged beyond the standard midi range snap back to their original place
|
//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;
|
new_pitch = original_pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1032,7 +1029,7 @@ MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, uint8_t dnote)
|
||||||
apply_command();
|
apply_command();
|
||||||
|
|
||||||
// care about notes being moved beyond the upper/lower bounds on the canvas
|
// 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()
|
highest_note_in_selection > midi_stream_view()->highest_note()
|
||||||
) {
|
) {
|
||||||
midi_stream_view()->set_note_range(MidiStreamView::ContentsRange);
|
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);
|
CanvasNote *note = dynamic_cast<CanvasNote *> (*i);
|
||||||
|
|
||||||
// only insert CanvasNotes into the map
|
// only insert CanvasNotes into the map
|
||||||
if(note) {
|
if (note) {
|
||||||
NoteResizeData *resize_data = new NoteResizeData();
|
NoteResizeData *resize_data = new NoteResizeData();
|
||||||
resize_data->canvas_note = note;
|
resize_data->canvas_note = note;
|
||||||
|
|
||||||
|
|
@ -1122,7 +1119,7 @@ MidiRegionView::begin_resizing(CanvasNote::NoteEnd note_end)
|
||||||
|
|
||||||
resize_data->resize_rect = resize_rect;
|
resize_data->resize_rect = resize_rect;
|
||||||
|
|
||||||
if(note_end == CanvasNote::NOTE_ON) {
|
if (note_end == CanvasNote::NOTE_ON) {
|
||||||
resize_data->current_x = note->x1();
|
resize_data->current_x = note->x1();
|
||||||
} else { // NOTE_OFF
|
} else { // NOTE_OFF
|
||||||
resize_data->current_x = note->x2();
|
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();
|
const double region_start = get_position_pixels();
|
||||||
|
|
||||||
if(relative) {
|
if (relative) {
|
||||||
(*i)->current_x = (*i)->current_x + x;
|
(*i)->current_x = (*i)->current_x + x;
|
||||||
} else {
|
} else {
|
||||||
// x is in track relative, transform it to region relative
|
// 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;
|
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_x1() = snap_to_pixel(current_x);
|
||||||
resize_rect->property_x2() = canvas_note->x2();
|
resize_rect->property_x2() = canvas_note->x2();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1172,7 +1169,7 @@ MidiRegionView::commit_resizing(CanvasNote::NoteEnd note_end, double event_x, bo
|
||||||
double current_x = (*i)->current_x;
|
double current_x = (*i)->current_x;
|
||||||
const double position = get_position_pixels();
|
const double position = get_position_pixels();
|
||||||
|
|
||||||
if(!relative) {
|
if (!relative) {
|
||||||
// event_x is in track relative, transform it to region relative
|
// event_x is in track relative, transform it to region relative
|
||||||
current_x = event_x - position;
|
current_x = event_x - position;
|
||||||
}
|
}
|
||||||
|
|
@ -1221,7 +1218,7 @@ MidiRegionView::change_velocity(uint8_t velocity, bool relative)
|
||||||
CanvasNoteEvent *event = *i;
|
CanvasNoteEvent *event = *i;
|
||||||
const boost::shared_ptr<Note> copy(new Note(*(event->note().get())));
|
const boost::shared_ptr<Note> copy(new Note(*(event->note().get())));
|
||||||
|
|
||||||
if(relative) {
|
if (relative) {
|
||||||
uint8_t new_velocity = copy->velocity() + velocity;
|
uint8_t new_velocity = copy->velocity() + velocity;
|
||||||
clamp_0_to_127(new_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
|
// 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();
|
_marked_for_selection.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1266,7 +1263,7 @@ MidiRegionView::change_channel(uint8_t channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// dont keep notes selected if tweaking a single note
|
// 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();
|
_marked_for_selection.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1308,22 +1305,24 @@ MidiRegionView::set_frame_color()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MidiRegionView::midi_force_channel_changed(int8_t channel)
|
MidiRegionView::midi_channel_mode_changed(ChannelMode mode, uint16_t mask)
|
||||||
{
|
{
|
||||||
force_channel = channel;
|
switch (mode) {
|
||||||
}
|
case AllChannels:
|
||||||
|
case FilterChannels:
|
||||||
|
_force_channel = -1;
|
||||||
|
break;
|
||||||
|
case ForceChannel:
|
||||||
|
_force_channel = mask;
|
||||||
|
mask = 0xFFFF; // Show all notes as active (below)
|
||||||
|
};
|
||||||
|
|
||||||
void
|
// Update notes for selection
|
||||||
MidiRegionView::midi_channel_selection_changed(uint16_t selection)
|
for (std::vector<ArdourCanvas::CanvasNoteEvent*>::iterator i = _events.begin();
|
||||||
{
|
i != _events.end(); ++i) {
|
||||||
if(force_channel >= 0) {
|
(*i)->on_channel_selection_change(mask);
|
||||||
selection = 0xFFFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(std::vector<ArdourCanvas::CanvasNoteEvent*>::iterator i = _events.begin();
|
_last_channel_selection = mask;
|
||||||
i != _events.end();
|
|
||||||
++i) {
|
|
||||||
(*i)->on_channel_selection_change(selection);
|
|
||||||
}
|
|
||||||
last_channel_selection = selection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -241,16 +241,15 @@ class MidiRegionView : public RegionView
|
||||||
bool canvas_event(GdkEvent* ev);
|
bool canvas_event(GdkEvent* ev);
|
||||||
bool note_canvas_event(GdkEvent* ev);
|
bool note_canvas_event(GdkEvent* ev);
|
||||||
|
|
||||||
int8_t force_channel;
|
void midi_channel_mode_changed(ARDOUR::ChannelMode mode, uint16_t mask);
|
||||||
void midi_force_channel_changed(int8_t channel);
|
|
||||||
uint16_t last_channel_selection;
|
|
||||||
void midi_channel_selection_changed(uint16_t selection);
|
|
||||||
|
|
||||||
void clear_selection_except(ArdourCanvas::CanvasNoteEvent* ev);
|
void clear_selection_except(ArdourCanvas::CanvasNoteEvent* ev);
|
||||||
void clear_selection() { clear_selection_except(NULL); }
|
void clear_selection() { clear_selection_except(NULL); }
|
||||||
void update_drag_selection(double last_x, double x, double last_y, double y);
|
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;
|
boost::shared_ptr<ARDOUR::MidiModel> _model;
|
||||||
std::vector<ArdourCanvas::CanvasNoteEvent*> _events;
|
std::vector<ArdourCanvas::CanvasNoteEvent*> _events;
|
||||||
|
|
|
||||||
|
|
@ -144,13 +144,11 @@ MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shar
|
||||||
mem_fun(this, &MidiTimeAxisView::channel_selector_toggled));
|
mem_fun(this, &MidiTimeAxisView::channel_selector_toggled));
|
||||||
controls_vbox.pack_end(_midi_expander, SHRINK, 0);
|
controls_vbox.pack_end(_midi_expander, SHRINK, 0);
|
||||||
boost::shared_ptr<MidiDiskstream> diskstream = midi_track()->midi_diskstream();
|
boost::shared_ptr<MidiDiskstream> diskstream = midi_track()->midi_diskstream();
|
||||||
|
|
||||||
// restore channel selector settings
|
// restore channel selector settings
|
||||||
_channel_selector.set_selected_channels(diskstream->get_channel_mask());
|
_channel_selector.set_channel_mode(diskstream->get_channel_mode(), diskstream->get_channel_mask());
|
||||||
_channel_selector.set_force_channel(diskstream->get_force_channel());
|
_channel_selector.mode_changed.connect(
|
||||||
_channel_selector.selection_changed.connect(
|
mem_fun(*midi_track()->midi_diskstream(), &MidiDiskstream::set_channel_mode));
|
||||||
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));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,8 @@ class MidiTimeAxisView : public RouteTimeAxisView
|
||||||
|
|
||||||
void update_range();
|
void update_range();
|
||||||
|
|
||||||
sigc::signal<void, uint16_t>& signal_channel_selection_changed()
|
sigc::signal<void, ARDOUR::ChannelMode, uint16_t>& signal_channel_mode_changed()
|
||||||
{ return _channel_selector.selection_changed; }
|
{ return _channel_selector.mode_changed; }
|
||||||
|
|
||||||
sigc::signal<void, int8_t>& signal_force_channel_changed()
|
|
||||||
{ return _channel_selector.force_channel_changed; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,28 +90,27 @@ class MidiDiskstream : public Diskstream
|
||||||
|
|
||||||
void set_note_mode (NoteMode m);
|
void set_note_mode (NoteMode m);
|
||||||
|
|
||||||
void set_channel_mask(uint16_t channel_mask) {
|
|
||||||
_playback_buf->set_channel_mask(channel_mask);
|
|
||||||
_capture_buf->set_channel_mask(channel_mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t get_channel_mask() {
|
uint16_t get_channel_mask() {
|
||||||
uint16_t playback_mask = _playback_buf->get_channel_mask();
|
uint16_t playback_mask = _playback_buf->get_channel_mask();
|
||||||
|
#ifndef NDEBUG
|
||||||
uint16_t capture_mask = _capture_buf->get_channel_mask();
|
uint16_t capture_mask = _capture_buf->get_channel_mask();
|
||||||
assert(playback_mask == capture_mask);
|
assert(playback_mask == capture_mask);
|
||||||
|
#endif
|
||||||
return playback_mask;
|
return playback_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_force_channel(int8_t force_channel) {
|
void set_channel_mode(ChannelMode mode, uint16_t mask) {
|
||||||
_playback_buf->set_force_channel(force_channel);
|
_playback_buf->set_channel_mode(mode, mask);
|
||||||
_capture_buf->set_force_channel(force_channel);
|
_capture_buf->set_channel_mode(mode, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t get_force_channel() {
|
ChannelMode get_channel_mode() {
|
||||||
int8_t playback_force_channel = _playback_buf->get_force_channel();
|
ChannelMode playback_mode = _playback_buf->get_channel_mode();
|
||||||
int8_t capture_force_channel = _capture_buf->get_force_channel();
|
#ifndef NDEBUG
|
||||||
assert(playback_force_channel == capture_force_channel);
|
ChannelMode capture_mode = _capture_buf->get_channel_mode();
|
||||||
return playback_force_channel;
|
assert(playback_mode == capture_mode);
|
||||||
|
#endif
|
||||||
|
return playback_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ public:
|
||||||
|
|
||||||
if (w > r) {
|
if (w > r) {
|
||||||
return ((r - w + _size) % _size) - 1;
|
return ((r - w + _size) % _size) - 1;
|
||||||
} else if(w < r) {
|
} else if (w < r) {
|
||||||
return (r - w) - 1;
|
return (r - w) - 1;
|
||||||
} else {
|
} else {
|
||||||
return _size - 1;
|
return _size - 1;
|
||||||
|
|
@ -102,14 +102,16 @@ public:
|
||||||
size_t read(size_t size, T* dst);
|
size_t read(size_t size, T* dst);
|
||||||
bool full_read(size_t size, T* dst);
|
bool full_read(size_t size, T* dst);
|
||||||
|
|
||||||
|
bool skip(size_t size);
|
||||||
|
|
||||||
void write(size_t size, const T* src);
|
void write(size_t size, const T* src);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable gint _write_ptr;
|
mutable int _write_ptr;
|
||||||
mutable gint _read_ptr;
|
mutable int _read_ptr;
|
||||||
|
|
||||||
size_t _size; ///< Size (capacity) in bytes
|
size_t _size; ///< Size (capacity) in bytes
|
||||||
T* _buf; ///< size, event, size, event...
|
T* _buf; ///< size, event, size, event...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -191,6 +193,23 @@ MidiRingBufferBase<T>::full_read(size_t size, T* dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool
|
||||||
|
MidiRingBufferBase<T>::skip(size_t size)
|
||||||
|
{
|
||||||
|
if (read_space() < size) {
|
||||||
|
std::cerr << "WARNING: Attempt to skip past end of MIDI ring buffer" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr);
|
||||||
|
g_atomic_int_set(&_read_ptr, (priv_read_ptr + size) % _size);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void
|
inline void
|
||||||
MidiRingBufferBase<T>::write(size_t size, const T* src)
|
MidiRingBufferBase<T>::write(size_t size, const T* src)
|
||||||
|
|
@ -199,14 +218,14 @@ MidiRingBufferBase<T>::write(size_t size, const T* src)
|
||||||
|
|
||||||
if (priv_write_ptr + size <= _size) {
|
if (priv_write_ptr + size <= _size) {
|
||||||
memcpy(&_buf[priv_write_ptr], src, size);
|
memcpy(&_buf[priv_write_ptr], src, size);
|
||||||
g_atomic_int_set(&_write_ptr, (priv_write_ptr + size) % _size);
|
g_atomic_int_set(&_write_ptr, (priv_write_ptr + size) % _size);
|
||||||
} else {
|
} else {
|
||||||
const size_t this_size = _size - priv_write_ptr;
|
const size_t this_size = _size - priv_write_ptr;
|
||||||
assert(this_size < size);
|
assert(this_size < size);
|
||||||
assert(priv_write_ptr + this_size <= _size);
|
assert(priv_write_ptr + this_size <= _size);
|
||||||
memcpy(&_buf[priv_write_ptr], src, this_size);
|
memcpy(&_buf[priv_write_ptr], src, this_size);
|
||||||
memcpy(&_buf[0], src+this_size, size - this_size);
|
memcpy(&_buf[0], src+this_size, size - this_size);
|
||||||
g_atomic_int_set(&_write_ptr, size - this_size);
|
g_atomic_int_set(&_write_ptr, size - this_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,11 +242,10 @@ MidiRingBufferBase<T>::write(size_t size, const T* src)
|
||||||
*/
|
*/
|
||||||
class MidiRingBuffer : public MidiRingBufferBase<Byte> {
|
class MidiRingBuffer : public MidiRingBufferBase<Byte> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** @param size Size in bytes.
|
/** @param size Size in bytes.
|
||||||
*/
|
*/
|
||||||
MidiRingBuffer(size_t size)
|
MidiRingBuffer(size_t size)
|
||||||
: MidiRingBufferBase<Byte>(size), _channel_mask(0xFFFF), _force_channel(-1)
|
: MidiRingBufferBase<Byte>(size), _channel_mask(0x0000FFFF)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
size_t write(double time, size_t size, const Byte* buf);
|
size_t write(double time, size_t size, const Byte* buf);
|
||||||
|
|
@ -238,21 +256,24 @@ public:
|
||||||
|
|
||||||
size_t read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset=0);
|
size_t read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset=0);
|
||||||
|
|
||||||
/**
|
/** Set the channel filtering mode.
|
||||||
* @param channel_mask each bit in channel_mask represents a midi channel: bit 0 = channel 0,
|
* @param mask If mode is FilterChannels, each bit represents a midi channel:
|
||||||
* bit 1 = channel 1 etc. the read and write methods will only allow
|
* bit 0 = channel 0, bit 1 = channel 1 etc. the read and write methods will only
|
||||||
* events to pass, whose channel bit is 1.
|
* process events whose channel bit is 1.
|
||||||
|
* If mode is ForceChannel, mask is simply a channel number which all events will
|
||||||
|
* be forced to while reading.
|
||||||
*/
|
*/
|
||||||
void set_channel_mask(uint16_t channel_mask) { g_atomic_int_set(&_channel_mask, channel_mask); }
|
void set_channel_mode(ChannelMode mode, uint16_t mask) {
|
||||||
uint16_t get_channel_mask() { return g_atomic_int_get(&_channel_mask); }
|
g_atomic_int_set(&_channel_mask, ((uint16_t)mode << 16) | mask);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
ChannelMode get_channel_mode() const {
|
||||||
* @param channel if negative, forcing channels is deactivated and filtering channels
|
return static_cast<ChannelMode>((g_atomic_int_get(&_channel_mask) & 0xFFFF0000) >> 16);
|
||||||
* is activated, if positive, the LSB of channel is the channel number
|
}
|
||||||
* of the channel all events are forced into and filtering is deactivated
|
|
||||||
*/
|
uint16_t get_channel_mask() const {
|
||||||
void set_force_channel(int8_t channel) { g_atomic_int_set(&_force_channel, channel); }
|
return static_cast<ChannelMode>((g_atomic_int_get(&_channel_mask) & 0x0000FFFF));
|
||||||
int8_t get_force_channel() { return g_atomic_int_get(&_force_channel); }
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
inline bool is_channel_event(Byte event_type_byte) {
|
inline bool is_channel_event(Byte event_type_byte) {
|
||||||
|
|
@ -263,8 +284,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
volatile uint16_t _channel_mask;
|
volatile uint32_t _channel_mask; // 16 bits mode, 16 bits mask
|
||||||
volatile int8_t _force_channel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -308,17 +328,18 @@ MidiRingBuffer::read_contents(size_t size, Byte* buf)
|
||||||
inline size_t
|
inline size_t
|
||||||
MidiRingBuffer::write(double time, size_t size, const Byte* buf)
|
MidiRingBuffer::write(double time, size_t size, const Byte* buf)
|
||||||
{
|
{
|
||||||
//printf("MRB - write %#X %d %d with time %lf\n",
|
/*fprintf(stderr, "MRB %p write (t = %f) ", this, time);
|
||||||
// buf[0], buf[1], buf[2], time);
|
for (size_t i = 0; i < size; ++i)
|
||||||
|
fprintf(stderr, "%X", (char)buf[i]);
|
||||||
|
fprintf(stderr, "\n");*/
|
||||||
|
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
if(is_channel_event(buf[0]) && (g_atomic_int_get(&_force_channel) < 0)) {
|
// Don't write event if it doesn't match channel filter
|
||||||
// filter events for channels
|
if (is_channel_event(buf[0]) && get_channel_mode() == FilterChannels) {
|
||||||
Byte channel_nr = buf[0] & 0x0F;
|
Byte channel = buf[0] & 0x0F;
|
||||||
if( !(g_atomic_int_get(&_channel_mask) & (1L << channel_nr)) ) {
|
if ( !(get_channel_mask() & (1L << channel)) )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_space() < (sizeof(double) + sizeof(size_t) + size)) {
|
if (write_space() < (sizeof(double) + sizeof(size_t) + size)) {
|
||||||
|
|
@ -326,11 +347,11 @@ MidiRingBuffer::write(double time, size_t size, const Byte* buf)
|
||||||
} else {
|
} else {
|
||||||
MidiRingBufferBase<Byte>::write(sizeof(double), (Byte*)&time);
|
MidiRingBufferBase<Byte>::write(sizeof(double), (Byte*)&time);
|
||||||
MidiRingBufferBase<Byte>::write(sizeof(size_t), (Byte*)&size);
|
MidiRingBufferBase<Byte>::write(sizeof(size_t), (Byte*)&size);
|
||||||
if(is_channel_event(buf[0]) && (g_atomic_int_get(&_force_channel) >= 0)) {
|
if (is_channel_event(buf[0]) && get_channel_mode() == ForceChannel) {
|
||||||
assert(size == 3);
|
assert(size == 3);
|
||||||
Byte tmp_buf[3];
|
Byte tmp_buf[3];
|
||||||
//force event into channel
|
// Force event to channel
|
||||||
tmp_buf[0] = (buf[0] & 0xF0) | (g_atomic_int_get(&_force_channel) & 0x0F);
|
tmp_buf[0] = (buf[0] & 0xF0) | (get_channel_mask() & 0x0F);
|
||||||
tmp_buf[1] = buf[1];
|
tmp_buf[1] = buf[1];
|
||||||
tmp_buf[2] = buf[2];
|
tmp_buf[2] = buf[2];
|
||||||
MidiRingBufferBase<Byte>::write(size, tmp_buf);
|
MidiRingBufferBase<Byte>::write(size, tmp_buf);
|
||||||
|
|
@ -354,22 +375,23 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t
|
||||||
if (read_space() == 0)
|
if (read_space() == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
MIDI::Event ev;
|
double ev_time;
|
||||||
|
uint32_t ev_size;
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
|
||||||
//printf("MRB - read %u .. %u + %u\n", start, end, offset);
|
//printf("---- MRB read %u .. %u + %u\n", start, end, offset);
|
||||||
|
|
||||||
while (read_space() > sizeof(double) + sizeof(size_t)) {
|
while (read_space() > sizeof(double) + sizeof(size_t)) {
|
||||||
|
|
||||||
full_peek(sizeof(double), (Byte*)&ev.time());
|
full_peek(sizeof(double), (Byte*)&ev_time);
|
||||||
|
|
||||||
if (ev.time() > end)
|
if (ev_time > end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
bool success = MidiRingBufferBase<Byte>::full_read(sizeof(double), (Byte*)&ev.time());
|
bool success = MidiRingBufferBase<Byte>::full_read(sizeof(double), (Byte*)&ev_time);
|
||||||
if (success) {
|
if (success) {
|
||||||
success = MidiRingBufferBase<Byte>::full_read(sizeof(size_t), (Byte*)&ev.size());
|
success = MidiRingBufferBase<Byte>::full_read(sizeof(size_t), (Byte*)&ev_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
|
@ -377,51 +399,47 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Byte first_event_byte;
|
Byte status;
|
||||||
if(success) {
|
success = full_peek(sizeof(Byte), &status);
|
||||||
success = full_peek(sizeof(Byte), &first_event_byte);
|
assert(success); // If this failed, buffer is corrupt, all hope is lost
|
||||||
}
|
|
||||||
|
|
||||||
// could this ever happen???
|
// Ignore event if it doesn't match channel filter
|
||||||
if (!success) {
|
if (is_channel_event(status) && get_channel_mode() == FilterChannels) {
|
||||||
std::cerr << "MRB: PEEK ERROR (first event byte)" << std::endl;
|
const Byte channel = status & 0x0F;
|
||||||
continue;
|
if ( !(get_channel_mask() & (1L << channel)) ) {
|
||||||
}
|
skip(ev_size); // Advance read pointer to next event
|
||||||
|
|
||||||
// filter events for channels
|
|
||||||
// filtering is only active, if forcing channels is not active
|
|
||||||
if(is_channel_event(first_event_byte) && (g_atomic_int_get(&_force_channel) < 0)) {
|
|
||||||
Byte channel_nr = first_event_byte & 0x0F;
|
|
||||||
if( !(g_atomic_int_get(&_channel_mask) & (1L << channel_nr)) ) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.time() >= start) {
|
if (ev_time >= start) {
|
||||||
ev.time() -= start;
|
|
||||||
// TODO: Right now there come MIDI Events with empty buffer
|
/*std::cerr << "MRB " << this << " - Reading event, time = "
|
||||||
if(!ev.buffer()) {
|
<< ev_time << " - " << start << " => " << ev_time - start
|
||||||
std::cerr << "MidiRingBuffer::read WARNING: Skipping MIDI Event with NULL buffer pointer "
|
<< ", size = " << ev_size << std::endl;*/
|
||||||
<< " and length " << int(ev.size()) << std::endl;
|
|
||||||
|
ev_time -= start;
|
||||||
|
|
||||||
|
Byte* write_loc = dst.reserve(ev_time, ev_size);
|
||||||
|
if (write_loc == NULL) {
|
||||||
|
std::cerr << "MRB: Unable to reserve space in buffer, event skipped";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Byte* write_loc = dst.reserve(ev.time(), ev.size());
|
success = MidiRingBufferBase<Byte>::full_read(ev_size, write_loc);
|
||||||
|
|
||||||
success = MidiRingBufferBase<Byte>::full_read(ev.size(), write_loc);
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
if(is_channel_event(first_event_byte) && (g_atomic_int_get(&_force_channel) >= 0)) {
|
if (is_channel_event(status) && get_channel_mode() == ForceChannel) {
|
||||||
write_loc[0] = (write_loc[0] & 0xF0) | (g_atomic_int_get(&_force_channel) & 0x0F);
|
write_loc[0] = (write_loc[0] & 0xF0) | (get_channel_mask() & 0x0F);
|
||||||
}
|
}
|
||||||
++count;
|
++count;
|
||||||
//printf("MRB - read event at time %lf\n", ev.time());
|
//printf("MRB - read event at time %lf\n", ev_time);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "MRB: READ ERROR (data)" << std::endl;
|
std::cerr << "MRB: READ ERROR (data)" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("MRB - SKIPPING EVENT AT TIME %f\n", ev.time());
|
printf("MRB (start %u) - Skipping event at (too early) time %f\n", start, ev_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,12 @@ namespace ARDOUR {
|
||||||
Percussive
|
Percussive
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ChannelMode {
|
||||||
|
AllChannels = 0, ///< Pass through all channel information unmodified
|
||||||
|
FilterChannels, ///< Ignore events on certain channels
|
||||||
|
ForceChannel ///< Force all events to a certain channel
|
||||||
|
};
|
||||||
|
|
||||||
enum EventTimeUnit {
|
enum EventTimeUnit {
|
||||||
Frames,
|
Frames,
|
||||||
Beats
|
Beats
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ setup_enum_writer ()
|
||||||
MeterPoint _MeterPoint;
|
MeterPoint _MeterPoint;
|
||||||
TrackMode _TrackMode;
|
TrackMode _TrackMode;
|
||||||
NoteMode _NoteMode;
|
NoteMode _NoteMode;
|
||||||
|
ChannelMode _ChannelMode;
|
||||||
MeterFalloff _MeterFalloff;
|
MeterFalloff _MeterFalloff;
|
||||||
MeterHold _MeterHold;
|
MeterHold _MeterHold;
|
||||||
EditMode _EditMode;
|
EditMode _EditMode;
|
||||||
|
|
@ -141,6 +142,11 @@ setup_enum_writer ()
|
||||||
REGISTER_ENUM (Percussive);
|
REGISTER_ENUM (Percussive);
|
||||||
REGISTER (_NoteMode);
|
REGISTER (_NoteMode);
|
||||||
|
|
||||||
|
REGISTER_ENUM (AllChannels);
|
||||||
|
REGISTER_ENUM (FilterChannels);
|
||||||
|
REGISTER_ENUM (ForceChannel);
|
||||||
|
REGISTER (_ChannelMode);
|
||||||
|
|
||||||
REGISTER_ENUM (MeterFalloffOff);
|
REGISTER_ENUM (MeterFalloffOff);
|
||||||
REGISTER_ENUM (MeterFalloffSlowest);
|
REGISTER_ENUM (MeterFalloffSlowest);
|
||||||
REGISTER_ENUM (MeterFalloffSlow);
|
REGISTER_ENUM (MeterFalloffSlow);
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,10 @@ MidiBuffer::push_back(const jack_midi_event_t& ev)
|
||||||
Byte*
|
Byte*
|
||||||
MidiBuffer::reserve(double time, size_t size)
|
MidiBuffer::reserve(double time, size_t size)
|
||||||
{
|
{
|
||||||
assert(size <= MAX_EVENT_SIZE);
|
if (size > MAX_EVENT_SIZE) {
|
||||||
|
cerr << "WARNING: Failed to reserve " << size << " bytes for event";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (_size == _capacity)
|
if (_size == _capacity)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -1227,11 +1227,10 @@ MidiDiskstream::get_state ()
|
||||||
snprintf (buf, sizeof(buf), "0x%x", _flags);
|
snprintf (buf, sizeof(buf), "0x%x", _flags);
|
||||||
node->add_property ("flags", buf);
|
node->add_property ("flags", buf);
|
||||||
|
|
||||||
snprintf (buf, sizeof(buf), "0x%x", get_channel_mask());
|
node->add_property("channel-mode", enum_2_string(get_channel_mode()));
|
||||||
node->add_property("channel_mask", buf);
|
|
||||||
|
|
||||||
snprintf (buf, sizeof(buf), "%d", get_force_channel());
|
snprintf (buf, sizeof(buf), "0x%x", get_channel_mask());
|
||||||
node->add_property("force_channel", buf);
|
node->add_property("channel-mask", buf);
|
||||||
|
|
||||||
node->add_property ("playlist", _playlist->name());
|
node->add_property ("playlist", _playlist->name());
|
||||||
|
|
||||||
|
|
@ -1311,18 +1310,20 @@ MidiDiskstream::set_state (const XMLNode& node)
|
||||||
_flags = Flag (string_2_enum (prop->value(), _flags));
|
_flags = Flag (string_2_enum (prop->value(), _flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((prop = node.property ("channel_mask")) != 0) {
|
ChannelMode channel_mode = AllChannels;
|
||||||
unsigned int channel_mask;
|
if ((prop = node.property ("channel-mode")) != 0) {
|
||||||
sscanf (prop->value().c_str(), "0x%x", &channel_mask);
|
channel_mode = ChannelMode (string_2_enum(prop->value(), channel_mode));
|
||||||
set_channel_mask(channel_mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((prop = node.property ("force_channel")) != 0) {
|
unsigned int channel_mask = 0xFFFF;
|
||||||
int force_channel;
|
if ((prop = node.property ("channel-mask")) != 0) {
|
||||||
sscanf (prop->value().c_str(), "%d", &force_channel);
|
sscanf (prop->value().c_str(), "0x%x", &channel_mask);
|
||||||
set_force_channel(force_channel);
|
if (channel_mask & 0xFFFF)
|
||||||
|
warning << _("MidiDiskstream: XML property channel-mask out of range") << endmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_channel_mode(channel_mode, channel_mask);
|
||||||
|
|
||||||
if ((prop = node.property ("channels")) != 0) {
|
if ((prop = node.property ("channels")) != 0) {
|
||||||
nchans = atoi (prop->value().c_str());
|
nchans = atoi (prop->value().c_str());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -491,9 +491,6 @@ void MidiModel::append(const MIDI::Event& ev)
|
||||||
write_lock();
|
write_lock();
|
||||||
_edited = true;
|
_edited = true;
|
||||||
|
|
||||||
cerr << "MidiModel append event type: "
|
|
||||||
<< hex << "0x" << (int)ev.type() << endl;
|
|
||||||
|
|
||||||
assert(_notes.empty() || ev.time() >= _notes.back()->time());
|
assert(_notes.empty() || ev.time() >= _notes.back()->time());
|
||||||
assert(_writing);
|
assert(_writing);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -428,9 +428,6 @@ MidiTrack::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_fram
|
||||||
passthru (start_frame, end_frame, nframes, offset, 0, (_meter_point == MeterInput));
|
passthru (start_frame, end_frame, nframes, offset, 0, (_meter_point == MeterInput));
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop all sounds
|
|
||||||
midi_panic();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -571,10 +568,8 @@ MidiTrack::process_output_buffers (BufferSet& bufs,
|
||||||
IO::silence(nframes, offset);
|
IO::silence(nframes, offset);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
MidiBuffer& output_buf = bufs.get_midi(0);
|
// Write 'automation' controllers (e.g. CC events from a UI slider)
|
||||||
// TODO this crashes: (sends events with NULL buffer pointer)
|
write_controller_messages(bufs.get_midi(0), start_frame, end_frame, nframes, offset);
|
||||||
// Is this necessary anyway here? Dont know.
|
|
||||||
//write_controller_messages(output_buf, start_frame, end_frame, nframes, offset);
|
|
||||||
|
|
||||||
deliver_output(bufs, start_frame, end_frame, nframes, offset);
|
deliver_output(bufs, start_frame, end_frame, nframes, offset);
|
||||||
}
|
}
|
||||||
|
|
@ -706,13 +701,13 @@ MidiTrack::set_note_mode (NoteMode m)
|
||||||
void
|
void
|
||||||
MidiTrack::midi_panic()
|
MidiTrack::midi_panic()
|
||||||
{
|
{
|
||||||
for(uint8_t channel = 0; channel <= 0xF; channel++) {
|
for (uint8_t channel = 0; channel <= 0xF; channel++) {
|
||||||
Byte ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 };
|
Byte ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 };
|
||||||
write_immediate_event(3, ev);
|
write_immediate_event(3, ev);
|
||||||
ev[1] = MIDI_CTL_ALL_NOTES_OFF;
|
ev[1] = MIDI_CTL_ALL_NOTES_OFF;
|
||||||
write_immediate_event(3, ev);
|
write_immediate_event(3, ev);
|
||||||
ev[1] = MIDI_CTL_RESET_CONTROLLERS;
|
ev[1] = MIDI_CTL_RESET_CONTROLLERS;
|
||||||
write_immediate_event(3, ev);
|
write_immediate_event(3, ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -721,6 +716,11 @@ MidiTrack::midi_panic()
|
||||||
bool
|
bool
|
||||||
MidiTrack::write_immediate_event(size_t size, const Byte* buf)
|
MidiTrack::write_immediate_event(size_t size, const Byte* buf)
|
||||||
{
|
{
|
||||||
|
printf("Write immediate event: ");
|
||||||
|
for (size_t i=0; i < size; ++i) {
|
||||||
|
printf("%X ", buf[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
return (_immediate_events.write(0, size, buf) == size);
|
return (_immediate_events.write(0, size, buf) == size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -361,11 +361,11 @@ SMFSource::read_event(uint32_t* delta_t, uint32_t* size, Byte** buf) const
|
||||||
if (event_size > 1)
|
if (event_size > 1)
|
||||||
fread((*buf) + 1, 1, *size - 1, _fd);
|
fread((*buf) + 1, 1, *size - 1, _fd);
|
||||||
|
|
||||||
printf("SMFSource %s read event: delta = %u, size = %u, data = ", _name.c_str(), *delta_t, *size);
|
/*printf("SMFSource %s read event: delta = %u, size = %u, data = ", _name.c_str(), *delta_t, *size);
|
||||||
for (size_t i=0; i < *size; ++i) {
|
for (size_t i=0; i < *size; ++i) {
|
||||||
printf("%X ", (*buf)[i]);
|
printf("%X ", (*buf)[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");*/
|
||||||
|
|
||||||
return (int)*size;
|
return (int)*size;
|
||||||
}
|
}
|
||||||
|
|
@ -374,7 +374,7 @@ SMFSource::read_event(uint32_t* delta_t, uint32_t* size, Byte** buf) const
|
||||||
nframes_t
|
nframes_t
|
||||||
SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const
|
SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const
|
||||||
{
|
{
|
||||||
cerr << "SMF read_unlocked " << name() << " read " << start << ", count=" << cnt << ", offset=" << stamp_offset << endl;
|
//cerr << "SMF read_unlocked " << name() << " read " << start << ", count=" << cnt << ", offset=" << stamp_offset << endl;
|
||||||
|
|
||||||
// 64 bits ought to be enough for anybody
|
// 64 bits ought to be enough for anybody
|
||||||
uint64_t time = 0; // in SMF ticks, 1 tick per _ppqn
|
uint64_t time = 0; // in SMF ticks, 1 tick per _ppqn
|
||||||
|
|
|
||||||
|
|
@ -95,24 +95,27 @@ JACK_MidiPort::write(byte * msg, size_t msglen, timestamp_t timestamp)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
assert(_currently_in_cycle);
|
|
||||||
assert(_jack_output_port);
|
assert(_jack_output_port);
|
||||||
assert(timestamp < _nframes_this_cycle);
|
assert(timestamp < _nframes_this_cycle);
|
||||||
|
|
||||||
if (timestamp == 0) {
|
if (_currently_in_cycle) {
|
||||||
timestamp = _last_write_timestamp;
|
if (timestamp == 0) {
|
||||||
}
|
timestamp = _last_write_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
if (jack_midi_event_write (jack_port_get_buffer (_jack_output_port, _nframes_this_cycle),
|
if (jack_midi_event_write (jack_port_get_buffer (_jack_output_port, _nframes_this_cycle),
|
||||||
timestamp, msg, msglen) == 0) {
|
timestamp, msg, msglen) == 0) {
|
||||||
ret = msglen;
|
ret = msglen;
|
||||||
_last_write_timestamp = timestamp;
|
_last_write_timestamp = timestamp;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ret = 0;
|
||||||
|
cerr << "write of " << msglen << " failed, port holds "
|
||||||
|
<< jack_midi_get_event_count (jack_port_get_buffer (_jack_output_port, _nframes_this_cycle))
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = 0;
|
cerr << "write to JACK midi port failed: not currently in a process cycle." << endl;
|
||||||
cerr << "write of " << msglen << " failed, port holds "
|
|
||||||
<< jack_midi_get_event_count (jack_port_get_buffer (_jack_output_port, _nframes_this_cycle))
|
|
||||||
<< endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue