ardour
instrument_info.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Paul Davis
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 
19 #include <algorithm>
20 
21 #include "pbd/compose.h"
22 
23 #include "midi++/midnam_patch.h"
24 
25 #include "ardour/instrument_info.h"
27 #include "ardour/processor.h"
28 #include "ardour/plugin.h"
29 #include "ardour/plugin_insert.h"
31 
32 #include "i18n.h"
33 
34 using namespace ARDOUR;
35 using namespace MIDI::Name;
36 using std::string;
37 
39 
41  : external_instrument_model (_("Unknown"))
42 {
43 }
44 
46 {
47 }
48 
49 void
50 InstrumentInfo::set_external_instrument (const string& model, const string& mode)
51 {
54  internal_instrument.reset ();
55  Changed(); /* EMIT SIGNAL */
56 }
57 
58 void
60 {
62  external_instrument_model = (_("Unknown"));
64  Changed(); /* EMIT SIGNAL */
65 }
66 
67 string
69 {
71  if (p) {
72  return p->name();
73  }
74 
75  if (external_instrument_mode.empty()) {
77  } else {
79  }
80 }
81 
82 string
83 InstrumentInfo::get_patch_name (uint16_t bank, uint8_t program, uint8_t channel) const
84 {
86  if (p) {
87  return get_plugin_patch_name (p, bank, program, channel);
88  }
89 
90  MIDI::Name::PatchPrimaryKey patch_key (program, bank);
91 
94  external_instrument_mode, channel, patch_key);
95 
96  if (patch) {
97  return patch->name();
98  } else {
99  /* program and bank numbers are zero-based: convert to one-based: MIDI_BP_ZERO */
100 
101 #define MIDI_BP_ZERO ((Config->get_first_midi_bank_is_zero())?0:1)
102 
103  return string_compose ("prg %1 bnk %2",program + MIDI_BP_ZERO , bank + MIDI_BP_ZERO);
104  }
105 }
106 
107 string
109 {
111  if (p || param.type() != MidiCCAutomation) {
112  return "";
113  }
114 
116  MIDI::Name::MidiPatchManager::instance().master_device_by_model(
118  if (!dev_names) {
119  return "";
120  }
121 
123  dev_names->channel_name_set_by_channel(
125  if (!chan_names) {
126  return "";
127  }
128 
130  dev_names->control_name_list(chan_names->control_list_name()));
131  if (!control_names) {
132  return "";
133  }
134 
135  return control_names->control(param.id())->name();
136 }
137 
140 {
142  if (p) {
144  }
145 
147  MidiPatchManager::instance().find_channel_name_set (external_instrument_model,
149  channel);
150 
151  //std::cerr << "got channel name set with name '" << channel_name_set->name() << std::endl;
152 
153  return channel_name_set;
154 }
155 
158 {
159  PatchNameList patch_list;
160 
162  if (!insert) {
164  }
165 
166  boost::shared_ptr<Plugin> pp = insert->plugin();
167 
169 
170  patch_list = InstrumentInfo::general_midi_patches ();
171 
172  } else if (pp->presets_are_MIDI_programs()) {
173 
174  std::vector<Plugin::PresetRecord> presets = pp->get_presets ();
175  std::vector<Plugin::PresetRecord>::iterator i;
176  int n;
177 
178  /* XXX note the assumption that plugin presets start their numbering at
179  * zero
180  */
181 
182  for (n = 0, i = presets.begin(); i != presets.end(); ++i, ++n) {
183  if ((*i).number >= 0) {
184  patch_list.push_back (boost::shared_ptr<Patch> (new Patch ((*i).label, n)));
185  } else {
186  patch_list.push_back (boost::shared_ptr<Patch> (new Patch (string_compose ("program %1", n), n)));
187  }
188  }
189  } else {
190  for (int n = 0; n < 127; ++n) {
191  patch_list.push_back (boost::shared_ptr<Patch> (new Patch (string_compose ("program %1", n), n)));
192  }
193  }
194 
195  boost::shared_ptr<PatchBank> pb (new PatchBank (0, p->name()));
196  pb->set_patch_name_list (patch_list);
197 
198  ChannelNameSet::PatchBanks patch_banks;
199  patch_banks.push_back (pb);
200 
201  boost::shared_ptr<MIDI::Name::ChannelNameSet> cns (new ChannelNameSet);
202  cns->set_patch_banks (patch_banks);
203 
204  return cns;
205 }
206 
209 {
210  if (_gm_patches.empty()) {
211  for (int n = 0; n < 128; n++) {
212  _gm_patches.push_back (boost::shared_ptr<Patch> (new Patch (general_midi_program_names[n], n)));
213  }
214  }
215 
216  return _gm_patches;
217 }
218 
219 string
220 InstrumentInfo::get_plugin_patch_name (boost::shared_ptr<Processor> p, uint16_t bank, uint8_t program, uint8_t /*channel*/) const
221 {
223  if (insert) {
224  boost::shared_ptr<Plugin> pp = insert->plugin();
225 
227  return MIDI::Name::general_midi_program_names[std::min((uint8_t) 127,program)];
228  }
229  }
230 
231  return string_compose (_("preset %1 (bank %2)"), (int) program, (int) bank);
232 }
#define MIDI_BP_ZERO
boost::shared_ptr< MIDI::Name::ChannelNameSet > plugin_programs_to_channel_name_set(boost::shared_ptr< Processor > p)
std::string get_patch_name(uint16_t bank, uint8_t program, uint8_t channel) const
std::string get_controller_name(Evoral::Parameter param) const
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr.hpp:396
void set_external_instrument(const std::string &model, const std::string &mode)
boost::shared_ptr< MIDI::Name::ChannelNameSet > get_patches(uint8_t channel)
PBD::Signal0< void > Changed
virtual bool current_preset_uses_general_midi() const
Definition: plugin.h:187
boost::shared_ptr< Plugin > plugin(uint32_t num=0) const
static MIDI::Name::PatchNameList _gm_patches
#define _(Text)
Definition: i18n.h:11
virtual bool presets_are_MIDI_programs() const
Definition: plugin.h:178
Definition: amp.h:29
std::string external_instrument_mode
boost::weak_ptr< ARDOUR::Processor > internal_instrument
std::string get_plugin_patch_name(boost::shared_ptr< ARDOUR::Processor >, uint16_t bank, uint8_t program, uint8_t channel) const
void set_internal_instrument(boost::shared_ptr< ARDOUR::Processor >)
const char * name
uint32_t id() const
Definition: Parameter.hpp:49
static const MIDI::Name::PatchNameList & general_midi_patches()
boost::shared_ptr< Patch > find_patch(std::string model, std::string custom_device_mode, uint8_t channel, PatchPrimaryKey patch_key)
std::string name() const
std::list< boost::shared_ptr< Patch > > PatchNameList
uint32_t type() const
Definition: Parameter.hpp:47
std::string get_instrument_name() const
uint8_t channel() const
Definition: Parameter.hpp:48
std::vector< PresetRecord > get_presets()
Definition: plugin.cc:313
static MidiPatchManager & instance()
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
std::string external_instrument_model