Vkeybd: add a mod-wheel
[ardour.git] / gtk2_ardour / port_group.cc
index 808ddc4ee00275dc982921787c9ba6e7d9f6585e..ab7feb618539c0cc827395d32e5bcbfff5ad8f7a 100644 (file)
@@ -1,21 +1,24 @@
 /*
-    Copyright (C) 2002-2009 Paul Davis
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
+ * Copyright (C) 2009-2018 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2012-2016 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2016 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include <cstring>
 #include <boost/shared_ptr.hpp>
@@ -23,6 +26,7 @@
 
 #include "midi++/mmc.h"
 
+#include "ardour/async_midi_port.h"
 #include "ardour/audioengine.h"
 #include "ardour/auditioner.h"
 #include "ardour/bundle.h"
 #include "ardour/io_processor.h"
 #include "ardour/midi_port.h"
 #include "ardour/midiport_manager.h"
+#include "ardour/plugin_insert.h"
 #include "ardour/port.h"
 #include "ardour/profile.h"
 #include "ardour/session.h"
+#include "ardour/sidechain.h"
 #include "ardour/user_bundle.h"
 
 #include "control_protocol/control_protocol.h"
@@ -337,6 +343,7 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
 
        boost::shared_ptr<PortGroup> bus (new PortGroup (string_compose (_("%1 Busses"), PROGRAM_NAME)));
        boost::shared_ptr<PortGroup> track (new PortGroup (string_compose (_("%1 Tracks"), PROGRAM_NAME)));
+       boost::shared_ptr<PortGroup> sidechain (new PortGroup (string_compose (_("%1 Sidechains"), PROGRAM_NAME)));
        boost::shared_ptr<PortGroup> system (new PortGroup (_("Hardware")));
        boost::shared_ptr<PortGroup> program (new PortGroup (string_compose (_("%1 Misc"), PROGRAM_NAME)));
        boost::shared_ptr<PortGroup> other (new PortGroup (_("Other")));
@@ -351,11 +358,11 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
 
        for (RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
 
-                /* we never show the monitor bus inputs */
+               /* we never show the monitor bus inputs */
 
-                if (inputs && (*i)->is_monitor()) {
-                        continue;
-                }
+               if (inputs && (*i)->is_monitor()) {
+                       continue;
+               }
 
                /* keep track of IOs that we have taken bundles from,
                   so that we can avoid taking the same IO from both
@@ -378,7 +385,7 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
        /* Now put the bundles that belong to these sorted RouteIOs into the PortGroup. */
 
        for (list<RouteIOs>::iterator i = route_ios.begin(); i != route_ios.end(); ++i) {
-               TimeAxisView* tv = PublicEditor::instance().axis_view_from_stripable (i->route);
+               TimeAxisView* tv = PublicEditor::instance().time_axis_view_from_stripable (i->route);
 
                /* Work out which group to put these IOs' bundles in */
                boost::shared_ptr<PortGroup> g;
@@ -399,6 +406,25 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
                                }
                        }
                }
