Optimize automation-event process splitting
[ardour.git] / libs / ardour / ardour / midi_patch_manager.h
index e9751c695608b8d56ebe552a55b1d53458d13c32..5eb34dbbf4047c91754ce1028310809c5e00dab9 100644 (file)
 #define MIDI_PATCH_MANAGER_H_
 
 #include "midi++/midnam_patch.h"
+
 #include "pbd/signals.h"
-#include "ardour/session_handle.h"
+#include "pbd/search_path.h"
 
-namespace ARDOUR {
-       class Session;
-}
+#include "ardour/libardour_visibility.h"
 
 namespace MIDI
 {
@@ -35,7 +34,7 @@ namespace MIDI
 namespace Name
 {
 
-class LIBARDOUR_API MidiPatchManager : public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr
+class LIBARDOUR_API MidiPatchManager
 {
        /// Singleton
 private:
@@ -46,7 +45,8 @@ private:
        static MidiPatchManager* _manager;
 
 public:
-       typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> > MidiNameDocuments;
+       typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> >    MidiNameDocuments;
+       typedef std::map<std::string, MIDINameDocument::MasterDeviceNamesList> DeviceNamesByMaker;
 
        virtual ~MidiPatchManager() { _manager = 0; }
 
@@ -57,10 +57,17 @@ public:
                return *_manager;
        }
 
-       void set_session (ARDOUR::Session*);
+       PBD::Signal0<void> PatchesChanged;
+
+       bool add_custom_midnam (const std::string& id, const std::string& midnam);
+       bool update_custom_midnam (const std::string& id, const std::string& midnam);
+       bool remove_custom_midnam (const std::string& id);
+
+       void add_search_path (const PBD::Searchpath& search_path);
 
-       boost::shared_ptr<MIDINameDocument> document_by_model(std::string model_name)
-               { return _documents[model_name]; }
+       void remove_search_path (const PBD::Searchpath& search_path);
+
+       boost::shared_ptr<MIDINameDocument> document_by_model(std::string model_name) const;
 
        boost::shared_ptr<MasterDeviceNames> master_device_by_model(std::string model_name)
                { return _master_devices_by_model[model_name]; }
@@ -72,7 +79,7 @@ public:
                boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device = master_device_by_model(model);
 
                if (master_device != 0 && custom_device_mode != "") {
-                       return master_device->channel_name_set_by_device_mode_and_channel(custom_device_mode, channel);
+                       return master_device->channel_name_set_by_channel(custom_device_mode, channel);
                } else {
                        return boost::shared_ptr<ChannelNameSet>();
                }
@@ -125,21 +132,31 @@ public:
 
        std::list<std::string> custom_device_mode_names_by_model(std::string model_name) {
                if (model_name != "") {
-                       return master_device_by_model(model_name)->custom_device_mode_names();
-               } else {
-                       return std::list<std::string>();
+                       if (master_device_by_model(model_name)) {
+                               return master_device_by_model(model_name)->custom_device_mode_names();
+                       }
                }
+               return std::list<std::string>();
        }
 
        const MasterDeviceNames::Models& all_models() const { return _all_models; }
 
+       const DeviceNamesByMaker& devices_by_manufacturer() const { return _devices_by_manufacturer; }
+
+private:
+       bool load_midi_name_document(const std::string& file_path);
+       bool add_midi_name_document(boost::shared_ptr<MIDINameDocument>);
+       bool remove_midi_name_document(const std::string& file_path, bool emit_signal = true);
+
+       void add_midnam_files_from_directory(const std::string& directory_path);
+       void remove_midnam_files_from_directory(const std::string& directory_path);
+
 private:
-       void session_going_away();
-       void refresh();
-       void add_session_patches();
+       PBD::Searchpath                         _search_path;
 
        MidiNameDocuments                       _documents;
        MIDINameDocument::MasterDeviceNamesList _master_devices_by_model;
+       DeviceNamesByMaker                      _devices_by_manufacturer;
        MasterDeviceNames::Models               _all_models;
 };