+std::string
+EngineControl::get_default_device(const string& current_device_name,
+ const vector<string>& available_devices)
+{
+ // If the current device is available, use it as default
+ if (std::find (available_devices.begin (),
+ available_devices.end (),
+ current_device_name) != available_devices.end ()) {
+
+ return current_device_name;
+ }
+
+ using namespace ARDOUR;
+
+ string default_device_name =
+ AudioBackend::get_standard_device_name(AudioBackend::DeviceDefault);
+
+ vector<string>::const_iterator i;
+
+ // If there is a "Default" device available, use it
+ for (i = available_devices.begin(); i != available_devices.end(); ++i) {
+ if (*i == default_device_name) {
+ return *i;
+ }
+ }
+
+ string none_device_name =
+ AudioBackend::get_standard_device_name(AudioBackend::DeviceNone);
+
+ // Use the first device that isn't "None"
+ for (i = available_devices.begin(); i != available_devices.end(); ++i) {
+ if (*i != none_device_name) {
+ return *i;
+ }
+ }
+
+ // Use "None" if there are no other available
+ return available_devices.front();
+}
+