+
+               /* When on input side, let's look for sidechains in the route's plugins
+                  to display them right next to their route */
+               for (uint32_t n = 0; inputs; ++n) {
+                       boost::shared_ptr<Processor> p = (i->route)->nth_plugin (n);
+                       if (!p) {
+                               break;
+                       }
+                       boost::shared_ptr<SideChain> sc = boost::static_pointer_cast<PluginInsert> (p)->sidechain ();
+
+                       if (sc) {
+                               boost::shared_ptr<IO> io = sc->input();
+                               if (tv) {
+                                       sidechain->add_bundle (io->bundle(), io, tv->color ());
+                               } else {
+                                       sidechain->add_bundle (io->bundle(), io);
+                               }
+                       }
+               }
        }
 
        /* Bundles owned by the session; add user bundles first, then normal ones, so
@@ -436,9 +462,10 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
                        ltc->add_channel (_("LTC Out"), DataType::AUDIO, session->engine().make_port_name_non_relative (session->ltc_output_port()->name()));
                        program->add_bundle (ltc);
                } else {
-                       boost::shared_ptr<Bundle> ltc (new Bundle (_("LTC In"), inputs));
-                       ltc->add_channel (_("LTC In"), DataType::AUDIO, session->engine().make_port_name_non_relative (session->ltc_input_port()->name()));
-                       program->add_bundle (ltc);
+                       // XXX TRANSPORTMASTERS
+                       //boost::shared_ptr<Bundle> ltc (new Bundle (_("LTC In"), inputs));
+                       // ltc->add_channel (_("LTC In"), DataType::AUDIO, session->engine().make_port_name_non_relative (session->ltc_input_port()->name()));
+                       // program->add_bundle (ltc);
                }
        }
 
@@ -463,6 +490,15 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
                }
        }
 
+       /* virtual keyboard */
+       if (!inputs && (type == DataType::MIDI || type == DataType::NIL)) {
+               boost::shared_ptr<ARDOUR::Port> ap = boost::dynamic_pointer_cast<ARDOUR::Port> (session->vkbd_output_port());
+               AudioEngine* ae = AudioEngine::instance();
+               boost::shared_ptr<Bundle> vm (new Bundle (_("Virtual MIDI"), inputs));
+               vm->add_channel (_("Virtual Keyboard"), DataType::MIDI, ae->make_port_name_non_relative (ap->name()));
+               program->add_bundle (vm);
+       }
+
        /* our sync ports */
 
        if ((type == DataType::MIDI || type == DataType::NIL)) {
@@ -470,12 +506,13 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
                AudioEngine* ae = AudioEngine::instance();
 
                if (inputs) {
-                       sync->add_channel (
-                               _("MTC in"), DataType::MIDI, ae->make_port_name_non_relative (session->mtc_input_port()->name())
-                               );
-                       sync->add_channel (
-                               _("MIDI clock in"), DataType::MIDI, ae->make_port_name_non_relative (session->midi_clock_input_port()->name())
-                               );
+                       // XXX TRANSPORTMASTER
+                       // sync->add_channel (
+                       // _("MTC in"), DataType::MIDI, ae->make_port_name_non_relative (session->mtc_input_port()->name())
+                       // );
+                       // sync->add_channel (
+                       // _("MIDI clock in"), DataType::MIDI, ae->make_port_name_non_relative (session->midi_clock_input_port()->name())
+                       //);
                        sync->add_channel (
                                _("MMC in"), DataType::MIDI, ae->make_port_name_non_relative (session->mmc_input_port()->name())
                                );
@@ -500,10 +537,10 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
        std::vector<std::string> extra_program[DataType::num_types];
        std::vector<std::string> extra_other[DataType::num_types];
 
-        string lpn (PROGRAM_NAME);
-        boost::to_lower (lpn);
-        string lpnc = lpn;
-        lpnc += ':';
+       string lpn (PROGRAM_NAME);
+       boost::to_lower (lpn);
+       string lpnc = lpn;
+       lpnc += ':';
 
        vector<string> ports;
        if (type == DataType::NIL) {
@@ -526,32 +563,35 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
                        if (!system->has_port(p) &&
                            !bus->has_port(p) &&
                            !track->has_port(p) &&
+                           !sidechain->has_port(p) &&
                            !program->has_port(p) &&
                            !other->has_port(p)) {
 
-                                /* special hack: ignore MIDI ports labelled Midi-Through. these
-                                   are basically useless and mess things up for default
-                                   connections.
-                                */
+                               /* special hack: ignore MIDI ports labelled Midi-Through. these
+                                  are basically useless and mess things up for default
+                                  connections.
+                               */
 
                                if (p.find ("Midi-Through") != string::npos || p.find ("Midi Through") != string::npos) {
-                                        ++s;
-                                        continue;
-                                }
+                                       ++s;
+                                       continue;
+                               }
 
-                                /* special hack: ignore our monitor inputs (which show up here because
-                                   we excluded them earlier.
-                                */
+                               /* special hack: ignore our monitor inputs (which show up here because
+                                  we excluded them earlier.
+                               */
 
-                                string lp = p, monitor = _("Monitor");
-                                boost::to_lower (lp);
-                                boost::to_lower (monitor);
+                               string lp = p;
+                               string monitor = _("Monitor");
 
-                                if ((lp.find (monitor) != string::npos) &&
-                                    (lp.find (lpn) != string::npos)) {
-                                        ++s;
-                                        continue;
-                                }
+                               boost::to_lower (lp);
+                               boost::to_lower (monitor);
+
+                               if ((lp.find (monitor) != string::npos) &&
+                                   (lp.find (lpn) != string::npos)) {
+                                       ++s;
+                                       continue;
+                               }
 
                                /* can't use the audio engine for this as we
                                 * are looking at ports not owned by the
@@ -560,29 +600,35 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
                                 */
 
                                PortEngine::PortHandle ph = AudioEngine::instance()->port_engine().get_port_by_name (p);
-                               if (ph) {
-                                       DataType t (AudioEngine::instance()->port_engine().port_data_type (ph));
-                                       if (t != DataType::NIL) {
-                                               if (port_has_prefix (p, X_("system:")) ||
-                                                   port_has_prefix (p, X_("alsa_pcm:")) ||
-                                                   port_has_prefix (p, X_("alsa_midi:"))) {
-                                                       extra_system[t].push_back (p);
-                                               } else if (port_has_prefix (p, lpnc)) {
-
-                                                       /* we own this port (named after the program) */
-
-                                                       /* Hide scene ports from non-Tracks Live builds */
-                                                       if (!ARDOUR::Profile->get_trx()) {
-                                                               if (p.find (_("Scene ")) != string::npos) {
-                                                                       ++s;
-                                                                       continue;
-                                                               }
-                                                       }
-
-                                                       extra_program[t].push_back (p);
-                                               } else {
-                                                       extra_other[t].push_back (p);
+
+                               if (!ph) {
+                                       continue;
+                               }
+
+                               DataType t (AudioEngine::instance()->port_engine().port_data_type (ph));
+
+                               if (t != DataType::NIL) {
+
+                                       PortFlags flags (AudioEngine::instance()->port_engine().get_port_flags (ph));
+
+                                       if (port_has_prefix (p, lpnc)) {
+
+                                               /* we own this port (named after the program) */
+
+                                               /* Hide scene ports for now */
+                                               if (p.find (_("Scene ")) != string::npos) {
+                                                       ++s;
+                                                       continue;
                                                }
+
+                                               extra_program[t].push_back (p);
+
+                                       } else if (flags & IsPhysical) {
+
+                                               extra_system[t].push_back (p);
+
+                                       } else {
+                                               extra_other[t].push_back (p);
                                        }
                                }
                        }
@@ -634,6 +680,7 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp
        add_group_if_not_empty (other);
        add_group_if_not_empty (bus);
        add_group_if_not_empty (track);
+       add_group_if_not_empty (sidechain);
        add_group_if_not_empty (program);
        add_group_if_not_empty (system);