mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-06 21:55:43 +01:00
'Channel safe' MIDI:
Resolve note on/off pairs in MidiModel. Add channel field to Parameter (for associating a channel with a CC list). Add channel selector to 'add controller automation' dialog. Write out note and CC MIDI events with proper channel. git-svn-id: svn://localhost/ardour2/branches/3.0@3085 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
466500fdaf
commit
b79d5bfad3
7 changed files with 52 additions and 91 deletions
|
|
@ -95,6 +95,7 @@ mtc_slave.cc
|
|||
named_selection.cc
|
||||
note.cc
|
||||
panner.cc
|
||||
parameter.cc
|
||||
pcm_utils.cc
|
||||
playlist.cc
|
||||
playlist_factory.cc
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace ARDOUR {
|
|||
*/
|
||||
class Note {
|
||||
public:
|
||||
Note(double time=0, double dur=0, uint8_t note=0, uint8_t vel=0x40);
|
||||
Note(uint8_t chan=0, double time=0, double dur=0, uint8_t note=0, uint8_t vel=0x40);
|
||||
Note(const Note& copy);
|
||||
|
||||
const Note& operator=(const Note& copy);
|
||||
|
|
|
|||
|
|
@ -48,85 +48,32 @@ namespace ARDOUR {
|
|||
class Parameter
|
||||
{
|
||||
public:
|
||||
inline Parameter(AutomationType type = NullAutomation, uint32_t id=0) : _type(type), _id(id) {}
|
||||
Parameter(AutomationType type = NullAutomation, uint32_t id=0, uint8_t channel=0)
|
||||
: _type(type), _id(id), _channel(channel)
|
||||
{}
|
||||
|
||||
/** Construct an Parameter from a string returned from Parameter::to_string
|
||||
* (AutomationList automation-id property)
|
||||
*/
|
||||
Parameter(const std::string& str) : _type(NullAutomation), _id(0) {
|
||||
if (str == "gain") {
|
||||
_type = GainAutomation;
|
||||
} else if (str == "solo") {
|
||||
_type = SoloAutomation;
|
||||
} else if (str == "mute") {
|
||||
_type = MuteAutomation;
|
||||
} else if (str == "fadein") {
|
||||
_type = FadeInAutomation;
|
||||
} else if (str == "fadeout") {
|
||||
_type = FadeOutAutomation;
|
||||
} else if (str == "envelope") {
|
||||
_type = EnvelopeAutomation;
|
||||
} else if (str == "pan") {
|
||||
_type = PanAutomation;
|
||||
} else if (str.length() > 4 && str.substr(0, 4) == "pan-") {
|
||||
_type = PanAutomation;
|
||||
_id = atoi(str.c_str()+4);
|
||||
} else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
|
||||
_type = PluginAutomation;
|
||||
_id = atoi(str.c_str()+10);
|
||||
} else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
|
||||
_type = MidiCCAutomation;
|
||||
_id = atoi(str.c_str()+7);
|
||||
} else {
|
||||
PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
|
||||
}
|
||||
Parameter(const std::string& str);
|
||||
|
||||
inline AutomationType type() const { return _type; }
|
||||
inline uint32_t id() const { return _id; }
|
||||
inline uint8_t channel() const { return _channel; }
|
||||
|
||||
inline bool operator==(const Parameter& id) const {
|
||||
return (_type == id._type && _id == id._id);
|
||||
}
|
||||
|
||||
inline AutomationType type() const { return _type; }
|
||||
inline uint32_t id() const { return _id; }
|
||||
|
||||
inline bool operator==(const Parameter& id) const
|
||||
{ return (_type == id._type && _id == id._id); }
|
||||
|
||||
/** Arbitrary but fixed ordering, so we're comparable (usable in std::map) */
|
||||
/** Arbitrary but fixed ordering (for use in e.g. std::map) */
|
||||
inline bool operator<(const Parameter& id) const {
|
||||
#ifndef NDEBUG
|
||||
if (_type == NullAutomation)
|
||||
PBD::warning << "Uninitialized Parameter compared." << endmsg;
|
||||
#endif
|
||||
return (_type < id._type || _id < id._id);
|
||||
return (_channel < id._channel || _type < id._type || _id < id._id);
|
||||
}
|
||||
|
||||
inline operator bool() const { return (_type != 0); }
|
||||
|
||||
/** Unique string representation, suitable as an XML property value.
|
||||
* e.g. <AutomationList automation-id="whatthisreturns">
|
||||
*/
|
||||
inline std::string to_string() const {
|
||||
if (_type == GainAutomation) {
|
||||
return "gain";
|
||||
} else if (_type == PanAutomation) {
|
||||
return string_compose("pan-%1", _id);
|
||||
} else if (_type == SoloAutomation) {
|
||||
return "solo";
|
||||
} else if (_type == MuteAutomation) {
|
||||
return "mute";
|
||||
} else if (_type == FadeInAutomation) {
|
||||
return "fadein";
|
||||
} else if (_type == FadeOutAutomation) {
|
||||
return "fadeout";
|
||||
} else if (_type == EnvelopeAutomation) {
|
||||
return "envelope";
|
||||
} else if (_type == PluginAutomation) {
|
||||
return string_compose("parameter-%1", _id);
|
||||
} else if (_type == MidiCCAutomation) {
|
||||
return string_compose("midicc-%1", _id);
|
||||
} else {
|
||||
assert(false);
|
||||
PBD::warning << "Uninitialized Parameter to_string() called." << endmsg;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
std::string to_string() const;
|
||||
|
||||
/* The below properties are only used for CC right now, but unchanging properties
|
||||
* of parameters (rather than changing parameters of automation lists themselves)
|
||||
|
|
@ -154,6 +101,7 @@ private:
|
|||
// default copy constructor is ok
|
||||
AutomationType _type;
|
||||
uint32_t _id;
|
||||
uint8_t _channel;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -304,9 +304,10 @@ MidiModel::control_to_midi_event(MidiEvent& ev, const MidiControlIterator& iter)
|
|||
ev.set_buffer((Byte*)malloc(3), true);
|
||||
|
||||
assert(iter.first);
|
||||
assert(iter.first->parameter().channel() < 16);
|
||||
assert(iter.first->parameter().id() <= INT8_MAX);
|
||||
assert(iter.second.second <= INT8_MAX);
|
||||
ev.buffer()[0] = MIDI_CMD_CONTROL;
|
||||
ev.buffer()[0] = MIDI_CMD_CONTROL + iter.first->parameter().channel();
|
||||
ev.buffer()[1] = (Byte)iter.first->parameter().id();
|
||||
ev.buffer()[2] = (Byte)iter.second.second;
|
||||
ev.time() = iter.second.first; // x
|
||||
|
|
@ -412,7 +413,7 @@ MidiModel::append_note_on_unlocked(uint8_t chan, double time, uint8_t note_num,
|
|||
assert(chan < 16);
|
||||
assert(_writing);
|
||||
|
||||
_notes.push_back(boost::shared_ptr<Note>(new Note(time, 0, note_num, velocity)));
|
||||
_notes.push_back(boost::shared_ptr<Note>(new Note(chan, time, 0, note_num, velocity)));
|
||||
if (_note_mode == Sustained) {
|
||||
//cerr << "MM Sustained: Appending active note on " << (unsigned)(uint8_t)note_num << endl;
|
||||
_write_notes[chan].push_back(_notes.size() - 1);
|
||||
|
|
@ -471,10 +472,7 @@ MidiModel::append_cc_unlocked(uint8_t chan, double time, uint8_t number, uint8_t
|
|||
assert(chan < 16);
|
||||
assert(_writing);
|
||||
|
||||
if (chan != 0) // FIXME
|
||||
cerr << "WARNING: CC on non-0 channel, channel information lost!" << endl;
|
||||
|
||||
Parameter param(MidiCCAutomation, number);
|
||||
Parameter param(MidiCCAutomation, number, chan);
|
||||
|
||||
boost::shared_ptr<AutomationControl> control = Automatable::control(param, true);
|
||||
control->list()->fast_simple_add(time, (double)value);
|
||||
|
|
|
|||
|
|
@ -22,15 +22,17 @@
|
|||
|
||||
namespace ARDOUR {
|
||||
|
||||
Note::Note(double t, double d, uint8_t n, uint8_t v)
|
||||
Note::Note(uint8_t chan, double t, double d, uint8_t n, uint8_t v)
|
||||
: _on_event(t, 3, NULL, true)
|
||||
, _off_event(t + d, 3, NULL, true)
|
||||
{
|
||||
_on_event.buffer()[0] = MIDI_CMD_NOTE_ON;
|
||||
assert(chan < 16);
|
||||
|
||||
_on_event.buffer()[0] = MIDI_CMD_NOTE_ON + chan;
|
||||
_on_event.buffer()[1] = n;
|
||||
_on_event.buffer()[2] = v;
|
||||
|
||||
_off_event.buffer()[0] = MIDI_CMD_NOTE_OFF;
|
||||
_off_event.buffer()[0] = MIDI_CMD_NOTE_OFF + chan;
|
||||
_off_event.buffer()[1] = n;
|
||||
_off_event.buffer()[2] = 0x40;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue