ardour
midi_patch_manager.h
Go to the documentation of this file.
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 
39 {
41 private:
44  MidiPatchManager& operator= (const MidiPatchManager&);
45 
47 
48 public:
49  typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> > MidiNameDocuments;
50  typedef std::map<std::string, MIDINameDocument::MasterDeviceNamesList> DeviceNamesByMaker;
51 
52  virtual ~MidiPatchManager() { _manager = 0; }
53 
55  if (_manager == 0) {
56  _manager = new MidiPatchManager();
57  }
58  return *_manager;
59  }
60 
61  void set_session (ARDOUR::Session*);
62 
64  { return _documents[model_name]; }
65 
67  { return _master_devices_by_model[model_name]; }
68 
70  std::string model,
71  std::string custom_device_mode,
72  uint8_t channel) {
73  boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device = master_device_by_model(model);
74 
75  if (master_device != 0 && custom_device_mode != "") {
76  return master_device->channel_name_set_by_channel(custom_device_mode, channel);
77  } else {
79  }
80  }
81 
83  std::string model,
84  std::string custom_device_mode,
85  uint8_t channel,
86  PatchPrimaryKey patch_key) {
87 
88  boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
89 
90  if (channel_name_set) {
91  return channel_name_set->find_patch(patch_key);
92  } else {
93  return boost::shared_ptr<Patch>();
94  }
95  }
96 
98  std::string model,
99  std::string custom_device_mode,
100  uint8_t channel,
101  PatchPrimaryKey patch_key) {
102 
103  boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
104 
105  if (channel_name_set) {
106  return channel_name_set->previous_patch(patch_key);
107  } else {
108  return boost::shared_ptr<Patch>();
109  }
110  }
111 
113  std::string model,
114  std::string custom_device_mode,
115  uint8_t channel,
116  PatchPrimaryKey patch_key) {
117 
118  boost::shared_ptr<ChannelNameSet> channel_name_set = find_channel_name_set(model, custom_device_mode, channel);
119 
120  if (channel_name_set) {
121  return channel_name_set->next_patch(patch_key);
122  } else {
123  return boost::shared_ptr<Patch>();
124  }
125  }
126 
127  std::list<std::string> custom_device_mode_names_by_model(std::string model_name) {
128  if (model_name != "") {
129  if (master_device_by_model(model_name)) {
130  return master_device_by_model(model_name)->custom_device_mode_names();
131  }
132  }
133  return std::list<std::string>();
134  }
135 
136  const MasterDeviceNames::Models& all_models() const { return _all_models; }
137 
138  const DeviceNamesByMaker& devices_by_manufacturer() const { return _devices_by_manufacturer; }
139 
140 private:
141  void session_going_away();
142  void refresh();
143  void add_session_patches();
144 
145  MidiNameDocuments _documents;
146  MIDINameDocument::MasterDeviceNamesList _master_devices_by_model;
147  DeviceNamesByMaker _devices_by_manufacturer;
148  MasterDeviceNames::Models _all_models;
149 };
150 
151 } // namespace Name
152 
153 } // namespace MIDI
154 
155 #endif /* MIDI_PATCH_MANAGER_H_ */
MasterDeviceNames::Models _all_models
std::list< std::string > custom_device_mode_names_by_model(std::string model_name)
boost::shared_ptr< Patch > next_patch(std::string model, std::string custom_device_mode, uint8_t channel, PatchPrimaryKey patch_key)
static MidiPatchManager * _manager
std::map< std::string, MIDINameDocument::MasterDeviceNamesList > DeviceNamesByMaker
Definition: amp.h:29
MIDINameDocument::MasterDeviceNamesList _master_devices_by_model
boost::shared_ptr< MasterDeviceNames > master_device_by_model(std::string model_name)
#define LIBARDOUR_API
DeviceNamesByMaker _devices_by_manufacturer
const MasterDeviceNames::Models & all_models() const
boost::shared_ptr< Patch > find_patch(std::string model, std::string custom_device_mode, uint8_t channel, PatchPrimaryKey patch_key)
boost::shared_ptr< ChannelNameSet > find_channel_name_set(std::string model, std::string custom_device_mode, uint8_t channel)
std::map< std::string, boost::shared_ptr< MIDINameDocument > > MidiNameDocuments
boost::shared_ptr< MIDINameDocument > document_by_model(std::string model_name)
static MidiPatchManager & instance()
boost::shared_ptr< Patch > previous_patch(std::string model, std::string custom_device_mode, uint8_t channel, PatchPrimaryKey patch_key)
Definition: ardour.h:41
const DeviceNamesByMaker & devices_by_manufacturer() const