+ if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
+ return boost::shared_ptr<Plugin> (new LadspaPlugin (*lp));
+ } else if ((lua = boost::dynamic_pointer_cast<LuaProc> (other)) != 0) {
+ return boost::shared_ptr<Plugin> (new LuaProc (*lua));
+#ifdef LV2_SUPPORT
+ } else if ((lv2p = boost::dynamic_pointer_cast<LV2Plugin> (other)) != 0) {
+ return boost::shared_ptr<Plugin> (new LV2Plugin (*lv2p));
+#endif
+#ifdef WINDOWS_VST_SUPPORT
+ } else if ((vp = boost::dynamic_pointer_cast<WindowsVSTPlugin> (other)) != 0) {
+ return boost::shared_ptr<Plugin> (new WindowsVSTPlugin (*vp));
+#endif
+#ifdef LXVST_SUPPORT
+ } else if ((lxvp = boost::dynamic_pointer_cast<LXVSTPlugin> (other)) != 0) {
+ return boost::shared_ptr<Plugin> (new LXVSTPlugin (*lxvp));
+#endif
+#ifdef AUDIOUNIT_SUPPORT
+ } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
+ return boost::shared_ptr<Plugin> (new AUPlugin (*ap));
+#endif
+ }
+
+ fatal << string_compose (_("programming error: %1"),
+ X_("unknown plugin type in PluginInsert::plugin_factory"))
+ << endmsg;
+ abort(); /*NOTREACHED*/
+ return boost::shared_ptr<Plugin> ((Plugin*) 0);
+}
+
+void
+PluginInsert::set_input_map (uint32_t num, ChanMapping m) {
+ if (num < _in_map.size()) {
+ bool changed = _in_map[num] != m;
+ _in_map[num] = m;
+ changed |= sanitize_maps ();
+ if (changed) {
+ PluginMapChanged (); /* EMIT SIGNAL */
+ _mapping_changed = true;
+ _session.set_dirty();
+ }
+ }
+}
+
+void
+PluginInsert::set_output_map (uint32_t num, ChanMapping m) {
+ if (num < _out_map.size()) {
+ bool changed = _out_map[num] != m;
+ _out_map[num] = m;
+ changed |= sanitize_maps ();
+ if (changed) {
+ PluginMapChanged (); /* EMIT SIGNAL */
+ _mapping_changed = true;
+ _session.set_dirty();
+ }
+ }
+}
+
+void
+PluginInsert::set_thru_map (ChanMapping m) {
+ bool changed = _thru_map != m;
+ _thru_map = m;
+ changed |= sanitize_maps ();
+ if (changed) {
+ PluginMapChanged (); /* EMIT SIGNAL */
+ _mapping_changed = true;
+ _session.set_dirty();
+ }
+}
+
+bool
+PluginInsert::pre_seed (const ChanCount& in, const ChanCount& out,
+ const ChanMapping& im, const ChanMapping& om, const ChanMapping& tm)
+{
+ if (_configured) { return false; }
+ _configured_in = in;
+ _configured_out = out;
+ _in_map[0] = im;
+ _out_map[0] = om;
+ _thru_map = tm;
+ _maps_from_state = in.n_total () > 0 && out.n_total () > 0;
+ return true;
+}
+
+ChanMapping
+PluginInsert::input_map () const
+{
+ ChanMapping rv;
+ uint32_t pc = 0;
+ for (PinMappings::const_iterator i = _in_map.begin (); i != _in_map.end (); ++i, ++pc) {
+ ChanMapping m (i->second);
+ const ChanMapping::Mappings& mp ((*i).second.mappings());
+ for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
+ for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
+ rv.set (tm->first, i->first + pc * natural_input_streams().get(tm->first), i->second);
+ }
+ }
+ }
+ return rv;
+}
+
+ChanMapping
+PluginInsert::output_map () const
+{
+ ChanMapping rv;
+ uint32_t pc = 0;
+ for (PinMappings::const_iterator i = _out_map.begin (); i != _out_map.end (); ++i, ++pc) {
+ ChanMapping m (i->second);
+ const ChanMapping::Mappings& mp ((*i).second.mappings());
+ for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
+ for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
+ rv.set (tm->first, i->first + pc * natural_output_streams().get(tm->first), i->second);
+ }
+ }
+ }
+ if (has_midi_bypass ()) {
+ rv.set (DataType::MIDI, 0, 0);
+ }
+
+ return rv;
+}
+
+bool
+PluginInsert::has_midi_bypass () const
+{
+ if (_configured_in.n_midi () == 1 && _configured_out.n_midi () == 1
+ && natural_output_streams ().n_midi () == 0) {
+ return true;
+ }
+ return false;
+}
+
+bool
+PluginInsert::has_midi_thru () const
+{
+ if (_configured_in.n_midi () == 1 && _configured_out.n_midi () == 1
+ && natural_input_streams ().n_midi () == 0 && natural_output_streams ().n_midi () == 0) {
+ return true;
+ }
+ return false;
+}
+
+#ifdef MIXBUS
+bool
+PluginInsert::is_channelstrip () const {
+ return _plugins.front()->is_channelstrip();
+}
+#endif
+
+bool
+PluginInsert::check_inplace ()
+{
+ bool inplace_ok = !_plugins.front()->inplace_broken ();
+
+ if (_thru_map.n_total () > 0) {
+ // TODO once midi-bypass is part of the mapping, ignore it
+ inplace_ok = false;
+ }
+
+ if (_match.method == Split && inplace_ok) {
+ assert (get_count() == 1);
+ assert (_in_map.size () == 1);
+ if (!_out_map[0].is_monotonic ()) {
+ inplace_ok = false;
+ }
+ if (_configured_internal != _configured_in) {
+ /* no sidechain -- TODO we could allow this with
+ * some more logic in PluginInsert::connect_and_run().
+ *
+ * PluginInsert::reset_map() already maps it.
+ */
+ inplace_ok = false;
+ }
+ /* check mapping */
+ for (DataType::iterator t = DataType::begin(); t != DataType::end() && inplace_ok; ++t) {
+ if (_configured_internal.get (*t) == 0) {
+ continue;
+ }
+ bool valid;
+ uint32_t first_idx = _in_map[0].get (*t, 0, &valid);
+ if (!valid || first_idx != 0) {
+ // so far only allow to copy the *first* stream's buffer to others
+ inplace_ok = false;
+ } else {
+ for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
+ uint32_t idx = _in_map[0].get (*t, i, &valid);
+ if (valid && idx != first_idx) {
+ inplace_ok = false;
+ break;
+ }
+ }
+ }
+ }
+
+ if (inplace_ok) {
+ DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: In Place Split Map\n", name()));
+ return false;
+ }
+ }
+
+ for (uint32_t pc = 0; pc < get_count() && inplace_ok ; ++pc) {
+ if (!_in_map[pc].is_monotonic ()) {
+ inplace_ok = false;
+ }
+ if (!_out_map[pc].is_monotonic ()) {
+ inplace_ok = false;
+ }
+ }
+ DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: %2\n", name(), inplace_ok ? "In-Place" : "No Inplace Processing"));
+ return !inplace_ok; // no-inplace
+}
+
+bool
+PluginInsert::sanitize_maps ()
+{
+ bool changed = false;
+ /* strip dead wood */
+ PinMappings new_ins;
+ PinMappings new_outs;
+ ChanMapping new_thru;
+
+ for (uint32_t pc = 0; pc < get_count(); ++pc) {
+ ChanMapping new_in;
+ ChanMapping new_out;
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+ for (uint32_t i = 0; i < natural_input_streams().get (*t); ++i) {
+ bool valid;
+ uint32_t idx = _in_map[pc].get (*t, i, &valid);
+ if (valid && idx < _configured_internal.get (*t)) {
+ new_in.set (*t, i, idx);
+ }
+ }
+ for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
+ bool valid;
+ uint32_t idx = _out_map[pc].get (*t, o, &valid);
+ if (valid && idx < _configured_out.get (*t)) {
+ new_out.set (*t, o, idx);
+ }
+ }
+ }
+ if (_in_map[pc] != new_in || _out_map[pc] != new_out) {
+ changed = true;
+ }
+ new_ins[pc] = new_in;
+ new_outs[pc] = new_out;
+ }
+
+ /* prevent dup output assignments */
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+ for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
+ bool mapped = false;
+ for (uint32_t pc = 0; pc < get_count(); ++pc) {
+ bool valid;
+ uint32_t idx = new_outs[pc].get_src (*t, o, &valid);
+ if (valid && mapped) {
+ new_outs[pc].unset (*t, idx);
+ } else if (valid) {
+ mapped = true;
+ }
+ }
+ }
+ }
+
+ /* remove excess thru */
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+ for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
+ bool valid;
+ uint32_t idx = _thru_map.get (*t, o, &valid);
+ if (valid && idx < _configured_internal.get (*t)) {
+ new_thru.set (*t, o, idx);
+ }
+ }
+ }
+
+ /* prevent out + thru, existing plugin outputs override thru */
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+ for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
+ bool mapped = false;
+ bool valid;
+ for (uint32_t pc = 0; pc < get_count(); ++pc) {
+ new_outs[pc].get_src (*t, o, &mapped);
+ if (mapped) { break; }
+ }
+ if (!mapped) { continue; }
+ uint32_t idx = new_thru.get (*t, o, &valid);
+ if (mapped) {
+ new_thru.unset (*t, idx);
+ }
+ }
+ }
+
+ if (has_midi_bypass ()) {
+ // TODO: include midi-bypass in the thru set,
+ // remove dedicated handling.
+ new_thru.unset (DataType::MIDI, 0);
+ }
+
+ if (_in_map != new_ins || _out_map != new_outs || _thru_map != new_thru) {
+ changed = true;
+ }
+ _in_map = new_ins;
+ _out_map = new_outs;
+ _thru_map = new_thru;
+
+ return changed;
+}
+
+bool
+PluginInsert::reset_map (bool emit)
+{
+ const PinMappings old_in (_in_map);
+ const PinMappings old_out (_out_map);
+
+ _in_map.clear ();
+ _out_map.clear ();
+ _thru_map = ChanMapping ();
+
+ /* build input map */
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+ uint32_t sc = 0; // side-chain round-robin (all instances)
+ uint32_t pc = 0;
+ for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
+ const uint32_t nis = natural_input_streams ().get(*t);
+ const uint32_t stride = nis - sidechain_input_pins().get (*t);
+
+ /* SC inputs are last in the plugin-insert.. */
+ const uint32_t sc_start = _configured_in.get (*t);
+ const uint32_t sc_len = _configured_internal.get (*t) - sc_start;
+ /* ...but may not be at the end of the plugin ports.
+ * in case the side-chain is not the last port, shift connections back.
+ * and connect to side-chain
+ */
+ uint32_t shift = 0;
+ uint32_t ic = 0; // split inputs
+ const uint32_t cend = _configured_in.get (*t);
+
+ for (uint32_t in = 0; in < nis; ++in) {
+ const Plugin::IOPortDescription& iod (_plugins[pc]->describe_io_port (*t, true, in));
+ if (iod.is_sidechain) {
+ /* connect sidechain sinks to sidechain inputs in round-robin fashion */
+ if (sc_len > 0) {// side-chain may be hidden
+ _in_map[pc].set (*t, in, sc_start + sc);
+ sc = (sc + 1) % sc_len;
+ }
+ ++shift;
+ } else {
+ if (_match.method == Split) {
+ if (cend == 0) { continue; }
+ if (_strict_io && ic + stride * pc >= cend) {
+ break;
+ }
+ /* connect *no* sidechain sinks in round-robin fashion */
+ _in_map[pc].set (*t, in, ic + stride * pc);
+ if (_strict_io && (ic + 1) == cend) {
+ break;
+ }
+ ic = (ic + 1) % cend;
+ } else {
+ uint32_t s = in - shift;
+ if (stride * pc + s < cend) {
+ _in_map[pc].set (*t, in, s + stride * pc);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* build output map */
+ uint32_t pc = 0;
+ for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
+ _out_map[pc] = ChanMapping (ChanCount::min (natural_output_streams(), _configured_out));
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+ _out_map[pc].offset_to(*t, pc * natural_output_streams().get(*t));
+ }