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>
36 class MidiPatchManager
40 MidiPatchManager() {};
41 MidiPatchManager( const MidiPatchManager& );
42 MidiPatchManager& operator= (const MidiPatchManager&);
44 static MidiPatchManager* _manager;
47 typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> > MidiNameDocuments;
49 virtual ~MidiPatchManager() { _manager = 0; }
51 static MidiPatchManager& instance() {
53 _manager = new MidiPatchManager();
58 void set_session (ARDOUR::Session&);
60 boost::shared_ptr<MIDINameDocument> document_by_model(std::string model_name)
61 { return _documents[model_name]; }
63 boost::shared_ptr<MasterDeviceNames> master_device_by_model(std::string model_name)
64 { return _master_devices_by_model[model_name]; }
66 boost::shared_ptr<ChannelNameSet> find_channel_name_set(
68 string custom_device_mode,
70 boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device = master_device_by_model(model);
72 if (master_device != 0 && custom_device_mode != "") {
73 return master_device->
74 channel_name_set_by_device_mode_and_channel(custom_device_mode, channel);
76 return boost::shared_ptr<ChannelNameSet>();
81 boost::shared_ptr<Patch> find_patch(
83 string custom_device_mode,
85 PatchPrimaryKey patch_key) {
87 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
89 if (channel_name_set) {
90 return channel_name_set->find_patch(patch_key);
92 return boost::shared_ptr<Patch>();
96 boost::shared_ptr<Patch> previous_patch(
98 string custom_device_mode,
100 PatchPrimaryKey patch_key) {
102 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
104 if (channel_name_set) {
105 return channel_name_set->previous_patch(patch_key);
107 return boost::shared_ptr<Patch>();
111 boost::shared_ptr<Patch> next_patch(
113 string custom_device_mode,
115 PatchPrimaryKey patch_key) {
117 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
119 if (channel_name_set) {
120 return channel_name_set->next_patch(patch_key);
122 return boost::shared_ptr<Patch>();
126 std::list<string> custom_device_mode_names_by_model(std::string model_name) {
127 if (model_name != "") {
128 return master_device_by_model(model_name)->custom_device_mode_names();
130 return std::list<string>();
134 const MasterDeviceNames::Models& all_models() const { return _all_models; }
140 ARDOUR::Session* _session;
141 MidiNameDocuments _documents;
142 MIDINameDocument::MasterDeviceNamesList _master_devices_by_model;
143 MasterDeviceNames::Models _all_models;
149 #endif /* MIDI_PATCH_MANAGER_H_ */