+ plug_id = id;
+ plug_page = page;
+ renew_plugin ();
+}
+
+void
+OSCSelectObserver::set_plugin_page (uint32_t page)
+{
+ plug_page = page;
+ renew_plugin ();
+}
+
+void
+OSCSelectObserver::set_plugin_size (uint32_t size)
+{
+ plug_page_size = size;
+ renew_plugin ();
+}
+
+void
+OSCSelectObserver::renew_plugin () {
+ plugin_connections.drop_connections ();
+ plugin_init();
+}
+
+void
+OSCSelectObserver::plugin_init()
+{
+ if (plug_id < 0) {
+ plugin_end ();
+ return;
+ }
+ boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
+ if (!r) {
+ plugin_end ();
+ return;
+ }
+
+ // we have a plugin number now get the processor
+ boost::shared_ptr<Processor> proc = r->nth_plugin (plug_id);
+ boost::shared_ptr<PluginInsert> pi;
+ if (!(pi = boost::dynamic_pointer_cast<PluginInsert>(proc))) {
+ plugin_end ();
+ return;
+ }
+ boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
+ // we have a plugin we can ask if it is activated
+ proc->ActiveChanged.connect (plugin_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::plug_enable, this, X_("/select/plugin/activate"), proc), OSC::instance());
+ _osc.float_message (X_("/select/plugin/activate"), proc->enabled(), addr);
+
+ bool ok = false;
+ // put only input controls into a vector
+ plug_params.clear ();
+ uint32_t nplug_params = pip->parameter_count();
+ for ( uint32_t ppi = 0; ppi < nplug_params; ++ppi) {
+ uint32_t controlid = pip->nth_parameter(ppi, ok);
+ if (!ok) {
+ continue;
+ }
+ if (pip->parameter_is_input(controlid)) {
+ plug_params.push_back (ppi);
+ }
+ }
+ nplug_params = plug_params.size ();
+
+ // default of 0 page size means show all
+ plug_size = nplug_params;
+ if (plug_page_size) {
+ plug_size = plug_page_size;
+ }
+ _osc.text_message (X_("/select/plugin/name"), pip->name(), addr);
+ uint32_t page_start = plug_page - 1;
+ uint32_t page_end = page_start + plug_size;
+
+ int pid = 1;
+ for ( uint32_t ppi = page_start; ppi < page_end; ++ppi, ++pid) {
+ if (ppi >= nplug_params) {
+ _osc.text_message_with_id (X_("/select/plugin/parameter/name"), pid, " ", in_line, addr);
+ _osc.float_message_with_id (X_("/select/plugin/parameter"), pid, 0, in_line, addr);
+ continue;
+ }
+
+ uint32_t controlid = pip->nth_parameter(plug_params[ppi], ok);
+ if (!ok) {
+ continue;
+ }
+ ParameterDescriptor pd;
+ pip->get_parameter_descriptor(controlid, pd);
+ _osc.text_message_with_id (X_("/select/plugin/parameter/name"), pid, pd.label, in_line, addr);
+ if ( pip->parameter_is_input(controlid)) {
+ boost::shared_ptr<AutomationControl> c = pi->automation_control(Evoral::Parameter(PluginAutomation, 0, controlid));
+ if (c) {
+ bool swtch = false;
+ if (pd.integer_step && pd.upper == 1) {
+ swtch = true;
+ }
+ c->Changed.connect (plugin_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::plugin_parameter_changed, this, pid, swtch, c), OSC::instance());
+ plugin_parameter_changed (pid, swtch, c);
+ }
+ }
+ }
+}
+
+void
+OSCSelectObserver::plugin_parameter_changed (int pid, bool swtch, boost::shared_ptr<PBD::Controllable> controllable)
+{
+ if (swtch) {
+ enable_message_with_id (X_("/select/plugin/parameter"), pid, controllable);
+ } else {
+ change_message_with_id (X_("/select/plugin/parameter"), pid, controllable);
+ }
+}
+
+void
+OSCSelectObserver::plugin_end ()
+{
+ plugin_connections.drop_connections ();
+ _osc.float_message (X_("/select/plugin/activate"), 0, addr);
+ _osc.text_message (X_("/select/plugin/name"), " ", addr);
+ for (uint32_t i = 1; i <= plug_size; i++) {
+ _osc.float_message_with_id (X_("/select/plugin/parameter"), i, 0, in_line, addr);
+ // next name
+ _osc.text_message_with_id (X_("/select/plugin/parameter/name"), i, " ", in_line, addr);
+ }
+ plug_size = 0;
+ nplug_params = 0;