From d97312d438a813985916dd35f613510e9448441f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 11 Jun 2012 22:59:35 +0000 Subject: 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 --- libs/ardour/ardour/instrument_info.h | 11 +++ libs/ardour/ardour/plugin.h | 30 ++++--- libs/ardour/ardour/route.h | 2 + libs/ardour/audio_unit.cc | 2 +- libs/ardour/instrument_info.cc | 107 +++++++++++++++++++++++- libs/ardour/route.cc | 37 +++++---- libs/ardour/vst_plugin.cc | 4 +- libs/midi++2/midi++/midnam_patch.h | 4 + libs/midi++2/midnam_patch.cc | 152 +++++++++++++++++++++++++++++++++++ 9 files changed, 315 insertions(+), 34 deletions(-) (limited to 'libs') 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 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 get_patches (uint8_t channel); + PBD::Signal0 Changed; + static const MIDI::Name::PatchBank::PatchNameList& general_midi_patches(); + private: std::string external_instrument_model; std::string external_instrument_mode; boost::weak_ptr internal_instrument; + + boost::shared_ptr plugin_programs_to_channel_name_set (boost::shared_ptr p); + std::string get_plugin_patch_name (boost::shared_ptr, 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 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_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 + #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 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 +InstrumentInfo::get_patches (uint8_t channel) +{ + boost::shared_ptr 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 +InstrumentInfo::plugin_programs_to_channel_name_set (boost::shared_ptr p) +{ + PatchBank::PatchNameList patch_list; + + boost::shared_ptr insert = boost::dynamic_pointer_cast (p); + + if (!insert) { + return boost::shared_ptr(); + } + + boost::shared_ptr 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 presets = pp->get_presets (); + std::vector::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 (new Patch (string_compose ("%1", n), (*i).label))); + } else { + patch_list.push_back (boost::shared_ptr (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 (new Patch (string_compose ("%1", n), + string_compose ("program %1", n)))); + } + } + + boost::shared_ptr pb (new PatchBank (p->name())); + pb->set_patch_name_list (patch_list); + + ChannelNameSet::PatchBanks patch_banks; + patch_banks.push_back (pb); + + boost::shared_ptr 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 (new Patch (string_compose ("%1", n), general_midi_program_names[n]))); + } + } + + return _gm_patches; +} + +string +InstrumentInfo::get_plugin_patch_name (boost::shared_ptr p, uint16_t bank, uint8_t program, uint8_t channel) const +{ + boost::shared_ptr insert = boost::dynamic_pointer_cast (p); + + if (insert) { + boost::shared_ptr 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, boost::shared_ptr< _output->set_user_latency (0); } - boost::shared_ptr 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 _output->set_user_latency (0); } - boost::shared_ptr 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()); + reset_instrument_info (); if (!already_deleting) { _session.clear_deletion_in_progress(); @@ -1478,11 +1470,7 @@ Route::remove_processor (boost::shared_ptr processor, ProcessorStream } } - boost::shared_ptr 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 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(*i)) { + if ((*i)->input_streams().n_midi() > 0 && + (*i)->output_streams().n_audio() > 0) { + return (*i); + } } } return boost::shared_ptr(); 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)); } } diff --git a/libs/midi++2/midi++/midnam_patch.h b/libs/midi++2/midi++/midnam_patch.h index cbf64299ea..276b402086 100644 --- a/libs/midi++2/midi++/midnam_patch.h +++ b/libs/midi++2/midi++/midnam_patch.h @@ -200,6 +200,8 @@ public: XMLNode& get_state (void); int set_state (const XMLTree&, const XMLNode&); + void set_patch_banks (const PatchBanks&); + private: std::string _name; AvailableForChannels _available_for_channels; @@ -352,6 +354,8 @@ private: MasterDeviceNames::Models _all_models; }; +extern const char* general_midi_program_names[128]; /* 0 .. 127 */ + } } diff --git a/libs/midi++2/midnam_patch.cc b/libs/midi++2/midnam_patch.cc index 66d3219310..1ad5cf9dc5 100644 --- a/libs/midi++2/midnam_patch.cc +++ b/libs/midi++2/midnam_patch.cc @@ -262,6 +262,28 @@ PatchBank::set_patch_name_list (const PatchNameList& pnl) return 0; } +void +ChannelNameSet::set_patch_banks (const ChannelNameSet::PatchBanks& pb) +{ + _patch_banks = pb; + + _patch_map.clear (); + _patch_list.clear (); + _patch_list_name = ""; + _available_for_channels.clear (); + + for (PatchBanks::const_iterator pbi = _patch_banks.begin(); pbi != _patch_banks.end(); ++pbi) { + for (PatchBank::PatchNameList::const_iterator pni = (*pbi)->patch_name_list().begin(); pni != (*pbi)->patch_name_list().end(); ++pni) { + _patch_map[(*pni)->patch_primary_key()] = (*pni); + _patch_list.push_back ((*pni)->patch_primary_key()); + } + } + + for (uint8_t n = 0; n < 16; ++n) { + _available_for_channels.insert (n); + } +} + XMLNode& ChannelNameSet::get_state (void) { @@ -526,6 +548,136 @@ MIDINameDocument::get_state(void) return nothing; } +const char* general_midi_program_names[128] = { + "Acoustic Grand Piano", + "Bright Acoustic Piano", + "Electric Grand Piano", + "Honky-tonk Piano", + "Rhodes Piano", + "Chorused Piano", + "Harpsichord", + "Clavinet", + "Celesta", + "Glockenspiel", + "Music Box", + "Vibraphone", + "Marimba", + "Xylophone", + "Tubular Bells", + "Dulcimer", + "Hammond Organ", + "Percussive Organ", + "Rock Organ", + "Church Organ", + "Reed Organ", + "Accordion", + "Harmonica", + "Tango Accordion", + "Acoustic Guitar (nylon)", + "Acoustic Guitar (steel)", + "Electric Guitar (jazz)", + "Electric Guitar (clean)", + "Electric Guitar (muted)", + "Overdriven Guitar", + "Distortion Guitar", + "Guitar Harmonics", + "Acoustic Bass", + "Electric Bass (finger)", + "Electric Bass (pick)", + "Fretless Bass", + "Slap Bass 1", + "Slap Bass 2", + "Synth Bass 1", + "Synth Bass 2", + "Violin", + "Viola", + "Cello", + "Contrabass", + "Tremolo Strings", + "Pizzicato Strings", + "Orchestral Harp", + "Timpani", + "String Ensemble 1", + "String Ensemble 2", + "SynthStrings 1", + "SynthStrings 2", + "Choir Aahs", + "Voice Oohs", + "Synth Voice", + "Orchestra Hit", + "Trumpet", + "Trombone", + "Tuba", + "Muted Trumpet", + "French Horn", + "Brass Section", + "Synth Brass 1", + "Synth Brass 2", + "Soprano Sax", + "Alto Sax", + "Tenor Sax", + "Baritone Sax", + "Oboe", + "English Horn", + "Bassoon", + "Clarinet", + "Piccolo", + "Flute", + "Recorder", + "Pan Flute", + "Bottle Blow", + "Shakuhachi", + "Whistle", + "Ocarina", + "Lead 1 (square)", + "Lead 2 (sawtooth)", + "Lead 3 (calliope lead)", + "Lead 4 (chiff lead)", + "Lead 5 (charang)", + "Lead 6 (voice)", + "Lead 7 (fifths)", + "Lead 8 (bass + lead)", + "Pad 1 (new age)", + "Pad 2 (warm)", + "Pad 3 (polysynth)", + "Pad 4 (choir)", + "Pad 5 (bowed)", + "Pad 6 (metallic)", + "Pad 7 (halo)", + "Pad 8 (sweep)", + "FX 1 (rain)", + "FX 2 (soundtrack)", + "FX 3 (crystal)", + "FX 4 (atmosphere)", + "FX 5 (brightness)", + "FX 6 (goblins)", + "FX 7 (echoes)", + "FX 8 (sci-fi)", + "Sitar", + "Banjo", + "Shamisen", + "Koto", + "Kalimba", + "Bagpipe", + "Fiddle", + "Shanai", + "Tinkle Bell", + "Agogo", + "Steel Drums", + "Woodblock", + "Taiko Drum", + "Melodic Tom", + "Synth Drum", + "Reverse Cymbal", + "Guitar Fret Noise", + "Breath Noise", + "Seashore", + "Bird Tweet", + "Telephone Ring", + "Helicopter", + "Applause", + "Gunshot", +}; } //namespace Name -- cgit v1.2.3