partially-done (but compile-friendly) move of instrument info into a new backend...
[ardour.git] / libs / ardour / instrument_info.cc
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 "pbd/compose.h"
20
21 #include "midi++/midnam_patch.h"
22
23 #include "ardour/instrument_info.h"
24 #include "ardour/midi_patch_manager.h"
25 #include "ardour/processor.h"
26 #include "ardour/rc_configuration.h"
27
28 #include "i18n.h"
29
30 using namespace ARDOUR;
31 using std::string;
32
33 InstrumentInfo::InstrumentInfo ()
34         : external_instrument_model (_("Unknown"))
35 {
36 }
37
38 InstrumentInfo::~InstrumentInfo ()
39 {
40 }
41
42 void
43 InstrumentInfo::set_external_instrument (const string& model, const string& mode)
44 {
45         external_instrument_model = model;
46         external_instrument_mode = mode;
47         internal_instrument.reset ();
48         Changed(); /* EMIT SIGNAL */
49 }
50
51 void
52 InstrumentInfo::set_internal_instrument (boost::shared_ptr<Processor> p)
53 {
54         internal_instrument = p;
55         external_instrument_model = (_("Unknown"));
56         external_instrument_mode = "";
57         Changed(); /* EMIT SIGNAL */
58 }
59
60 string
61 InstrumentInfo::get_instrument_name () const
62 {
63         boost::shared_ptr<Processor> p = internal_instrument.lock();
64
65         if (p) {
66                 return p->name();
67         }
68
69         if (external_instrument_mode.empty()) {
70                 return external_instrument_model;
71         } else {
72                 return string_compose ("%1 (%2)", external_instrument_model, external_instrument_mode);
73         }
74 }
75
76 string
77 InstrumentInfo::get_patch_name (uint16_t bank, uint8_t program, uint8_t channel) const
78 {
79         boost::shared_ptr<Processor> p = internal_instrument.lock();
80
81         if (p) {
82                 return "some plugin program";
83         }
84
85         MIDI::Name::PatchPrimaryKey patch_key (bank, program);
86         
87         boost::shared_ptr<MIDI::Name::Patch> patch =
88                 MIDI::Name::MidiPatchManager::instance().find_patch (external_instrument_model, 
89                                                                      external_instrument_mode, channel, patch_key);
90
91         if (patch) {
92                 return patch->name();
93         } else {
94                 /* program and bank numbers are zero-based: convert to one-based: MIDI_BP_ZERO */
95
96 #define MIDI_BP_ZERO ((Config->get_first_midi_bank_is_zero())?0:1)
97
98                 return string_compose ("%1 %2",program + MIDI_BP_ZERO , bank + MIDI_BP_ZERO);
99         }
100 }