Extend API to allow calling new_midi_source_path() with source_lock held
authorRobin Gareus <robin@gareus.org>
Sat, 24 Jun 2017 23:23:03 +0000 (01:23 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 24 Jun 2017 23:57:19 +0000 (01:57 +0200)
This is in preparation for cloning MIDI-sources during snapshot save.

libs/ardour/ardour/session.h
libs/ardour/session.cc

index bc8614be96d2fddf5052af5311ba6c04202ef45f..2da54f8bbc29b320d636a35fbea3472eaf6fb5d5 100644 (file)
@@ -249,7 +249,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        std::string format_audio_source_name (const std::string& legalized_base, uint32_t nchan, uint32_t chan, bool destructive, bool take_required, uint32_t cnt, bool related_exists);
        std::string new_audio_source_path_for_embedded (const std::string& existing_path);
        std::string new_audio_source_path (const std::string&, uint32_t nchans, uint32_t chan, bool destructive, bool take_required);
-       std::string new_midi_source_path (const std::string&);
+       std::string new_midi_source_path (const std::string&, bool need_source_lock = true);
        /** create a new track or bus from a template (XML path)
         * @param how_many how many tracks or busses to create
         * @param template_path path to xml template file
@@ -801,7 +801,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        boost::shared_ptr<Source> source_by_id (const PBD::ID&);
        boost::shared_ptr<AudioFileSource> audio_source_by_path_and_channel (const std::string&, uint16_t) const;
-       boost::shared_ptr<MidiSource> midi_source_by_path (const std::string&) const;
+       boost::shared_ptr<MidiSource> midi_source_by_path (const std::string&, bool need_source_lock) const;
        uint32_t count_sources_by_origin (const std::string&);
 
        void add_playlist (boost::shared_ptr<Playlist>, bool unused = false);
index b6d4bb988c56265acc92207a50ac9c598a6bca90..416f972ea784c4da35434d7f800bbb9a8646e105 100644 (file)
@@ -4887,13 +4887,16 @@ Session::audio_source_by_path_and_channel (const string& path, uint16_t chn) con
 }
 
 boost::shared_ptr<MidiSource>
-Session::midi_source_by_path (const std::string& path) const
+Session::midi_source_by_path (const std::string& path, bool need_source_lock) const
 {
        /* Restricted to MIDI files because audio sources require a channel
           for unique identification, in addition to a path.
        */
 
-       Glib::Threads::Mutex::Lock lm (source_lock);
+       Glib::Threads::Mutex::Lock lm (source_lock, Glib::Threads::NOT_LOCK);
+       if (need_source_lock) {
+               lm.acquire ();
+       }
 
        for (SourceMap::const_iterator s = sources.begin(); s != sources.end(); ++s) {
                boost::shared_ptr<MidiSource> ms
@@ -5194,7 +5197,7 @@ Session::new_audio_source_path (const string& base, uint32_t nchan, uint32_t cha
 
 /** Return a unique name based on `base` for a new internal MIDI source */
 string
-Session::new_midi_source_path (const string& base)
+Session::new_midi_source_path (const string& base, bool need_lock)
 {
        uint32_t cnt;
        char buf[PATH_MAX+1];
@@ -5235,7 +5238,7 @@ Session::new_midi_source_path (const string& base)
                                existing++;
                        }
 
-                       if (midi_source_by_path (possible_path)) {
+                       if (midi_source_by_path (possible_path, need_lock)) {
                                existing++;
                        }
                }