diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2006-07-07 23:51:30 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2006-07-07 23:51:30 +0000 |
commit | 8b46567e0677eb25c965ed46b80da8808fa33b2b (patch) | |
tree | f34e3d1cbdab142e7f155d981fee5fb56a82c431 /libs/ardour/panner.cc | |
parent | 6f2e8de6a05d9d52069fa1f95c3264b5f151df5f (diff) |
id_t becomes a fully-fledged object, UUID's used for IDs, generic MIDI now owns bindings, MIDI binding concept removed from libardour itself in favor of generic Controllables
git-svn-id: svn://localhost/ardour2/trunk@669 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/panner.cc')
-rw-r--r-- | libs/ardour/panner.cc | 241 |
1 files changed, 20 insertions, 221 deletions
diff --git a/libs/ardour/panner.cc b/libs/ardour/panner.cc index 83c9e6eb4d..a56424cfea 100644 --- a/libs/ardour/panner.cc +++ b/libs/ardour/panner.cc @@ -53,21 +53,21 @@ float Panner::current_automation_version_number = 1.0; string EqualPowerStereoPanner::name = "Equal Power Stereo"; string Multi2dPanner::name = "Multiple (2D)"; -/* this is a default mapper of MIDI control values to a pan position - others can be imagined. see Panner::set_midi_to_pan_function(). +/* this is a default mapper of control values to a pan position + others can be imagined. */ -static pan_t direct_midi_to_pan (double fract) { +static pan_t direct_control_to_pan (double fract) { return fract; } -static double direct_pan_to_midi (pan_t val) { +static double direct_pan_to_control (pan_t val) { return val; } StreamPanner::StreamPanner (Panner& p) : parent (p), - _midi_control (*this, (MIDI::Port*) 0) + _control (*this) { _muted = false; @@ -80,84 +80,30 @@ StreamPanner::~StreamPanner () { } -StreamPanner::MIDIControl::MIDIControl (StreamPanner& s, MIDI::Port* port) - : MIDI::Controllable (port, 0), sp (s), setting(false) -{ - midi_to_pan = direct_midi_to_pan; - pan_to_midi = direct_pan_to_midi; - last_written = 0; /* XXX need a good out-of-bound-value */ -} - void -StreamPanner::MIDIControl::set_value (float val) +StreamPanner::PanControllable::set_value (float val) { - setting = true; - sp.set_position (midi_to_pan (val)); - setting = false; -} - -void -StreamPanner::MIDIControl::send_feedback (pan_t value) -{ - - if (!setting && get_midi_feedback() && pan_to_midi) { - MIDI::byte val = (MIDI::byte) (pan_to_midi (value) * 127.0f); - MIDI::channel_t ch = 0; - MIDI::eventType ev = MIDI::none; - MIDI::byte additional = 0; - MIDI::EventTwoBytes data; - - if (get_control_info (ch, ev, additional)) { - data.controller_number = additional; - data.value = val; - last_written = val; - - sp.get_parent().session().send_midi_message (get_port(), ev, ch, data); - } - - // send_midi_feedback (pan_to_midi (val)); - } - + panner.set_position (direct_control_to_pan (val)); } -MIDI::byte* -StreamPanner::MIDIControl::write_feedback (MIDI::byte* buf, int32_t& bufsize, pan_t val, bool force) +float +StreamPanner::PanControllable::get_value (void) const { - if (get_midi_feedback() && pan_to_midi && bufsize > 2) { - MIDI::channel_t ch = 0; - MIDI::eventType ev = MIDI::none; - MIDI::byte additional = 0; - MIDI::byte pm; - if (get_control_info (ch, ev, additional)) { - - pm = (MIDI::byte) (pan_to_midi (val) * 127.0); - - if (pm != last_written || force) { - *buf++ = (0xF0 & ev) | (0xF & ch); - *buf++ = additional; /* controller number */ - *buf++ = pm; - last_written = pm; - bufsize -= 3; - } - } - } - - return buf; + float xpos; + panner.get_effective_position (xpos); + return direct_pan_to_control (xpos); } - -void -StreamPanner::reset_midi_control (MIDI::Port* port, bool on) +bool +StreamPanner::PanControllable::can_send_feedback () const { - MIDI::channel_t chn; - MIDI::eventType ev; - MIDI::byte extra; + AutoState astate = panner.get_parent().automation_state (); - _midi_control.get_control_info (chn, ev, extra); - if (!on) { - chn = -1; + if ((astate == Play) || (astate == Touch && !panner.get_parent().touching())) { + return true; } - _midi_control.midi_rebind (port, chn); + + return false; } void @@ -180,10 +126,7 @@ StreamPanner::set_position (float xpos, bool link_call) x = xpos; update (); Changed (); - - if (parent.session().get_midi_feedback()) { - _midi_control.send_feedback (x); - } + _control.Changed (); } } @@ -224,42 +167,11 @@ StreamPanner::set_state (const XMLNode& node) { const XMLProperty* prop; XMLNodeConstIterator iter; - XMLNodeList midi_kids; if ((prop = node.property (X_("muted")))) { set_muted (prop->value() == "yes"); } - midi_kids = node.children ("MIDI"); - - for (iter = midi_kids.begin(); iter != midi_kids.end(); ++iter) { - - XMLNodeList kids; - XMLNodeConstIterator miter; - XMLNode* child; - - kids = (*iter)->children (); - - for (miter = kids.begin(); miter != kids.end(); ++miter) { - - child =* miter; - - if (child->name() == "pan") { - - MIDI::eventType ev = MIDI::on; /* initialize to keep gcc happy */ - MIDI::byte additional = 0; /* ditto */ - MIDI::channel_t chn = 0; /* ditto */ - - if (get_midi_node_info (child, ev, chn, additional)) { - _midi_control.set_control_type (chn, ev, additional); - } else { - error << _("MIDI pan control specification is incomplete, so it has been ignored") << endmsg; - } - } - } - } - - return 0; } @@ -267,68 +179,6 @@ void StreamPanner::add_state (XMLNode& node) { node.add_property (X_("muted"), (muted() ? "yes" : "no")); - - /* MIDI control */ - - MIDI::channel_t chn; - MIDI::eventType ev; - MIDI::byte additional; - XMLNode* midi_node = 0; - XMLNode* child; - - if (_midi_control.get_control_info (chn, ev, additional)) { - - midi_node = node.add_child ("MIDI"); - - child = midi_node->add_child ("pan"); - set_midi_node_info (child, ev, chn, additional); - } - -} - - -bool -StreamPanner::get_midi_node_info (XMLNode * node, MIDI::eventType & ev, MIDI::channel_t & chan, MIDI::byte & additional) -{ - bool ok = true; - const XMLProperty* prop; - int xx; - - if ((prop = node->property ("event")) != 0) { - sscanf (prop->value().c_str(), "0x%x", &xx); - ev = (MIDI::eventType) xx; - } else { - ok = false; - } - - if (ok && ((prop = node->property ("channel")) != 0)) { - sscanf (prop->value().c_str(), "%d", &xx); - chan = (MIDI::channel_t) xx; - } else { - ok = false; - } - - if (ok && ((prop = node->property ("additional")) != 0)) { - sscanf (prop->value().c_str(), "0x%x", &xx); - additional = (MIDI::byte) xx; - } - - return ok; -} - -bool -StreamPanner::set_midi_node_info (XMLNode * node, MIDI::eventType ev, MIDI::channel_t chan, MIDI::byte additional) -{ - char buf[32]; - - snprintf (buf, sizeof(buf), "0x%x", ev); - node->add_property ("event", buf); - snprintf (buf, sizeof(buf), "%d", chan); - node->add_property ("channel", buf); - snprintf (buf, sizeof(buf), "0x%x", additional); - node->add_property ("additional", buf); - - return true; } /*---------------------------------------------------------------------- */ @@ -959,8 +809,6 @@ Panner::Panner (string name, Session& s) _linked = false; _link_direction = SameDirection; _bypassed = false; - - reset_midi_control (_session.mmc_port(), _session.get_mmc_control()); } Panner::~Panner () @@ -1107,8 +955,6 @@ Panner::reset (uint32_t nouts, uint32_t npans) (*x)->update (); } - reset_midi_control (_session.mmc_port(), _session.get_mmc_control()); - /* force hard left/right panning in a common case: 2in/2out */ @@ -1490,14 +1336,6 @@ Panner::touching () const } void -Panner::reset_midi_control (MIDI::Port* port, bool on) -{ - for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) { - (*i)->reset_midi_control (port, on); - } -} - -void Panner::set_position (float xpos, StreamPanner& orig) { float xnow; @@ -1639,42 +1477,3 @@ Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig) } } } - -void -Panner::send_all_midi_feedback () -{ - if (_session.get_midi_feedback()) { - float xpos; - - // do feedback for all panners - for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) { - (*i)->get_effective_position (xpos); - - (*i)->midi_control().send_feedback (xpos); - } - - } -} - -MIDI::byte* -Panner::write_midi_feedback (MIDI::byte* buf, int32_t& bufsize) -{ - AutoState astate = automation_state (); - - if (_session.get_midi_feedback() && - (astate == Play || (astate == Touch && !touching()))) { - - float xpos; - - // do feedback for all panners - for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) { - (*i)->get_effective_position (xpos); - - buf = (*i)->midi_control().write_feedback (buf, bufsize, xpos); - } - - } - - return buf; -} - |