summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2012-06-11 22:59:35 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2012-06-11 22:59:35 +0000
commitd97312d438a813985916dd35f613510e9448441f (patch)
tree5be2844fc16359c2eb550b72c9f84737c534d614 /libs/ardour
parentc81691741118ab34c5f6f458c2d84f431e481ada (diff)
lots more work trying to create a common structure for accessing plugin and MIDNAME patch/preset/program names. still not done
git-svn-id: svn://localhost/ardour2/branches/3.0@12665 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/ardour/instrument_info.h11
-rw-r--r--libs/ardour/ardour/plugin.h30
-rw-r--r--libs/ardour/ardour/route.h2
-rw-r--r--libs/ardour/audio_unit.cc2
-rw-r--r--libs/ardour/instrument_info.cc107
-rw-r--r--libs/ardour/route.cc37
-rw-r--r--libs/ardour/vst_plugin.cc4
7 files changed, 159 insertions, 34 deletions
diff --git a/libs/ardour/ardour/instrument_info.h b/libs/ardour/ardour/instrument_info.h
index d4c9bf4f46..f83b2c0632 100644
--- a/libs/ardour/ardour/instrument_info.h
+++ b/libs/ardour/ardour/instrument_info.h
@@ -24,6 +24,8 @@
#include "pbd/signals.h"
+#include "midi++/midnam_patch.h"
+
#include <boost/weak_ptr.hpp>
namespace ARDOUR {
@@ -41,13 +43,22 @@ class InstrumentInfo {
std::string get_patch_name (uint16_t bank, uint8_t program, uint8_t channel) const;
std::string get_instrument_name () const;
+ boost::shared_ptr<MIDI::Name::ChannelNameSet> get_patches (uint8_t channel);
+
PBD::Signal0<void> Changed;
+ static const MIDI::Name::PatchBank::PatchNameList& general_midi_patches();
+
private:
std::string external_instrument_model;
std::string external_instrument_mode;
boost::weak_ptr<ARDOUR::Processor> internal_instrument;
+
+ boost::shared_ptr<MIDI::Name::ChannelNameSet> plugin_programs_to_channel_name_set (boost::shared_ptr<Processor> p);
+ std::string get_plugin_patch_name (boost::shared_ptr<ARDOUR::Processor>, uint16_t bank, uint8_t program, uint8_t channel) const;
+
+ static MIDI::Name::PatchBank::PatchNameList _gm_patches;
};
} /* namespace ARDOUR */
diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h
index cfdf0e8121..f33fb9d1e5 100644
--- a/libs/ardour/ardour/plugin.h
+++ b/libs/ardour/ardour/plugin.h
@@ -166,16 +166,17 @@ class Plugin : public PBD::StatefulDestructible, public Latent
void monitoring_changed ();
struct PresetRecord {
- PresetRecord () : user (true) {}
- PresetRecord (const std::string& u, const std::string& l, bool s = true) : uri (u), label (l), user (s) {}
-
- bool operator!= (PresetRecord const & a) const {
- return uri != a.uri || label != a.label;
- }
-
- std::string uri;
- std::string label;
- bool user;
+ PresetRecord () : number (-1), user (true) {}
+ PresetRecord (const std::string& u, const std::string& l, int n = -1, bool s = true) : uri (u), label (l), number (n), user (s) {}
+
+ bool operator!= (PresetRecord const & a) const {
+ return number != a.number || uri != a.uri || label != a.label;
+ }
+
+ std::string uri;
+ std::string label;
+ int number; // if <0, invalid
+ bool user;
};
PresetRecord save_preset (std::string);
@@ -188,6 +189,15 @@ class Plugin : public PBD::StatefulDestructible, public Latent
std::vector<PresetRecord> get_presets ();
+ /* This is hard to return a correct value for because most plugin APIs
+ do not specify plugin behaviour. However, if you want to force
+ the display of plugin built-in preset names rather than MIDI program
+ numbers, return true. If you want a generic description, return
+ false.
+ */
+ virtual bool presets_are_MIDI_programs() const { return true; }
+ virtual bool current_preset_uses_general_midi() const { return true; }
+
/** @return Last preset to be requested; the settings may have
* been changed since; find out with parameter_changed_since_last_preset.
*/
diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h
index 5a828513e3..d1248d8b03 100644
--- a/libs/ardour/ardour/route.h
+++ b/libs/ardour/ardour/route.h
@@ -603,6 +603,8 @@ class Route : public SessionObject, public Automatable, public RouteGroupMember,
boost::weak_ptr<Processor> _processor_after_last_custom_meter;
/** true if the last custom meter position was at the end of the processor list */
bool _last_custom_meter_was_at_end;
+
+ void reset_instrument_info ();
};
} // namespace ARDOUR
diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc
index 9151e76bec..52e329bb87 100644
--- a/libs/ardour/audio_unit.cc
+++ b/libs/ardour/audio_unit.cc
@@ -2107,7 +2107,7 @@ AUPlugin::find_presets ()
for (FactoryPresetMap::iterator i = factory_preset_map.begin(); i != factory_preset_map.end(); ++i) {
/* XXX: dubious */
string const uri = string_compose ("%1", _presets.size ());
- _presets.insert (make_pair (uri, Plugin::PresetRecord (uri, i->first)));
+ _presets.insert (make_pair (uri, Plugin::PresetRecord (uri, i->first, i->second)));
}
#endif
diff --git a/libs/ardour/instrument_info.cc b/libs/ardour/instrument_info.cc
index 21e4bd1cd9..c83f7ae321 100644
--- a/libs/ardour/instrument_info.cc
+++ b/libs/ardour/instrument_info.cc
@@ -16,6 +16,8 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <algorithm>
+
#include "pbd/compose.h"
#include "midi++/midnam_patch.h"
@@ -23,13 +25,17 @@
#include "ardour/instrument_info.h"
#include "ardour/midi_patch_manager.h"
#include "ardour/processor.h"
+#include "ardour/plugin.h"
#include "ardour/rc_configuration.h"
#include "i18n.h"
using namespace ARDOUR;
+using namespace MIDI::Name;
using std::string;
+MIDI::Name::PatchBank::PatchNameList InstrumentInfo::_gm_patches;
+
InstrumentInfo::InstrumentInfo ()
: external_instrument_model (_("Unknown"))
{
@@ -79,7 +85,7 @@ InstrumentInfo::get_patch_name (uint16_t bank, uint8_t program, uint8_t channel)
boost::shared_ptr<Processor> p = internal_instrument.lock();
if (p) {
- return "some plugin program";
+ return get_plugin_patch_name (p, bank, program, channel);
}
MIDI::Name::PatchPrimaryKey patch_key (bank, program);
@@ -95,6 +101,103 @@ InstrumentInfo::get_patch_name (uint16_t bank, uint8_t program, uint8_t channel)
#define MIDI_BP_ZERO ((Config->get_first_midi_bank_is_zero())?0:1)
- return string_compose ("%1 %2",program + MIDI_BP_ZERO , bank + MIDI_BP_ZERO);
+ return string_compose ("prg %1 bnk %2",program + MIDI_BP_ZERO , bank + MIDI_BP_ZERO);
}
}
+
+boost::shared_ptr<MIDI::Name::ChannelNameSet>
+InstrumentInfo::get_patches (uint8_t channel)
+{
+ boost::shared_ptr<Processor> p = internal_instrument.lock();
+
+ if (p) {
+ return plugin_programs_to_channel_name_set (p);
+ }
+
+ return MidiPatchManager::instance().find_channel_name_set (external_instrument_model,
+ external_instrument_mode,
+ channel);
+
+}
+
+boost::shared_ptr<MIDI::Name::ChannelNameSet>
+InstrumentInfo::plugin_programs_to_channel_name_set (boost::shared_ptr<Processor> p)
+{
+ PatchBank::PatchNameList patch_list;
+
+ boost::shared_ptr<PluginInsert> insert = boost::dynamic_pointer_cast<PluginInsert> (p);
+
+ if (!insert) {
+ return boost::shared_ptr<ChannelNameSet>();
+ }
+
+ boost::shared_ptr<Plugin> pp = insert->plugin();
+
+ if (pp->current_preset_uses_general_midi()) {
+
+ patch_list = InstrumentInfo::general_midi_patches ();
+
+ } else if (pp->presets_are_MIDI_programs()) {
+
+ std::vector<Plugin::PresetRecord> presets = pp->get_presets ();
+ std::vector<Plugin::PresetRecord>::iterator i;
+ int n;
+
+ /* XXX note the assumption that plugin presets start their numbering at
+ * zero
+ */
+
+ for (n = 0, i = presets.begin(); i != presets.end(); ++i, ++n) {
+ if ((*i).number >= 0) {
+ patch_list.push_back (boost::shared_ptr<Patch> (new Patch (string_compose ("%1", n), (*i).label)));
+ } else {
+ patch_list.push_back (boost::shared_ptr<Patch> (new Patch (string_compose ("%1", n),
+ string_compose ("program %1", n))));
+ }
+ }
+ } else {
+ for (int n = 0; n < 127; ++n) {
+ patch_list.push_back (boost::shared_ptr<Patch> (new Patch (string_compose ("%1", n),
+ string_compose ("program %1", n))));
+ }
+ }
+
+ boost::shared_ptr<PatchBank> pb (new PatchBank (p->name()));
+ pb->set_patch_name_list (patch_list);
+
+ ChannelNameSet::PatchBanks patch_banks;
+ patch_banks.push_back (pb);
+
+ boost::shared_ptr<MIDI::Name::ChannelNameSet> cns (new ChannelNameSet);
+ cns->set_patch_banks (patch_banks);
+
+ return cns;
+}
+
+const MIDI::Name::PatchBank::PatchNameList&
+InstrumentInfo::general_midi_patches()
+{
+ if (_gm_patches.empty()) {
+ for (int n = 0; n < 128; n++) {
+ _gm_patches.push_back (boost::shared_ptr<Patch> (new Patch (string_compose ("%1", n), general_midi_program_names[n])));
+ }
+ }
+
+ return _gm_patches;
+}
+
+string
+InstrumentInfo::get_plugin_patch_name (boost::shared_ptr<Processor> p, uint16_t bank, uint8_t program, uint8_t channel) const
+{
+ boost::shared_ptr<PluginInsert> insert = boost::dynamic_pointer_cast<PluginInsert> (p);
+
+ if (insert) {
+ boost::shared_ptr<Plugin> pp = insert->plugin();
+
+ if (pp->current_preset_uses_general_midi()) {
+ return MIDI::Name::general_midi_program_names[std::min((uint8_t) 127,program)];
+ }
+ }
+
+ return string_compose (_("preset %1 (bank %2)"), (int) program, (int) bank);
+}
diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc
index bd916458dd..318524d8ed 100644
--- a/libs/ardour/route.cc
+++ b/libs/ardour/route.cc
@@ -1014,11 +1014,7 @@ Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<
_output->set_user_latency (0);
}
- boost::shared_ptr<Processor> instr = the_instrument();
- if (instr) {
- _instrument_info.set_internal_instrument (instr);
- }
-
+ reset_instrument_info ();
processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
set_processor_positions ();
@@ -1167,11 +1163,7 @@ Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor>
_output->set_user_latency (0);
}
- boost::shared_ptr<Processor> instr = the_instrument();
- if (instr) {
- _instrument_info.set_internal_instrument (instr);
- }
-
+ reset_instrument_info ();
processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
set_processor_positions ();
@@ -1378,7 +1370,7 @@ Route::clear_processors (Placement p)
processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
set_processor_positions ();
- _instrument_info.set_internal_instrument (boost::shared_ptr<Processor>());
+ reset_instrument_info ();
if (!already_deleting) {
_session.clear_deletion_in_progress();
@@ -1478,11 +1470,7 @@ Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStream
}
}
- boost::shared_ptr<Processor> instr = the_instrument();
- if (instr) {
- _instrument_info.set_internal_instrument (instr);
- }
-
+ reset_instrument_info ();
processor->drop_references ();
processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
set_processor_positions ();
@@ -1579,12 +1567,20 @@ Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams*
(*i)->drop_references ();
}
+ reset_instrument_info ();
processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
set_processor_positions ();
return 0;
}
+void
+Route::reset_instrument_info ()
+{
+ boost::shared_ptr<Processor> instr = the_instrument();
+ _instrument_info.set_internal_instrument (instr);
+}
+
/** Caller must hold process lock */
int
Route::configure_processors (ProcessorStreams* err)
@@ -2543,6 +2539,7 @@ Route::set_processor_state (const XMLNode& node)
}
}
+ reset_instrument_info ();
processors_changed (RouteProcessorChange ());
set_processor_positions ();
}
@@ -4067,9 +4064,11 @@ Route::the_instrument () const
{
Glib::RWLock::WriterLock lm (_processor_lock);
for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
- if ((*i)->input_streams().n_midi() > 0 &&
- (*i)->output_streams().n_audio() > 0) {
- return (*i);
+ if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
+ if ((*i)->input_streams().n_midi() > 0 &&
+ (*i)->output_streams().n_audio() > 0) {
+ return (*i);
+ }
}
}
return boost::shared_ptr<Processor>();
diff --git a/libs/ardour/vst_plugin.cc b/libs/ardour/vst_plugin.cc
index 1afc496b16..84186fd672 100644
--- a/libs/ardour/vst_plugin.cc
+++ b/libs/ardour/vst_plugin.cc
@@ -598,7 +598,7 @@ VSTPlugin::find_presets ()
int const vst_version = _plugin->dispatcher (_plugin, effGetVstVersion, 0, 0, NULL, 0);
for (int i = 0; i < _plugin->numPrograms; ++i) {
- PresetRecord r (string_compose (X_("VST:%1:%2"), unique_id (), i), "", false);
+ PresetRecord r (string_compose (X_("VST:%1:%2"), unique_id (), i), "", -1, false);
if (vst_version >= 2) {
char buf[256];
@@ -628,7 +628,7 @@ VSTPlugin::find_presets ()
assert (uri);
assert (label);
- PresetRecord r (uri->value(), label->value(), true);
+ PresetRecord r (uri->value(), label->value(), -1, true);
_presets.insert (make_pair (r.uri, r));
}
}