diff --git a/libs/ardour/ardour/rc_configuration_vars.h b/libs/ardour/ardour/rc_configuration_vars.h index ea44c60682..4916eeece4 100644 --- a/libs/ardour/ardour/rc_configuration_vars.h +++ b/libs/ardour/ardour/rc_configuration_vars.h @@ -202,3 +202,11 @@ CONFIG_VARIABLE (bool, widget_prelight, "widget-prelight", true) CONFIG_VARIABLE (std::string, mixer_strip_visibility, "mixer-strip-visibility", "PhaseInvert,SoloSafe,SoloIsolated,Group,MeterPoint") CONFIG_VARIABLE (bool, allow_non_quarter_pulse, "allow-non-quarter-pulse", false) CONFIG_VARIABLE (bool, show_region_gain, "show-region-gain", false) + +/* SoundGrid specific */ + +CONFIG_VARIABLE (uint32_t, sg_physical_inputs, "soundgrid-physical-inputs", 8) +CONFIG_VARIABLE (uint32_t, sg_physical_outputs, "soundgrid-physical-inputs", 8) +CONFIG_VARIABLE (uint32_t, sg_tracks, "soundgrid-tracks", 24) +CONFIG_VARIABLE (uint32_t, sg_busses, "soundgrid-tracks", 8) +CONFIG_VARIABLE (uint32_t, sg_plugins_per_track, "soundgrid-plugins-per-track", 8) diff --git a/libs/ardour/ardour/soundgrid.h b/libs/ardour/ardour/soundgrid.h index b57e633483..d10f54617c 100644 --- a/libs/ardour/ardour/soundgrid.h +++ b/libs/ardour/ardour/soundgrid.h @@ -47,6 +47,9 @@ class SoundGrid : public boost::noncopyable uint32_t physical_inputs, uint32_t physical_outputs, uint32_t max_plugins_per_rack); int teardown (); + bool initialized () const; + bool driver_configured() const; + static SoundGrid& instance(); static bool available (); static std::vector lan_port_names(); @@ -56,31 +59,6 @@ class SoundGrid : public boost::noncopyable static std::vector possible_network_buffer_sizes (); static int set_parameters (const std::string& device, int sr, int bufsize); - - struct InventoryItem { - virtual ~InventoryItem() {}; /* force virtual so that we can use dynamic_cast<> */ - - uint32_t assign; - std::string name; - std::string mac; - std::string hostname; - uint32_t channels; - std::string device; - std::string status; - }; - - struct SGSInventoryItem : public InventoryItem { - }; - - struct IOInventoryItem : public InventoryItem { - int32_t sample_rate; - int32_t output_channels; - }; - - typedef std::vector Inventory; - static void update_inventory (Inventory&); - static void clear_inventory (Inventory&); - static void driver_register (const WSDCoreHandle, const WSCoreCallbackTable*, const WSMixerConfig*); void finalize (void* ecc, int state); @@ -96,9 +74,11 @@ class SoundGrid : public boost::noncopyable bool get_gain (uint32_t clusterType, uint32_t trackHandle, double &out_gainValue); int configure_io (uint32_t clusterType, uint32_t trackHandle, uint32_t channels); - int configure_driver (uint32_t physical_inputs, uint32_t physical_outputs, uint32_t tracks); + uint32_t physical_inputs() const { return _physical_inputs; } + uint32_t physical_outputs() const { return _physical_outputs; } + struct Port { enum Position { @@ -238,7 +218,7 @@ class SoundGrid : public boost::noncopyable struct TrackOutputPort : public Port { TrackOutputPort (uint32_t chainer_id, uint32_t channel) : Port (eClusterType_InputTrack, chainer_id, - eControlType_Output, 0, eControlID_Output_Gain, channel, Port::Pre) {} + eControlType_Output, 0, eControlID_Output_Gain, channel, Port::Post) {} }; struct BusInputPort : public Port { @@ -250,7 +230,7 @@ class SoundGrid : public boost::noncopyable struct BusOutputPort : public Port { BusOutputPort (uint32_t chainer_id, uint32_t channel) : Port (eClusterType_GroupTrack, chainer_id, - eControlType_Output, 0, eControlID_Output_Gain, channel, Port::Pre) {} + eControlType_Output, 0, eControlID_Output_Gain, channel, Port::Post) {} }; @@ -278,6 +258,10 @@ class SoundGrid : public boost::noncopyable WSCoreCallbackTable _callback_table; WSMixerConfig _mixer_config; + bool _driver_configured; + + uint32_t _physical_inputs; + uint32_t _physical_outputs; uint32_t _max_plugins; void display_update (); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 69d232079c..1f39b61a76 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -47,7 +47,9 @@ #include "ardour/midi_port.h" #include "ardour/port.h" #include "ardour/process_thread.h" +#include "ardour/profile.h" #include "ardour/session.h" +#include "ardour/soundgrid.h" #include "i18n.h" @@ -1111,7 +1113,8 @@ AudioEngine::get_ports (const string& port_name_pattern, const string& type_name return 0; } } - return jack_get_ports (_priv_jack, port_name_pattern.c_str(), type_name_pattern.c_str(), flags); + const char** p = jack_get_ports (_priv_jack, port_name_pattern.c_str(), type_name_pattern.c_str(), flags); + return p; } void @@ -1200,9 +1203,15 @@ AudioEngine::n_physical (unsigned long flags) const { ChanCount c; + if (Profile->get_soundgrid()) { + c.set (DataType::AUDIO, SoundGrid::instance().physical_inputs() + SoundGrid::instance().physical_outputs()); + return c; + } + GET_PRIVATE_JACK_POINTER_RET (_jack, c); const char ** ports = jack_get_ports (_priv_jack, NULL, NULL, JackPortIsPhysical | flags); + if (ports == 0) { return c; } @@ -1222,12 +1231,24 @@ AudioEngine::n_physical (unsigned long flags) const ChanCount AudioEngine::n_physical_inputs () const { + if (Profile->get_soundgrid()) { + ChanCount c; + c.set (DataType::AUDIO, SoundGrid::instance().physical_inputs()); + return c; + } + return n_physical (JackPortIsInput); } ChanCount AudioEngine::n_physical_outputs () const { + if (Profile->get_soundgrid()) { + ChanCount c; + c.set (DataType::AUDIO, SoundGrid::instance().physical_outputs()); + return c; + } + return n_physical (JackPortIsOutput); } @@ -1242,12 +1263,29 @@ AudioEngine::get_physical (DataType type, unsigned long flags, vector& p } if (ports) { - for (uint32_t i = 0; ports[i]; ++i) { + for (uint32_t i = 0; ports[i]; ++i) { if (strstr (ports[i], "Midi-Through")) { continue; } - phy.push_back (ports[i]); - } + phy.push_back (ports[i]); + } + + if (Profile->get_soundgrid()) { + uint32_t limit; + if (flags & JackPortIsOutput) { + limit = SoundGrid::instance().physical_outputs(); + } else { + limit = SoundGrid::instance().physical_inputs(); + } + + while (phy.size() > limit) { + phy.pop_back (); + } + + cerr << "\n\n\n\n returned " << phy.size() << " physical ports\n"; + + } + free (ports); } } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 180a6070fe..1757ee2660 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4154,7 +4154,7 @@ Session::add_automation_list(AutomationList *al) bool Session::have_rec_enabled_track () const { - return g_atomic_int_get (&_have_rec_enabled_track) == 1; + return g_atomic_int_get (const_cast(&_have_rec_enabled_track)) == 1; } /** Update the state of our rec-enabled tracks flag */ diff --git a/libs/ardour/soundgrid.mm b/libs/ardour/soundgrid.mm index 5fb6a080ba..31301bf4a2 100644 --- a/libs/ardour/soundgrid.mm +++ b/libs/ardour/soundgrid.mm @@ -67,6 +67,9 @@ SoundGrid::SoundGrid () : dl_handle (0) , _sg (0) , _host_handle (0) + , _driver_configured (false) + , _physical_inputs (0) + , _physical_outputs (0) , _max_plugins (8) { } @@ -83,62 +86,75 @@ SoundGrid::~SoundGrid() } } +bool +SoundGrid::initialized() const +{ + return (_sg != 0); +} + +bool +SoundGrid::driver_configured() const +{ + return _driver_configured; +} + int SoundGrid::initialize (void* window_handle, uint32_t max_tracks, uint32_t max_busses, uint32_t /*physical_inputs*/, uint32_t physical_outputs, uint32_t max_plugins_per_rack) { - if (!_sg) { - WTErr ret; - DEBUG_TRACE (DEBUG::SoundGrid, "Initializing SG core...\n"); - - WSMixerConfig mixer_limits; - Init_WSMixerConfig (&mixer_limits); - - max_tracks = 64; - - mixer_limits.m_clusterConfigs[eClusterType_Inputs].m_uiIndexNum = 2; // Physical IO + Device Driver - mixer_limits.m_clusterConfigs[eClusterType_Outputs].m_uiIndexNum = 2; // Physical IO + Device Driver - mixer_limits.m_clusterConfigs[eClusterType_InputTrack].m_uiIndexNum = max_tracks; - mixer_limits.m_clusterConfigs[eClusterType_GroupTrack].m_uiIndexNum = max_busses + physical_outputs; - - DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Initializing SG Core with %1 tracks\n", max_tracks)); - - char execpath[MAXPATHLEN+1]; - uint32_t pathsz = sizeof (execpath); - string driver_path; - - if (getenv ("ARDOUR_BUNDLED") == 0) { -#ifdef __APPLE__ - _NSGetExecutablePath (execpath, &pathsz); -#else - readlink ("/proc/self/exe", execpath, sizeof(execpath)); -#endif - vector s; - s.push_back (Glib::path_get_dirname (execpath)); - s.push_back (".."); - s.push_back ("libs"); - s.push_back ("soundgrid"); - s.push_back ("SurfaceDriver_App.bundle"); - driver_path = Glib::build_filename (s); - } else { - driver_path = Glib::build_filename (ardour_dll_directory(), "SurfaceDriver_App.bundle"); - } - - DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("driver path: %1\n", driver_path)); - - if ((ret = InitializeMixerCoreDLL (&mixer_limits, driver_path.c_str(), window_handle, _sg_callback, this, &_sg)) != eNoErr) { - DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Failed to initialize SG core, ret = %1 core handle %2\n", ret, _sg)); - return -1; - } - - _max_plugins = max_plugins_per_rack; - - DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Initialized SG core, core handle %1\n", _sg)); - } else { + if (initialized()) { DEBUG_TRACE (DEBUG::SoundGrid, "SG core already initialized...\n"); + return 1; } + WTErr ret; + DEBUG_TRACE (DEBUG::SoundGrid, "Initializing SG core...\n"); + + WSMixerConfig mixer_limits; + Init_WSMixerConfig (&mixer_limits); + + max_tracks = 64; + + mixer_limits.m_clusterConfigs[eClusterType_Inputs].m_uiIndexNum = 2; // Physical IO + Device Driver + mixer_limits.m_clusterConfigs[eClusterType_Outputs].m_uiIndexNum = 2; // Physical IO + Device Driver + mixer_limits.m_clusterConfigs[eClusterType_InputTrack].m_uiIndexNum = max_tracks; + mixer_limits.m_clusterConfigs[eClusterType_GroupTrack].m_uiIndexNum = max_busses + physical_outputs; + + DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Initializing SG Core with %1 tracks\n", max_tracks)); + + char execpath[MAXPATHLEN+1]; + uint32_t pathsz = sizeof (execpath); + string driver_path; + + if (getenv ("ARDOUR_BUNDLED") == 0) { +#ifdef __APPLE__ + _NSGetExecutablePath (execpath, &pathsz); +#else + readlink ("/proc/self/exe", execpath, sizeof(execpath)); +#endif + vector s; + s.push_back (Glib::path_get_dirname (execpath)); + s.push_back (".."); + s.push_back ("libs"); + s.push_back ("soundgrid"); + s.push_back ("SurfaceDriver_App.bundle"); + driver_path = Glib::build_filename (s); + } else { + driver_path = Glib::build_filename (ardour_dll_directory(), "SurfaceDriver_App.bundle"); + } + + DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("driver path: %1\n", driver_path)); + + if ((ret = InitializeMixerCoreDLL (&mixer_limits, driver_path.c_str(), window_handle, _sg_callback, this, &_sg)) != eNoErr) { + DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Failed to initialize SG core, ret = %1 core handle %2\n", ret, _sg)); + return -1; + } + + _max_plugins = max_plugins_per_rack; + + DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Initialized SG core, core handle %1\n", _sg)); + return 0; } @@ -178,6 +194,14 @@ int SoundGrid::configure_driver (uint32_t inputs, uint32_t outputs, uint32_t tracks) { WSConfigSGDriverCommand myCommand; + + if (_driver_configured) { + return 0; + } + + _physical_outputs = outputs; + _physical_inputs = inputs; + uint32_t in = inputs+tracks; uint32_t out = outputs+tracks; @@ -307,6 +331,7 @@ SoundGrid::configure_driver (uint32_t inputs, uint32_t outputs, uint32_t tracks) #endif } + _driver_configured = true; return 0; } @@ -340,7 +365,7 @@ SoundGrid::_finalize (void* p, int state) } int -SoundGrid::set (WSEvent* ev, const std::string& /*what*/) +SoundGrid::set (WSEvent* ev, const std::string& what) { if (!_host_handle) { return -1; @@ -348,6 +373,8 @@ SoundGrid::set (WSEvent* ev, const std::string& /*what*/) ev->sourceController = (WSDControllerHandle) this; + DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Set %1\n", what)); + if (_callback_table.setEventProc (_host_handle, this, ev) != eNoErr) { DEBUG_TRACE (DEBUG::SoundGrid, "Set failure\n"); return -1; @@ -533,80 +560,6 @@ SoundGrid::coreaudio_device_name () return "com_waves_WCAudioGridEngine:0"; } -void -SoundGrid::update_inventory (Inventory& inventory) -{ - clear_inventory (inventory); - - WSSGDevices currentSGDevices; - Init_WSSGDevices(¤tSGDevices); - WTErr eRetVal; - - eRetVal = instance().get (¤tSGDevices.m_controlInfo.m_controlID, (WSControlInfo*)¤tSGDevices); - - if (eRetVal != eNoErr) { - error << string_compose (_("SoundGrid: could not retrieve inventory (%1)"), eRetVal) << endmsg; - return; - } - - DEBUG_TRACE (PBD::DEBUG::SoundGrid, string_compose ("inventory contains %1 IO boxes and %2 servers\n", - currentSGDevices.m_IOBoxs.m_numberOfDevices, - currentSGDevices.m_SGServers.m_numberOfDevices)); - - for (uint32_t n = 0; n < currentSGDevices.m_IOBoxs.m_numberOfDevices; ++n) { - IOInventoryItem* ii = new (IOInventoryItem); - WSIOBoxDevice* dev = ¤tSGDevices.m_IOBoxs.m_ioBoxDevices[n]; - - ii->assign = dev->assignIndex; - ii->device = dev->type; - ii->channels = dev->channelCount; - ii->channels = dev->outputChannelCount; - ii->sample_rate = dev->sampleRate; - ii->name = dev->name; - ii->hostname = dev->hostname; - ii->mac = dev->mac; - if (dev->isIncompatible) { - ii->status = _("Incompatible"); - } else if (dev->isActive) { - ii->status = _("Active"); - } else { - ii->status = _("Inactive"); - } - - inventory.push_back (ii); - } - - for (uint32_t n = 0; n < currentSGDevices.m_SGServers.m_numberOfDevices; ++n) { - SGSInventoryItem* is = new (SGSInventoryItem); - WSSGSDevice* dev = ¤tSGDevices.m_SGServers.m_sgsDevices[n]; - - is->assign = dev->assignIndex; - is->device = dev->type; - is->channels = dev->channelCount; - is->name = dev->name; - is->hostname = dev->hostname; - is->mac = dev->mac; - if (dev->isIncompatible) { - is->status = _("Incompatible"); - } else if (dev->isActive) { - is->status = _("Active"); - } else { - is->status = _("Inactive"); - } - - inventory.push_back (is); - } -} - -void -SoundGrid::clear_inventory (Inventory& inventory) -{ - for (Inventory::iterator i = inventory.begin(); i != inventory.end(); ++i) { - delete *i; - } - inventory.clear(); -} - vector SoundGrid::possible_network_buffer_sizes () { @@ -741,13 +694,13 @@ SoundGrid::remove_all_racks () } int -SoundGrid::set_gain (uint32_t clusterType, uint32_t trackHandle, double in_gainValue) +SoundGrid::set_gain (uint32_t clusterType, uint32_t trackHandle, double gainValue) { WSEvent faderEvent; Init_WSEvent(&faderEvent); faderEvent.eventID = eEventID_MoveTo; - faderEvent.controllerValue = in_gainValue; + faderEvent.controllerValue = gainValue; Init_WSControlID(&faderEvent.controlID); faderEvent.controlID.clusterID.clusterType = clusterType; @@ -762,15 +715,15 @@ SoundGrid::set_gain (uint32_t clusterType, uint32_t trackHandle, double in_gainV } bool -SoundGrid::get_gain (uint32_t in_clusterType, uint32_t in_trackHandle, double &out_gainValue) +SoundGrid::get_gain (uint32_t clusterType, uint32_t trackHandle, double &out_gainValue) { WSControlInfo faderInfo; Init_WSControlInfo(&faderInfo); Init_WSControlID(&faderInfo.m_controlID); - faderInfo.m_controlID.clusterID.clusterType = in_clusterType; - faderInfo.m_controlID.clusterID.clusterHandle = in_trackHandle; + faderInfo.m_controlID.clusterID.clusterType = clusterType; + faderInfo.m_controlID.clusterID.clusterHandle = trackHandle; faderInfo.m_controlID.sectionControlID.sectionType = eControlType_Output; faderInfo.m_controlID.sectionControlID.sectionIndex = eControlType_Output_Local;