2 * Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
3 * Copyright (C) 2009-2014 David Robillard <d@drobilla.net>
4 * Copyright (C) 2009-2014 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2015-2016 Robin Gareus <robin@gareus.org>
6 * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef MIDI_PATCH_MANAGER_H_
24 #define MIDI_PATCH_MANAGER_H_
26 #include "midi++/midnam_patch.h"
28 #include "pbd/signals.h"
29 #include "pbd/search_path.h"
31 #include "ardour/libardour_visibility.h"
39 class LIBARDOUR_API MidiPatchManager
44 MidiPatchManager( const MidiPatchManager& );
45 MidiPatchManager& operator= (const MidiPatchManager&);
47 static MidiPatchManager* _manager;
50 typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> > MidiNameDocuments;
51 typedef std::map<std::string, MIDINameDocument::MasterDeviceNamesList> DeviceNamesByMaker;
53 virtual ~MidiPatchManager() { _manager = 0; }
55 static MidiPatchManager& instance() {
57 _manager = new MidiPatchManager();
62 PBD::Signal0<void> PatchesChanged;
64 bool add_custom_midnam (const std::string& id, const std::string& midnam);
65 bool update_custom_midnam (const std::string& id, const std::string& midnam);
66 bool remove_custom_midnam (const std::string& id);
67 bool is_custom_model (const std::string& model) const;
69 void add_search_path (const PBD::Searchpath& search_path);
71 void remove_search_path (const PBD::Searchpath& search_path);
73 boost::shared_ptr<MIDINameDocument> document_by_model(std::string model_name) const;
75 boost::shared_ptr<MasterDeviceNames> master_device_by_model(std::string model_name)
76 { return _master_devices_by_model[model_name]; }
78 boost::shared_ptr<ChannelNameSet> find_channel_name_set(
80 std::string custom_device_mode,
82 boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device = master_device_by_model(model);
84 if (master_device != 0 && custom_device_mode != "") {
85 return master_device->channel_name_set_by_channel(custom_device_mode, channel);
87 return boost::shared_ptr<ChannelNameSet>();
91 boost::shared_ptr<Patch> find_patch(
93 std::string custom_device_mode,
95 PatchPrimaryKey patch_key) {
97 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
99 if (channel_name_set) {
100 return channel_name_set->find_patch(patch_key);
102 return boost::shared_ptr<Patch>();
106 boost::shared_ptr<Patch> previous_patch(
108 std::string custom_device_mode,
110 PatchPrimaryKey patch_key) {
112 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
114 if (channel_name_set) {
115 return channel_name_set->previous_patch(patch_key);
117 return boost::shared_ptr<Patch>();
121 boost::shared_ptr<Patch> next_patch(
123 std::string custom_device_mode,
125 PatchPrimaryKey patch_key) {
127 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
129 if (channel_name_set) {
130 return channel_name_set->next_patch(patch_key);
132 return boost::shared_ptr<Patch>();
136 std::list<std::string> custom_device_mode_names_by_model(std::string model_name) {
137 if (model_name != "") {
138 if (master_device_by_model(model_name)) {
139 return master_device_by_model(model_name)->custom_device_mode_names();
142 return std::list<std::string>();
145 const MasterDeviceNames::Models& all_models() const { return _all_models; }
147 const DeviceNamesByMaker& devices_by_manufacturer() const { return _devices_by_manufacturer; }
150 bool load_midi_name_document(const std::string& file_path);
151 bool add_midi_name_document(boost::shared_ptr<MIDINameDocument>);
152 bool remove_midi_name_document(const std::string& file_path, bool emit_signal = true);
154 void add_midnam_files_from_directory(const std::string& directory_path);
155 void remove_midnam_files_from_directory(const std::string& directory_path);
158 PBD::Searchpath _search_path;
160 MidiNameDocuments _documents;
161 MIDINameDocument::MasterDeviceNamesList _master_devices_by_model;
162 DeviceNamesByMaker _devices_by_manufacturer;
163 MasterDeviceNames::Models _all_models;
170 #endif /* MIDI_PATCH_MANAGER_H_ */