C++ implementation of fan_out_instrument.lua
authorRobin Gareus <robin@gareus.org>
Thu, 10 Nov 2016 03:54:03 +0000 (04:54 +0100)
committerRobin Gareus <robin@gareus.org>
Thu, 10 Nov 2016 03:54:59 +0000 (04:54 +0100)
gtk2_ardour/mixer_strip.cc
gtk2_ardour/route_ui.cc
gtk2_ardour/route_ui.h

index c26b18942a26146c5b69399723d3b3d87bf73b79..12a0d837ad7424128b39b3738d17e32bf78ccee9 100644 (file)
@@ -1696,6 +1696,11 @@ MixerStrip::build_route_ops_menu ()
                items.push_back (MenuElem (_("Pin Connections..."), sigc::mem_fun (*this, &RouteUI::manage_pins)));
        }
 
+       if (_route->the_instrument () && _route->the_instrument ()->output_streams().n_audio() > 2) {
+               // TODO ..->n_audio() > 1 && separate_output_groups) hard to check here every time.
+               items.push_back (MenuElem (_("Fan Out Instrument"), sigc::bind (sigc::mem_fun (*this, &RouteUI::fan_out), false)));
+       }
+
        items.push_back (SeparatorElem());
        items.push_back (MenuElem (_("Adjust Latency..."), sigc::mem_fun (*this, &RouteUI::adjust_latency)));
 
index 9f204a59fcae71b8a5404114c9c4cce805de2298..ed8873def77677545f1c271ba0ac4fd1ff7bbfc4 100644 (file)
@@ -17,6 +17,7 @@
 
 */
 
+#include <map>
 #include <boost/algorithm/string.hpp>
 
 #include <gtkmm2ext/gtk_ui.h>
 #include "ardour/vca.h"
 #include "ardour/vca_manager.h"
 #include "ardour/audio_track.h"
+#include "ardour/audio_port.h"
 #include "ardour/audioengine.h"
 #include "ardour/filename_extensions.h"
 #include "ardour/midi_track.h"
 #include "ardour/monitor_control.h"
 #include "ardour/internal_send.h"
+#include "ardour/panner_shell.h"
 #include "ardour/profile.h"
 #include "ardour/phase_control.h"
 #include "ardour/send.h"
@@ -2334,6 +2337,54 @@ RouteUI::manage_pins ()
        }
 }
 
+void
+RouteUI::fan_out (bool to_busses)
+{
+       boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ());
+       assert (pi);
+
+       const uint32_t n_outputs = pi->output_streams ().n_audio ();
+       if (_route->n_outputs ().n_audio () != n_outputs) {
+               MessageDialog msg (string_compose (
+                                       _("The Plugin's number of audio outputs ports (%1) does not match the Tracks's number of audio outputs (%2). Cannot fan out."),
+                                       n_outputs, _route->n_outputs ().n_audio ()));
+               msg.run ();
+               return;
+       }
+       boost::shared_ptr<Plugin> plugin = pi->plugin ();
+       std::map<std::string, uint32_t> busnames;
+       for (uint32_t p = 0; p < n_outputs; ++p) {
+               const Plugin::IOPortDescription& pd (plugin->describe_io_port (DataType::AUDIO, false, p));
+               std::string bn = pi->name () + " " + pd.group_name;
+               busnames[bn]++;
+       }
+
+       if (busnames.size () < 2) {
+               MessageDialog msg (_("Instrument has only 1 output bus. Nothing to fan out."));
+               msg.run ();
+               return;
+       }
+
+       uint32_t outputs = 2;
+       if (_session->master_out ()) {
+               outputs = std::max (outputs, _session->master_out ()->n_inputs ().n_audio ());
+       }
+
+       _route->output ()->disconnect (this);
+       _route->panner_shell ()->set_bypassed (true);
+
+       for (uint32_t p = 0; p < n_outputs; ++p) {
+               const Plugin::IOPortDescription& pd (plugin->describe_io_port (DataType::AUDIO, false, p));
+               std::string bn = pi->name () + " " + pd.group_name;
+               boost::shared_ptr<Route> r = _session->route_by_name (bn);
+               if (!r) {
+                       RouteList rl = _session->new_audio_route (busnames[bn], outputs, NULL, 1, bn, PresentationInfo::AudioBus, PresentationInfo::max_order);
+                       r = rl.front ();
+               }
+               _route->output ()->audio (p)->connect (r->input ()->audio (pd.group_channel).get());
+       }
+}
+
 bool
 RouteUI::mark_hidden (bool yn)
 {
index e05db7f67708f4f7b633f91b4e4a368af1225425..41d11fe6c4f0866c8e6285290d727e4979c689c1 100644 (file)
@@ -208,6 +208,7 @@ class RouteUI : public virtual ARDOUR::SessionHandlePtr, public virtual PBD::Sco
 
        void manage_pins ();
        void maybe_add_route_print_mgr ();
+       void fan_out (bool to_busses = true);
 
        virtual void route_property_changed (const PBD::PropertyChange&) = 0;
        void route_removed ();