+#ifdef LV2_EXTENDED
+ // Intercept Automation Write Events
+ if ((flags & PORT_AUTOCTRL)) {
+ LV2_Atom* atom = (LV2_Atom*)(data - sizeof(LV2_Atom));
+ if (atom->type == _uri_map.urids.atom_Blank ||
+ atom->type == _uri_map.urids.atom_Object) {
+ LV2_Atom_Object* obj = (LV2_Atom_Object*)atom;
+ if (obj->body.otype == _uri_map.urids.auto_event) {
+ // only if transport_rolling ??
+ const LV2_Atom* parameter = NULL;
+ const LV2_Atom* value = NULL;
+ lv2_atom_object_get(obj,
+ _uri_map.urids.auto_parameter, ¶meter,
+ _uri_map.urids.auto_value, &value,
+ 0);
+ if (parameter && value) {
+ const uint32_t p = ((const LV2_Atom_Int*)parameter)->body;
+ const float v = ((const LV2_Atom_Float*)value)->body;
+ // -> add automation event..
+ DEBUG_TRACE(DEBUG::LV2Automate,
+ string_compose ("Event p: %1 t: %2 v: %3\n", p, frames, v));
+ AutomationCtrlPtr c = get_automation_control (p);
+ if (c &&
+ (c->ac->automation_state() == Touch || c->ac->automation_state() == Write)
+ ) {
+ framepos_t when = std::max ((framepos_t) 0, start + frames - _current_latency);
+ assert (start + frames - _current_latency >= 0);
+ if (c->guard) {
+ c->guard = false;
+ c->ac->list()->add (when, v, true, true);
+ } else {
+ c->ac->set_double (v, when, true);
+ }
+ }
+ }
+ }
+ else if (obj->body.otype == _uri_map.urids.auto_setup) {
+ // TODO optional arguments, for now we assume the plugin
+ // writes automation for its own inputs
+ // -> put them in "touch" mode (preferably "exclusive plugin touch(TM)"
+ for (AutomationCtrlMap::iterator i = _ctrl_map.begin(); i != _ctrl_map.end(); ++i) {
+ if (_port_flags[i->first] & PORT_CTRLED) {
+ DEBUG_TRACE(DEBUG::LV2Automate,
+ string_compose ("Setup p: %1\n", i->first));
+ i->second->ac->set_automation_state (Touch);
+ }
+ }
+ }
+ else if (obj->body.otype == _uri_map.urids.auto_finalize) {
+ // set [touched] parameters to "play" ??
+ // allow plugin to change its mode (from analyze to apply)
+ const LV2_Atom* parameter = NULL;
+ const LV2_Atom* value = NULL;
+ lv2_atom_object_get(obj,
+ _uri_map.urids.auto_parameter, ¶meter,
+ _uri_map.urids.auto_value, &value,
+ 0);
+ if (parameter && value) {
+ const uint32_t p = ((const LV2_Atom_Int*)parameter)->body;
+ const float v = ((const LV2_Atom_Float*)value)->body;
+ AutomationCtrlPtr c = get_automation_control (p);
+ DEBUG_TRACE(DEBUG::LV2Automate,
+ string_compose ("Finalize p: %1 v: %2\n", p, v));
+ if (c && _port_flags[p] & PORT_CTRLER) {
+ c->ac->set_value(v, Controllable::NoGroup);
+ }
+ } else {
+ DEBUG_TRACE(DEBUG::LV2Automate, "Finalize\n");
+ }
+ for (AutomationCtrlMap::iterator i = _ctrl_map.begin(); i != _ctrl_map.end(); ++i) {
+ // guard will be false if an event was written
+ if ((_port_flags[i->first] & PORT_CTRLED) && !i->second->guard) {
+ DEBUG_TRACE(DEBUG::LV2Automate,
+ string_compose ("Thin p: %1\n", i->first));
+ i->second->ac->alist ()->thin (20);
+ }
+ }
+ }
+ else if (obj->body.otype == _uri_map.urids.auto_start) {
+ const LV2_Atom* parameter = NULL;
+ lv2_atom_object_get(obj,
+ _uri_map.urids.auto_parameter, ¶meter,
+ 0);
+ if (parameter) {
+ const uint32_t p = ((const LV2_Atom_Int*)parameter)->body;
+ AutomationCtrlPtr c = get_automation_control (p);
+ DEBUG_TRACE(DEBUG::LV2Automate, string_compose ("Start Touch p: %1\n", p));
+ if (c) {
+ c->ac->start_touch (std::max ((framepos_t)0, start - _current_latency));
+ c->guard = true;
+ }
+ }
+ }
+ else if (obj->body.otype == _uri_map.urids.auto_end) {
+ const LV2_Atom* parameter = NULL;
+ lv2_atom_object_get(obj,
+ _uri_map.urids.auto_parameter, ¶meter,
+ 0);
+ if (parameter) {
+ const uint32_t p = ((const LV2_Atom_Int*)parameter)->body;
+ AutomationCtrlPtr c = get_automation_control (p);
+ DEBUG_TRACE(DEBUG::LV2Automate, string_compose ("End Touch p: %1\n", p));
+ if (c) {
+ c->ac->stop_touch (true, std::max ((framepos_t)0, start - _current_latency));
+ }
+ }
+ }
+ }
+ }
+#endif
+ // Intercept state dirty message
+ if (_has_state_interface /* && (flags & PORT_DIRTYMSG)*/) {
+ LV2_Atom* atom = (LV2_Atom*)(data - sizeof(LV2_Atom));
+ if (atom->type == _uri_map.urids.atom_Blank ||
+ atom->type == _uri_map.urids.atom_Object) {
+ LV2_Atom_Object* obj = (LV2_Atom_Object*)atom;
+ if (obj->body.otype == _uri_map.urids.state_StateChanged) {
+ _session.set_dirty ();
+ }
+ }
+ }
+