revert recent change to cleaner names for MIDI ports, which breaks certain other...
[ardour.git] / gtk2_ardour / engine_dialog.cc
index 6b069653feed7c37fd3e23aa38bc8858e77bd6fb..d54f6100a93137b973eebdab650b87017410ba16 100644 (file)
 #include <fstream>
 #include <map>
 
+#include <boost/scoped_ptr.hpp>
+
 #include <glibmm.h>
 #include <gtkmm/messagedialog.h>
+
+#include "pbd/epa.h"
 #include "pbd/xml++.h"
 
 #ifdef __APPLE__
@@ -65,6 +69,10 @@ EngineControl::EngineControl ()
          priority_spinner (priority_adjustment),
          ports_adjustment (128, 8, 1024, 1, 16),
          ports_spinner (ports_adjustment),
+         input_latency_adjustment (0, 0, 99999, 1),
+         input_latency (input_latency_adjustment),
+         output_latency_adjustment (0, 0, 99999, 1),
+         output_latency (output_latency_adjustment),
          realtime_button (_("Realtime")),
          no_memory_lock_button (_("Do not lock memory")),
          unlock_memory_button (_("Unlock memory")),
@@ -134,6 +142,7 @@ EngineControl::EngineControl ()
 #else
        strings.push_back (X_("ALSA"));
        strings.push_back (X_("OSS"));
+       strings.push_back (X_("FreeBoB"));
        strings.push_back (X_("FFADO"));
 #endif
        strings.push_back (X_("NetJACK"));
@@ -406,12 +415,10 @@ EngineControl::build_command_line (vector<string>& cmd)
 {
        string str;
        string driver;
-       bool using_oss = false;
        bool using_alsa = false;
        bool using_coreaudio = false;
-       bool using_netjack = false;
-       bool using_ffado = false;
        bool using_dummy = false;
+       bool using_ffado = false;
 
        /* first, path to jackd */
 
@@ -420,11 +427,14 @@ EngineControl::build_command_line (vector<string>& cmd)
        /* now jackd arguments */
 
        str = timeout_combo.get_active_text ();
+       
        if (str != _("Ignore")) {
+
                double secs = 0;
                uint32_t msecs;
                secs = atof (str);
                msecs = (uint32_t) floor (secs * 1000.0);
+               
                if (msecs > 0) {
                        cmd.push_back ("-t");
                        cmd.push_back (to_string (msecs, std::dec));
@@ -463,31 +473,22 @@ EngineControl::build_command_line (vector<string>& cmd)
        cmd.push_back ("-d");
 
        driver = driver_combo.get_active_text ();
+       
        if (driver == X_("ALSA")) {
                using_alsa = true;
                cmd.push_back ("alsa");
        } else if (driver == X_("OSS")) {
-               using_oss = true;
                cmd.push_back ("oss");
        } else if (driver == X_("CoreAudio")) {
                using_coreaudio = true;
                cmd.push_back ("coreaudio");
        } else if (driver == X_("NetJACK")) {
-               using_netjack = true;
                cmd.push_back ("netjack");
+       } else if (driver == X_("FreeBoB")) {
+               cmd.push_back ("freebob");
        } else if (driver == X_("FFADO")) {
                using_ffado = true;
-
-               /* do this until FFADO becomes the standard */
-
-               char* hack = getenv ("ARDOUR_FIREWIRE_DRIVER_NAME");
-
-               if (hack) {
-                       cmd.push_back (hack);
-               } else {
-                       cmd.push_back ("freebob");
-               }
-
+               cmd.push_back ("firewire");
        } else if ( driver == X_("Dummy")) {
                using_dummy = true;
                cmd.push_back ("dummy");
@@ -514,6 +515,7 @@ EngineControl::build_command_line (vector<string>& cmd)
 
                        cmd.push_back ("-C");
                        cmd.push_back (input_device);
+                       
                        cmd.push_back ("-P");
                        cmd.push_back (output_device);
 
@@ -523,7 +525,7 @@ EngineControl::build_command_line (vector<string>& cmd)
                        cmd.push_back ("-C");
                }
 
-               if (! using_dummy ) {
+               if (!using_dummy) {
                        cmd.push_back ("-n");
                        cmd.push_back (to_string ((uint32_t) floor (periods_spinner.get_value()), std::dec));
                }
@@ -534,6 +536,23 @@ EngineControl::build_command_line (vector<string>& cmd)
 
        cmd.push_back ("-p");
        cmd.push_back (period_size_combo.get_active_text());
+       
+       if (using_alsa || using_ffado || using_coreaudio) {
+
+               double val = input_latency_adjustment.get_value();
+
+                if (val) {
+                        cmd.push_back ("-I");
+                        cmd.push_back (to_string ((uint32_t) val, std::dec));
+                }
+
+                val = output_latency_adjustment.get_value();
+                
+               if (val) {
+                        cmd.push_back ("-O");
+                        cmd.push_back (to_string ((uint32_t) val, std::dec));
+                }
+       }
 
        if (using_alsa) {
 
@@ -583,7 +602,6 @@ EngineControl::build_command_line (vector<string>& cmd)
                } else if (str == _("raw")) {
                        cmd.push_back ("-X raw");
                }
-
        } else if (using_coreaudio) {
 
 #ifdef __APPLE__
@@ -599,16 +617,23 @@ EngineControl::build_command_line (vector<string>& cmd)
                cmd.push_back (device);
 #endif
 
-       } else if (using_oss) {
-
-       } else if (using_netjack) {
-
        }
 }
 
 bool
 EngineControl::engine_running ()
 {
+        EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
+        boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
+
+        /* revert all environment settings back to whatever they were when ardour started
+         */
+
+        if (global_epa) {
+                current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
+                global_epa->restore ();
+        }
+
        jack_status_t status;
        jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);
 
@@ -631,7 +656,7 @@ EngineControl::setup_engine ()
                return 1; // try again
        }
 
-       Glib::ustring jackdrc_path = Glib::get_home_dir();
+       std::string jackdrc_path = Glib::get_home_dir();
        jackdrc_path += "/.jackdrc";
 
        ofstream jackdrc (jackdrc_path.c_str());
@@ -674,6 +699,8 @@ EngineControl::enumerate_devices (const string& driver)
 #ifndef __APPLE__
        } else if (driver == "ALSA") {
                devices[driver] = enumerate_alsa_devices ();
+       } else if (driver == "FreeBOB") {
+               devices[driver] = enumerate_freebob_devices ();
        } else if (driver == "FFADO") {
                devices[driver] = enumerate_ffado_devices ();
        } else if (driver == "OSS") {
@@ -858,6 +885,7 @@ EngineControl::enumerate_freebob_devices ()
        vector<string> devs;
        return devs;
 }
