1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 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 |
#if HAVE_ALSA |
27 |
# include "MidiInputDeviceAlsa.h" |
28 |
#endif // HAVE_ALSA |
29 |
|
30 |
#if HAVE_COREMIDI |
31 |
# include "MidiInputDeviceCoreMidi.h" |
32 |
#endif // HAVE_CORE_MIDI |
33 |
|
34 |
#if HAVE_MIDISHARE |
35 |
# include "MidiInputDeviceMidiShare.h" |
36 |
#endif // HAVE_MIDISHARE |
37 |
|
38 |
namespace LinuxSampler { |
39 |
|
40 |
std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories; |
41 |
std::map<String, DeviceParameterFactory*> MidiInputDeviceFactory::ParameterFactories; |
42 |
|
43 |
#if HAVE_ALSA |
44 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceAlsa); |
45 |
/* Common parameters */ |
46 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterActive); |
47 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts); |
48 |
#endif // HAVE_ALSA |
49 |
|
50 |
#if HAVE_COREMIDI |
51 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceCoreMidi); |
52 |
/* Common parameters */ |
53 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterActive); |
54 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterPorts); |
55 |
#endif // HAVE_COREMIDI |
56 |
|
57 |
#if HAVE_MIDISHARE |
58 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMidiShare); |
59 |
/* Common parameters */ |
60 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterActive); |
61 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterPorts); |
62 |
#endif // HAVE_MIDISHARE |
63 |
|
64 |
MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters, Sampler* pSampler) throw (LinuxSamplerException) { |
65 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
66 |
//Let's see if we need to create parameters |
67 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
68 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
69 |
if (pParamFactory) { |
70 |
thisDeviceParams = pParamFactory->CreateAllParams(Parameters); |
71 |
} else { |
72 |
//No parameters are registered by the driver. Throw if any parameters were specified. |
73 |
if (Parameters.size() != 0) throw LinuxSamplerException("Driver '" + DriverName + "' does not have any parameters."); |
74 |
} |
75 |
//Now create the device using those parameters |
76 |
MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams, pSampler); |
77 |
//Now attach all parameters to the newely created device. |
78 |
for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) { |
79 |
iter->second->Attach(pDevice); |
80 |
} |
81 |
return pDevice; |
82 |
} |
83 |
|
84 |
std::vector<String> MidiInputDeviceFactory::AvailableDrivers() { |
85 |
std::vector<String> result; |
86 |
std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin(); |
87 |
while (iter != InnerFactories.end()) { |
88 |
result.push_back(iter->first); |
89 |
iter++; |
90 |
} |
91 |
return result; |
92 |
} |
93 |
|
94 |
String MidiInputDeviceFactory::AvailableDriversAsString() { |
95 |
std::vector<String> drivers = AvailableDrivers(); |
96 |
String result; |
97 |
std::vector<String>::iterator iter = drivers.begin(); |
98 |
for (; iter != drivers.end(); iter++) { |
99 |
if (result != "") result += ","; |
100 |
result += *iter; |
101 |
} |
102 |
return result; |
103 |
} |
104 |
|
105 |
std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) { |
106 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
107 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
108 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
109 |
if (pParamFactory) { |
110 |
thisDeviceParams = pParamFactory->CreateAllParams(); |
111 |
} |
112 |
return thisDeviceParams; |
113 |
} |
114 |
|
115 |
DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) { |
116 |
std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName); |
117 |
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi input driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'."); |
118 |
return parameters[ParameterName]; |
119 |
} |
120 |
|
121 |
String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) { |
122 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
123 |
return InnerFactories[DriverName]->Description(); |
124 |
} |
125 |
|
126 |
String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) { |
127 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
128 |
return InnerFactories[DriverName]->Version(); |
129 |
} |
130 |
|
131 |
} // namespace LinuxSampler |