use new syntax for connecting to backend signals that enforces explicit connection...
[ardour.git] / libs / ardour / ardour / midi_patch_manager.h
1 /*
2     Copyright (C) 2008 Hans Baier
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #ifndef MIDI_PATCH_MANAGER_H_
22 #define MIDI_PATCH_MANAGER_H_
23
24 #include "midi++/midnam_patch.h"
25 #include "pbd/signals.h"
26 #include "ardour/session_handle.h"
27
28 namespace ARDOUR {
29         class Session;
30 }
31
32 namespace MIDI
33 {
34
35 namespace Name
36 {
37
38 class MidiPatchManager : public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr
39 {
40         /// Singleton
41 private:
42         MidiPatchManager() {};
43         MidiPatchManager( const MidiPatchManager& );
44         MidiPatchManager& operator= (const MidiPatchManager&);
45
46         static MidiPatchManager* _manager;
47
48 public:
49         typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> > MidiNameDocuments;
50
51         virtual ~MidiPatchManager() { _manager = 0; }
52
53         static MidiPatchManager& instance() {
54                 if (_manager == 0) {
55                         _manager = new MidiPatchManager();
56                 }
57                 return *_manager;
58         }
59
60         void set_session (ARDOUR::Session*);
61
62         boost::shared_ptr<MIDINameDocument> document_by_model(std::string model_name)
63                 { return _documents[model_name]; }
64
65         boost::shared_ptr<MasterDeviceNames> master_device_by_model(std::string model_name)
66                 { return _master_devices_by_model[model_name]; }
67
68         boost::shared_ptr<ChannelNameSet> find_channel_name_set(
69                         std::string model,
70                         std::string custom_device_mode,
71                         uint8_t channel) {
72                 boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device = master_device_by_model(model);
73
74                 if (master_device != 0 && custom_device_mode != "") {
75                         return master_device->channel_name_set_by_device_mode_and_channel(custom_device_mode, channel);
76                 } else {
77                         return boost::shared_ptr<ChannelNameSet>();
78                 }
79         }
80
81         boost::shared_ptr<Patch> find_patch(
82                         std::string model,
83                         std::string custom_device_mode,
84                         uint8_t channel,
85                         PatchPrimaryKey patch_key) {
86
87                 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
88
89                 if (channel_name_set) {
90                         return  channel_name_set->find_patch(patch_key);
91                 } else {
92                         return boost::shared_ptr<Patch>();
93                 }
94         }
95
96         boost::shared_ptr<Patch> previous_patch(
97                         std::string model,
98                         std::string custom_device_mode,
99                         uint8_t channel,
100                         PatchPrimaryKey patch_key) {
101
102                 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
103
104                 if (channel_name_set) {
105                         return  channel_name_set->previous_patch(patch_key);
106                 } else {
107                         return boost::shared_ptr<Patch>();
108                 }
109         }
110
111         boost::shared_ptr<Patch> next_patch(
112                         std::string model,
113                         std::string custom_device_mode,
114                         uint8_t channel,
115                         PatchPrimaryKey patch_key) {
116
117                 boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
118
119                 if (channel_name_set) {
120                         return  channel_name_set->next_patch(patch_key);
121                 } else {
122                         return boost::shared_ptr<Patch>();
123                 }
124         }
125
126         std::list<std::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();
129                 } else {
130                         return std::list<std::string>();
131                 }
132         }
133
134         const MasterDeviceNames::Models& all_models() const { return _all_models; }
135
136 private:
137         void session_going_away();
138         void refresh();
139
140         MidiNameDocuments                       _documents;
141         MIDINameDocument::MasterDeviceNamesList _master_devices_by_model;
142         MasterDeviceNames::Models               _all_models;
143 };
144
145 } // namespace Name
146
147 } // namespace MIDI
148
149 #endif /* MIDI_PATCH_MANAGER_H_ */