Allow calling IO::silence for yet unregistered ports (Click)
[ardour.git] / libs / ardour / io.cc
index 5b949613c3fdff4a4c7c2b3e5debe00fd9580f1e..a3549f0a1d3ff0895ae7c9fb9abe99435b3e0093 100644 (file)
@@ -31,6 +31,7 @@
 #include "pbd/replace_all.h"
 #include "pbd/unknown_type.h"
 #include "pbd/enumwriter.h"
+#include "pbd/locale_guard.h"
 #include "pbd/types_convert.h"
 
 #include "ardour/audioengine.h"
@@ -147,7 +148,9 @@ IO::silence (framecnt_t nframes)
        /* io_lock, not taken: function must be called from Session::process() calltree */
 
        for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
-               i->get_buffer(nframes).silence (nframes);
+               if (i->port_handle ()) {
+                       i->get_buffer(nframes).silence (nframes);
+               }
        }
 }
 
@@ -553,7 +556,6 @@ IO::state (bool /*full_state*/)
 {
        XMLNode* node = new XMLNode (state_node_name);
        int n;
-       LocaleGuard lg;
        Glib::Threads::Mutex::Lock lm (io_lock);
 
        node->set_property ("name", name());
@@ -616,9 +618,6 @@ IO::set_state (const XMLNode& node, int version)
         */
        assert (version >= 3000);
 
-       XMLNodeConstIterator iter;
-       LocaleGuard lg;
-
        /* force use of non-localized representation of decimal point,
           since we use it a lot in XML files and so forth.
        */
@@ -756,6 +755,7 @@ IO::find_possible_bundle (const string &desired_name)
                string possible_name;
                bool stereo = false;
                string::size_type last_non_digit_pos;
+               std::string bundle_number_str;
 
                error << string_compose(_("Unknown bundle \"%1\" listed for %2 of %3"), desired_name, bundle_type_name, _name)
                      << endmsg;
@@ -766,9 +766,8 @@ IO::find_possible_bundle (const string &desired_name)
                last_non_digit_pos = desired_name.find_last_not_of(digits);
 
                if (last_non_digit_pos != string::npos) {
-                       stringstream s;
-                       s << desired_name.substr(last_non_digit_pos);
-                       s >> bundle_number;
+                       bundle_number_str = desired_name.substr(last_non_digit_pos);
+                       bundle_number = string_to<int32_t>(bundle_number_str);
                }
 
                // see if it's a stereo connection e.g. "in 3+4"
@@ -780,9 +779,8 @@ IO::find_possible_bundle (const string &desired_name)
 
                        if (left_last_non_digit_pos != string::npos) {
                                int left_bundle_number = 0;
-                               stringstream s;
-                               s << desired_name.substr(left_last_non_digit_pos, last_non_digit_pos-1);
-                               s >> left_bundle_number;
+                               bundle_number_str = desired_name.substr(left_last_non_digit_pos, last_non_digit_pos-1);
+                               left_bundle_number = string_to<int32_t>(bundle_number_str);
 
                                if (left_bundle_number > 0 && left_bundle_number + 1 == bundle_number) {
                                        bundle_number--;
@@ -807,15 +805,12 @@ IO::find_possible_bundle (const string &desired_name)
                        if (bundle_number & mask) {
                                bundle_number &= ~mask;
 
-                               stringstream s;
-                               s << default_name << " " << bundle_number + 1;
+                               std::string possible_name = default_name + " " + to_string(bundle_number + 1);
 
                                if (stereo) {
-                                       s << "+" << bundle_number + 2;
+                                       possible_name += "+" + to_string(bundle_number + 2);
                                }
 
-                               possible_name = s.str();
-
                                if ((c = _session.bundle_by_name (possible_name)) != 0) {
                                        break;
                                }