diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-06-11 12:07:17 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-06-11 12:07:17 +0000 |
commit | 960de7306f8573f6cb698cf031fad46daa3c741d (patch) | |
tree | 690e6312cbe1d25bfe3845cdd578b6c864d83ab8 /libs/ardour | |
parent | 80afb6e08b52f05d672df2d991265df713792010 (diff) |
partially-done (but compile-friendly) move of instrument info into a new backend object
git-svn-id: svn://localhost/ardour2/branches/3.0@12652 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
-rw-r--r-- | libs/ardour/ardour/instrument_info.h | 56 | ||||
-rw-r--r-- | libs/ardour/ardour/route.h | 4 | ||||
-rw-r--r-- | libs/ardour/instrument_info.cc | 100 | ||||
-rw-r--r-- | libs/ardour/route.cc | 17 | ||||
-rw-r--r-- | libs/ardour/wscript | 1 |
5 files changed, 178 insertions, 0 deletions
diff --git a/libs/ardour/ardour/instrument_info.h b/libs/ardour/ardour/instrument_info.h new file mode 100644 index 0000000000..d4c9bf4f46 --- /dev/null +++ b/libs/ardour/ardour/instrument_info.h @@ -0,0 +1,56 @@ +/* + Copyright (C) 2012 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef __ardour_instrument_info_h__ +#define __ardour_instrument_info_h__ + +#include <string> +#include <stdint.h> + +#include "pbd/signals.h" + +#include <boost/weak_ptr.hpp> + +namespace ARDOUR { + +class Processor; + +class InstrumentInfo { + public: + InstrumentInfo(); + ~InstrumentInfo (); + + void set_external_instrument (const std::string& model, const std::string& mode); + void set_internal_instrument (boost::shared_ptr<ARDOUR::Processor>); + + std::string get_patch_name (uint16_t bank, uint8_t program, uint8_t channel) const; + std::string get_instrument_name () const; + + PBD::Signal0<void> Changed; + + private: + std::string external_instrument_model; + std::string external_instrument_mode; + + boost::weak_ptr<ARDOUR::Processor> internal_instrument; +}; + +} /* namespace ARDOUR */ + + +#endif /* __ardour_instrument_info_h__ */ diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index bdda941a97..5a828513e3 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -41,6 +41,7 @@ #include "pbd/destructible.h" #include "ardour/ardour.h" +#include "ardour/instrument_info.h" #include "ardour/io.h" #include "ardour/types.h" #include "ardour/mute_master.h" @@ -405,6 +406,7 @@ class Route : public SessionObject, public Automatable, public RouteGroupMember, special case not covered by this utility function. */ boost::shared_ptr<Processor> the_instrument() const; + InstrumentInfo& instrument_info() { return _instrument_info; } void automation_snapshot (framepos_t now, bool force=false); void protect_automation (); @@ -500,6 +502,8 @@ class Route : public SessionObject, public Automatable, public RouteGroupMember, DataType _default_type; FedBy _fed_by; + InstrumentInfo _instrument_info; + virtual ChanCount input_streams () const; protected: diff --git a/libs/ardour/instrument_info.cc b/libs/ardour/instrument_info.cc new file mode 100644 index 0000000000..21e4bd1cd9 --- /dev/null +++ b/libs/ardour/instrument_info.cc @@ -0,0 +1,100 @@ +/* + Copyright (C) 2012 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "pbd/compose.h" + +#include "midi++/midnam_patch.h" + +#include "ardour/instrument_info.h" +#include "ardour/midi_patch_manager.h" +#include "ardour/processor.h" +#include "ardour/rc_configuration.h" + +#include "i18n.h" + +using namespace ARDOUR; +using std::string; + +InstrumentInfo::InstrumentInfo () + : external_instrument_model (_("Unknown")) +{ +} + +InstrumentInfo::~InstrumentInfo () +{ +} + +void +InstrumentInfo::set_external_instrument (const string& model, const string& mode) +{ + external_instrument_model = model; + external_instrument_mode = mode; + internal_instrument.reset (); + Changed(); /* EMIT SIGNAL */ +} + +void +InstrumentInfo::set_internal_instrument (boost::shared_ptr<Processor> p) +{ + internal_instrument = p; + external_instrument_model = (_("Unknown")); + external_instrument_mode = ""; + Changed(); /* EMIT SIGNAL */ +} + +string +InstrumentInfo::get_instrument_name () const +{ + boost::shared_ptr<Processor> p = internal_instrument.lock(); + + if (p) { + return p->name(); + } + + if (external_instrument_mode.empty()) { + return external_instrument_model; + } else { + return string_compose ("%1 (%2)", external_instrument_model, external_instrument_mode); + } +} + +string +InstrumentInfo::get_patch_name (uint16_t bank, uint8_t program, uint8_t channel) const +{ + boost::shared_ptr<Processor> p = internal_instrument.lock(); + + if (p) { + return "some plugin program"; + } + + MIDI::Name::PatchPrimaryKey patch_key (bank, program); + + boost::shared_ptr<MIDI::Name::Patch> patch = + MIDI::Name::MidiPatchManager::instance().find_patch (external_instrument_model, + external_instrument_mode, channel, patch_key); + + if (patch) { + return patch->name(); + } else { + /* program and bank numbers are zero-based: convert to one-based: MIDI_BP_ZERO */ + +#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); + } +} diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index f215e5d4f6..bd916458dd 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -1014,6 +1014,11 @@ 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); + } + processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */ set_processor_positions (); @@ -1162,6 +1167,11 @@ 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); + } + processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */ set_processor_positions (); @@ -1368,6 +1378,8 @@ Route::clear_processors (Placement p) processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */ set_processor_positions (); + _instrument_info.set_internal_instrument (boost::shared_ptr<Processor>()); + if (!already_deleting) { _session.clear_deletion_in_progress(); } @@ -1466,6 +1478,11 @@ Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStream } } + boost::shared_ptr<Processor> instr = the_instrument(); + if (instr) { + _instrument_info.set_internal_instrument (instr); + } + processor->drop_references (); processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */ set_processor_positions (); diff --git a/libs/ardour/wscript b/libs/ardour/wscript index 27a9ed0380..c0fcec8d29 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -105,6 +105,7 @@ libardour_sources = [ 'graph.cc', 'graphnode.cc', 'import.cc', + 'instrument_info.cc', 'internal_return.cc', 'internal_send.cc', 'interpolation.cc', |