diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2009-12-11 02:00:22 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2009-12-11 02:00:22 +0000 |
commit | 2983f8de97412b4887394747abed59fa11a11cff (patch) | |
tree | d8e43dfc53beca04f39ed9745de11491d9ba4844 /libs/surfaces/generic_midi | |
parent | 29a8238e4d34f1f15aec0b55e98bee080cf8fec5 (diff) |
(MAY BREAK COMPILATION - unfinished work, being transferred between machines via svn) ... start to make MidiControllable bind to a URI, not an object
git-svn-id: svn://localhost/ardour2/branches/3.0@6346 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/surfaces/generic_midi')
-rw-r--r-- | libs/surfaces/generic_midi/midicontrollable.cc | 79 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/midicontrollable.h | 11 |
2 files changed, 67 insertions, 23 deletions
diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc index 92000a6dee..8b2077fb5b 100644 --- a/libs/surfaces/generic_midi/midicontrollable.cc +++ b/libs/surfaces/generic_midi/midicontrollable.cc @@ -32,8 +32,25 @@ using namespace MIDI; using namespace PBD; using namespace ARDOUR; +MIDIControllable::MIDIControllable (Port& p, const string& c, bool is_bistate) + : controllable (0), _port (p), bistate (is_bistate) +{ + init (); +} + MIDIControllable::MIDIControllable (Port& p, Controllable& c, bool is_bistate) - : controllable (c), _port (p), bistate (is_bistate) + : controllable (&c), _current_uri (c.uri()), _port (p), bistate (is_bistate) +{ + init (); +} + +MIDIControllable::~MIDIControllable () +{ + drop_external_control (); +} + +void +MIDIControllable::init () { setting = false; last_value = 0; // got a better idea ? @@ -48,11 +65,6 @@ MIDIControllable::MIDIControllable (Port& p, Controllable& c, bool is_bistate) midi_rebind (0); } -MIDIControllable::~MIDIControllable () -{ - drop_external_control (); -} - void MIDIControllable::midi_forget () { @@ -74,6 +86,12 @@ MIDIControllable::midi_forget () } void +MIDIControllable::reacquire_controllable () +{ + _controllable = Controllable::controllable_by_uri (current_uri); +} + +void MIDIControllable::midi_rebind (channel_t c) { if (c >= 0) { @@ -162,8 +180,12 @@ MIDIControllable::midi_sense_note_off (Parser &p, EventTwoBytes *tb) void MIDIControllable::midi_sense_note (Parser &, EventTwoBytes *msg, bool is_on) { + if (!controllable) { + return; + } + if (!bistate) { - controllable.set_value (msg->note_number/127.0); + controllable->set_value (msg->note_number/127.0); } else { /* Note: parser handles the use of zero velocity to @@ -176,51 +198,62 @@ MIDIControllable::midi_sense_note (Parser &, EventTwoBytes *msg, bool is_on) } } - last_value = (MIDI::byte) (controllable.get_value() * 127.0); // to prevent feedback fights + last_value = (MIDI::byte) (controllable->get_value() * 127.0); // to prevent feedback fights } void MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg) { - if (controllable.touching()) { + if (!controllable) { + return; + } + + if (controllable->touching()) { return; // to prevent feedback fights when e.g. dragging a UI slider } if (control_additional == msg->controller_number) { if (!bistate) { - controllable.set_value (midi_to_control(msg->value)); + controllable->set_value (midi_to_control(msg->value)); } else { if (msg->value > 64.0) { - controllable.set_value (1); + controllable->set_value (1); } else { - controllable.set_value (0); + controllable->set_value (0); } } - last_value = (MIDI::byte) (control_to_midi(controllable.get_value())); // to prevent feedback fights + last_value = (MIDI::byte) (control_to_midi(controllable->get_value())); // to prevent feedback fights } } void MIDIControllable::midi_sense_program_change (Parser &, byte msg) { + if (!controllable) { + return; + } /* XXX program change messages make no sense for bistates */ if (!bistate) { - controllable.set_value (msg/127.0); - last_value = (MIDI::byte) (controllable.get_value() * 127.0); // to prevent feedback fights + controllable->set_value (msg/127.0); + last_value = (MIDI::byte) (controllable->get_value() * 127.0); // to prevent feedback fights } } void MIDIControllable::midi_sense_pitchbend (Parser &, pitchbend_t pb) { + if (!controllable) { + return; + } + /* pitchbend messages make no sense for bistates */ /* XXX gack - get rid of assumption about typeof pitchbend_t */ - controllable.set_value ((pb/(float) SHRT_MAX)); - last_value = (MIDI::byte) (controllable.get_value() * 127.0); // to prevent feedback fights + controllable->set_value ((pb/(float) SHRT_MAX)); + last_value = (MIDI::byte) (controllable->get_value() * 127.0); // to prevent feedback fights } void @@ -240,7 +273,7 @@ MIDIControllable::midi_receiver (Parser &, byte *msg, size_t /*len*/) bind_midi ((channel_t) (msg[0] & 0xf), eventType (msg[0] & 0xF0), msg[1]); - controllable.LearningFinished (); + controllable->LearningFinished (); } void @@ -336,7 +369,7 @@ MIDIControllable::send_feedback () msg[0] = (control_type & 0xF0) | (control_channel & 0xF); msg[1] = control_additional; - msg[2] = (byte) (control_to_midi(controllable.get_value())); + msg[2] = (byte) (control_to_midi(controllable->get_value())); _port.write (msg, 3, 0); } @@ -346,7 +379,7 @@ MIDIControllable::write_feedback (MIDI::byte* buf, int32_t& bufsize, bool /*forc { if (control_type != none && feedback && bufsize > 2) { - MIDI::byte gm = (MIDI::byte) (control_to_midi(controllable.get_value())); + MIDI::byte gm = (MIDI::byte) (control_to_midi(controllable->get_value())); if (gm != last_value) { *buf++ = (0xF0 & control_type) | (0xF & control_channel); @@ -401,8 +434,12 @@ MIDIControllable::set_state (const XMLNode& node, int /*version*/) XMLNode& MIDIControllable::get_state () { + if (!controllable) { + return XXX !what!; + } + char buf[32]; - XMLNode& node (controllable.get_state ()); + XMLNode& node (controllable->get_state ()); snprintf (buf, sizeof(buf), "0x%x", (int) control_type); node.add_property ("event", buf); diff --git a/libs/surfaces/generic_midi/midicontrollable.h b/libs/surfaces/generic_midi/midicontrollable.h index 4aabd696b0..7b84c9b60a 100644 --- a/libs/surfaces/generic_midi/midicontrollable.h +++ b/libs/surfaces/generic_midi/midicontrollable.h @@ -41,8 +41,11 @@ class MIDIControllable : public PBD::Stateful { public: MIDIControllable (MIDI::Port&, PBD::Controllable&, bool bistate = false); + MIDIControllable (MIDI::Port&, const std::string& uri, bool bistate = false); virtual ~MIDIControllable (); + bool ok() const { return !_current_uri.empty(); } + void send_feedback (); MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool force = false); @@ -59,7 +62,7 @@ class MIDIControllable : public PBD::Stateful float midi_to_control(float val); MIDI::Port& get_port() const { return _port; } - PBD::Controllable& get_controllable() const { return controllable; } + PBD::Controllable* get_controllable() const { return controllable; } std::string control_description() const { return _control_description; } @@ -70,8 +73,10 @@ class MIDIControllable : public PBD::Stateful MIDI::channel_t get_control_channel () { return control_channel; } MIDI::eventType get_control_type () { return control_type; } MIDI::byte get_control_additional () { return control_additional; } + private: - PBD::Controllable& controllable; + PBD::Controllable* controllable; + std::string _current_uri; MIDI::Port& _port; bool setting; MIDI::byte last_value; @@ -85,6 +90,8 @@ class MIDIControllable : public PBD::Stateful MIDI::channel_t control_channel; std::string _control_description; bool feedback; + + void reacquire_controllable (); void midi_receiver (MIDI::Parser &p, MIDI::byte *, size_t); void midi_sense_note (MIDI::Parser &, MIDI::EventTwoBytes *, bool is_on); |