+
 vector<string>
 EngineControl::enumerate_oss_devices ()
 {
@@ -890,7 +918,7 @@ EngineControl::driver_changed ()
 
        vector<string>& strings = devices[driver];
 
-       if (strings.empty() && driver != "FFADO" && driver != "Dummy") {
+       if (strings.empty() && driver != "FreeBoB" && driver != "FFADO" && driver != "Dummy") {
                error << string_compose (_("No devices found for driver \"%1\""), driver) << endmsg;
                return;
        }
@@ -954,7 +982,7 @@ EngineControl::redisplay_latency ()
 void
 EngineControl::audio_mode_changed ()
 {
-       Glib::ustring str = audio_mode_combo.get_active_text();
+       std::string str = audio_mode_combo.get_active_text();
 
        if (str == _("Playback/Recording on 1 Device")) {
                input_device_combo.set_sensitive (false);
@@ -1091,7 +1119,7 @@ EngineControl::get_state ()
 {
        XMLNode* root = new XMLNode ("AudioSetup");
        XMLNode* child;
-       Glib::ustring path;
+       std::string path;
 
        child = new XMLNode ("periods");
        child->add_property ("val", to_string (periods_adjustment.get_value(), std::dec));
@@ -1208,15 +1236,21 @@ EngineControl::set_state (const XMLNode& root)
        XMLNode* child;
        XMLProperty* prop = NULL;
        bool using_dummy = false;
+       bool using_ffado = false;
 
        int val;
        string strval;
 
        if ( (child = root.child ("driver"))){
                prop = child->property("val");
+               
                if (prop && (prop->value() == "Dummy") ) {
                        using_dummy = true;
                }
+               if (prop && (prop->value() == "FFADO") ) {
+                       using_ffado = true;
+               }
+
        }
 
        clist = root.children();
@@ -1229,9 +1263,15 @@ EngineControl::set_state (const XMLNode& root)
 
                if (!prop || prop->value().empty()) {
 
-                       if ((using_dummy && ( child->name() == "interface" || child->name() == "inputdevice" || child->name() == "outputdevice" )) ||
-                               child->name() == "timeout")
+                       if (((using_dummy || using_ffado) 
+                               && ( child->name() == "interface" 
+                                       || child->name() == "inputdevice" 
+                                       || child->name() == "outputdevice")) 
+                               || child->name() == "timeout")
+                       {
                                continue;
+                       }
+                       
                        error << string_compose (_("AudioSetup value for %1 is missing data"), child->name()) << endmsg;
                        continue;
                }