2 Copyright (C) 2008 Hans Baier
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef MIDI_PATCH_MANAGER_H_
22 #define MIDI_PATCH_MANAGER_H_
24 #include "midi++/midnam_patch.h"
26 #include "pbd/signals.h"
27 #include "pbd/search_path.h"
29 #include "ardour/libardour_visibility.h"
37 class LIBARDOUR_API MidiPatchManager
42 MidiPatchManager( const MidiPatchManager& );
43 MidiPatchManager& operator= (const MidiPatchManager&);
45 static MidiPatchManager* _manager;
48 typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> > MidiNameDocuments;
49 typedef std::map<std::string, MIDINameDocument::MasterDeviceNamesList> DeviceNamesByMaker;
51 virtual ~MidiPatchManager() { _manager = 0; }
53 static MidiPatchManager& instance() {
55 _manager = new MidiPatchManager();
60 PBD::Signal0<void> PatchesChanged;
62 bool add_custom_midnam (const std::string& id, const std::string& midnam);
63 bool update_custom_midnam (const std::string& id, const std::string& midnam);
64 bool remove_custom_midnam (const std::string& id);
66 void add_search_path (const PBD::Searchpath& search_path);
68 void remove_search_path (const PBD::Searchpath& search_path);
70 boost::shared_ptr<MIDINameDocument> document_by_model(std::string model_name) const;
72 boost::shared_ptr<MasterDeviceNames> master_device_by_model(std::string model_name)
73 { return _master_devices_by_model[model_name]; }
75 boost::shared_ptr<ChannelNameSet> find_channel_name_set(
77 std::string custom_device_mode,
79 boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device = master_device_by_model(model);
81 if (master_device != 0 && custom_device_mode != "") {
82 return master_device->channel_name_set_by_channel(custom_device_mode, channel);
84 return boost::shared_ptr<ChannelNameSet>();
88 boost::shared_ptr<Patch> find_patch(
90 std::string custom_device_mode,
92 PatchPrimaryKey patch_key) {
94 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
96 if (channel_name_set) {
97 return channel_name_set->find_patch(patch_key);
99 return boost::shared_ptr<Patch>();
103 boost::shared_ptr<Patch> previous_patch(
105 std::string custom_device_mode,
107 PatchPrimaryKey patch_key) {
109 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
111 if (channel_name_set) {
112 return channel_name_set->previous_patch(patch_key);
114 return boost::shared_ptr<Patch>();
118 boost::shared_ptr<Patch> next_patch(
120 std::string custom_device_mode,
122 PatchPrimaryKey patch_key) {
124 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
126 if (channel_name_set) {
127 return channel_name_set->next_patch(patch_key);
129 return boost::shared_ptr<Patch>();
133 std::list<std::string> custom_device_mode_names_by_model(std::string model_name) {
134 if (model_name != "") {
135 if (master_device_by_model(model_name)) {
136 return master_device_by_model(model_name)->custom_device_mode_names();
139 return std::list<std::string>();
142 const MasterDeviceNames::Models& all_models() const { return _all_models; }
144 const DeviceNamesByMaker& devices_by_manufacturer() const { return _devices_by_manufacturer; }
147 bool load_midi_name_document(const std::string& file_path);
148 bool add_midi_name_document(boost::shared_ptr<MIDINameDocument>);
149 bool remove_midi_name_document(const std::string& file_path, bool emit_signal = true);
151 void add_midnam_files_from_directory(const std::string& directory_path);
152 void remove_midnam_files_from_directory(const std::string& directory_path);
155 PBD::Searchpath _search_path;
157 MidiNameDocuments _documents;
158 MIDINameDocument::MasterDeviceNamesList _master_devices_by_model;
159 DeviceNamesByMaker _devices_by_manufacturer;
160 MasterDeviceNames::Models _all_models;
167 #endif /* MIDI_PATCH_MANAGER_H_ */