1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
12 |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
17 |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
23 |
|
24 |
#include "MidiInputDeviceFactory.h" |
25 |
|
26 |
#include "../../common/global_private.h" |
27 |
|
28 |
#if HAVE_ALSA |
29 |
# include "MidiInputDeviceAlsa.h" |
30 |
#endif // HAVE_ALSA |
31 |
|
32 |
#if HAVE_COREMIDI |
33 |
# include "MidiInputDeviceCoreMidi.h" |
34 |
#endif // HAVE_CORE_MIDI |
35 |
|
36 |
#if HAVE_MIDISHARE |
37 |
# include "MidiInputDeviceMidiShare.h" |
38 |
#endif // HAVE_MIDISHARE |
39 |
|
40 |
#if HAVE_MME_MIDI |
41 |
# include "MidiInputDeviceMme.h" |
42 |
#endif // HAVE_MME_MIDI |
43 |
|
44 |
#if HAVE_JACK_MIDI |
45 |
# include "MidiInputDeviceJack.h" |
46 |
#endif // HAVE_JACK_MIDI |
47 |
|
48 |
namespace LinuxSampler { |
49 |
|
50 |
std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories; |
51 |
std::map<String, DeviceParameterFactory*> MidiInputDeviceFactory::ParameterFactories; |
52 |
|
53 |
#if HAVE_ALSA |
54 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceAlsa); |
55 |
/* Common parameters */ |
56 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterActive); |
57 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts); |
58 |
#endif // HAVE_ALSA |
59 |
|
60 |
#if HAVE_COREMIDI |
61 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceCoreMidi); |
62 |
/* Common parameters */ |
63 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterActive); |
64 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterPorts); |
65 |
#endif // HAVE_COREMIDI |
66 |
|
67 |
#if HAVE_MIDISHARE |
68 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMidiShare); |
69 |
/* Common parameters */ |
70 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterActive); |
71 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterPorts); |
72 |
#endif // HAVE_MIDISHARE |
73 |
|
74 |
#if HAVE_MME_MIDI |
75 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMme); |
76 |
/* Common parameters */ |
77 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMme, ParameterActive); |
78 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMme, ParameterPorts); |
79 |
#endif // HAVE_MME_MIDI |
80 |
|
81 |
#if HAVE_JACK_MIDI |
82 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceJack); |
83 |
/* Common parameters */ |
84 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceJack, ParameterActive); |
85 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceJack, ParameterPorts); |
86 |
/* Driver specific parameters */ |
87 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceJack, ParameterName); |
88 |
#endif // HAVE_JACK_MIDI |
89 |
|
90 |
MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters, Sampler* pSampler) throw (Exception) { |
91 |
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
92 |
//Let's see if we need to create parameters |
93 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
94 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
95 |
if (pParamFactory) { |
96 |
thisDeviceParams = pParamFactory->CreateAllParams(Parameters); |
97 |
} else { |
98 |
//No parameters are registered by the driver. Throw if any parameters were specified. |
99 |
if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters."); |
100 |
} |
101 |
//Now create the device using those parameters |
102 |
MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams, pSampler); |
103 |
//Now attach all parameters to the newely created device. |
104 |
for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) { |
105 |
iter->second->Attach(pDevice); |
106 |
} |
107 |
return pDevice; |
108 |
} |
109 |
|
110 |
std::vector<String> MidiInputDeviceFactory::AvailableDrivers() { |
111 |
std::vector<String> result; |
112 |
std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin(); |
113 |
while (iter != InnerFactories.end()) { |
114 |
result.push_back(iter->first); |
115 |
iter++; |
116 |
} |
117 |
return result; |
118 |
} |
119 |
|
120 |
String MidiInputDeviceFactory::AvailableDriversAsString() { |
121 |
std::vector<String> drivers = AvailableDrivers(); |
122 |
String result; |
123 |
std::vector<String>::iterator iter = drivers.begin(); |
124 |
for (; iter != drivers.end(); iter++) { |
125 |
if (result != "") result += ","; |
126 |
result += *iter; |
127 |
} |
128 |
return result; |
129 |
} |
130 |
|
131 |
std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) { |
132 |
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
133 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
134 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
135 |
if (pParamFactory) { |
136 |
thisDeviceParams = pParamFactory->CreateAllParams(); |
137 |
} |
138 |
return thisDeviceParams; |
139 |
} |
140 |
|
141 |
DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) { |
142 |
std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName); |
143 |
if (!parameters.count(ParameterName)) throw Exception("Midi input driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'."); |
144 |
return parameters[ParameterName]; |
145 |
} |
146 |
|
147 |
String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) { |
148 |
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
149 |
return InnerFactories[DriverName]->Description(); |
150 |
} |
151 |
|
152 |
String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) { |
153 |
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
154 |
return InnerFactories[DriverName]->Version(); |
155 |
} |
156 |
|
157 |
} // namespace LinuxSampler |