3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* 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 * |
* it under the terms of the GNU General Public License as published by * |
23 |
|
|
24 |
#include "MidiInputDeviceFactory.h" |
#include "MidiInputDeviceFactory.h" |
25 |
|
|
26 |
|
#include "../../common/global_private.h" |
27 |
|
|
28 |
#if HAVE_ALSA |
#if HAVE_ALSA |
29 |
# include "MidiInputDeviceAlsa.h" |
# include "MidiInputDeviceAlsa.h" |
30 |
#endif // HAVE_ALSA |
#endif // HAVE_ALSA |
31 |
|
|
32 |
#if HAVE_CORE_MIDI |
#if HAVE_COREMIDI |
33 |
# include "MidiInputDeviceCoreMidi.h" |
# include "MidiInputDeviceCoreMidi.h" |
34 |
#endif // HAVE_CORE_MIDI |
#endif // HAVE_CORE_MIDI |
35 |
|
|
37 |
# include "MidiInputDeviceMidiShare.h" |
# include "MidiInputDeviceMidiShare.h" |
38 |
#endif // HAVE_MIDISHARE |
#endif // HAVE_MIDISHARE |
39 |
|
|
40 |
|
#if HAVE_MME_MIDI |
41 |
|
# include "MidiInputDeviceMme.h" |
42 |
|
#endif // HAVE_MME_MIDI |
43 |
namespace LinuxSampler { |
namespace LinuxSampler { |
44 |
|
|
45 |
std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories; |
std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories; |
52 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts); |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts); |
53 |
#endif // HAVE_ALSA |
#endif // HAVE_ALSA |
54 |
|
|
55 |
#if HAVE_CORE_MIDI |
#if HAVE_COREMIDI |
56 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceCoreMidi); |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceCoreMidi); |
57 |
/* Common parameters */ |
/* Common parameters */ |
58 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterActive); |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterActive); |
59 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterPorts); |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterPorts); |
60 |
#endif // HAVE_CORE_MIDI |
#endif // HAVE_COREMIDI |
61 |
|
|
62 |
#if HAVE_MIDISHARE |
#if HAVE_MIDISHARE |
63 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMidiShare); |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMidiShare); |
66 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterPorts); |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterPorts); |
67 |
#endif // HAVE_MIDISHARE |
#endif // HAVE_MIDISHARE |
68 |
|
|
69 |
MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
#if HAVE_MME_MIDI |
70 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMme); |
71 |
|
/* Common parameters */ |
72 |
|
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMme, ParameterActive); |
73 |
|
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMme, ParameterPorts); |
74 |
|
#endif // HAVE_MME_MIDI |
75 |
|
|
76 |
|
MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters, Sampler* pSampler) throw (Exception) { |
77 |
|
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
78 |
//Let's see if we need to create parameters |
//Let's see if we need to create parameters |
79 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
80 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
82 |
thisDeviceParams = pParamFactory->CreateAllParams(Parameters); |
thisDeviceParams = pParamFactory->CreateAllParams(Parameters); |
83 |
} else { |
} else { |
84 |
//No parameters are registered by the driver. Throw if any parameters were specified. |
//No parameters are registered by the driver. Throw if any parameters were specified. |
85 |
if (Parameters.size() != 0) throw LinuxSamplerException("Driver '" + DriverName + "' does not have any parameters."); |
if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters."); |
86 |
} |
} |
87 |
//Now create the device using those parameters |
//Now create the device using those parameters |
88 |
MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams); |
MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams, pSampler); |
89 |
//Now attach all parameters to the newely created device. |
//Now attach all parameters to the newely created device. |
90 |
for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) { |
for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) { |
91 |
iter->second->Attach(pDevice); |
iter->second->Attach(pDevice); |
114 |
return result; |
return result; |
115 |
} |
} |
116 |
|
|
117 |
std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) { |
std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) { |
118 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
119 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
120 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
121 |
if (pParamFactory) { |
if (pParamFactory) { |
124 |
return thisDeviceParams; |
return thisDeviceParams; |
125 |
} |
} |
126 |
|
|
127 |
DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) { |
DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) { |
128 |
std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName); |
std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName); |
129 |
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi input driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'."); |
if (!parameters.count(ParameterName)) throw Exception("Midi input driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'."); |
130 |
return parameters[ParameterName]; |
return parameters[ParameterName]; |
131 |
} |
} |
132 |
|
|
133 |
String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) { |
String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) { |
134 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
135 |
return InnerFactories[DriverName]->Description(); |
return InnerFactories[DriverName]->Description(); |
136 |
} |
} |
137 |
|
|
138 |
String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) { |
String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) { |
139 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
140 |
return InnerFactories[DriverName]->Version(); |
return InnerFactories[DriverName]->Version(); |
141 |
} |
} |
142 |
|
|