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_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 |
namespace LinuxSampler { |
namespace LinuxSampler { |
41 |
|
|
42 |
std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories; |
std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories; |
49 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts); |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts); |
50 |
#endif // HAVE_ALSA |
#endif // HAVE_ALSA |
51 |
|
|
52 |
MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
#if HAVE_COREMIDI |
53 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'."); |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceCoreMidi); |
54 |
|
/* Common parameters */ |
55 |
|
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterActive); |
56 |
|
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterPorts); |
57 |
|
#endif // HAVE_COREMIDI |
58 |
|
|
59 |
|
#if HAVE_MIDISHARE |
60 |
|
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMidiShare); |
61 |
|
/* Common parameters */ |
62 |
|
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterActive); |
63 |
|
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterPorts); |
64 |
|
#endif // HAVE_MIDISHARE |
65 |
|
|
66 |
|
MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters, Sampler* pSampler) throw (Exception) { |
67 |
|
if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'."); |
68 |
//Let's see if we need to create parameters |
//Let's see if we need to create parameters |
69 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
70 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
72 |
thisDeviceParams = pParamFactory->CreateAllParams(Parameters); |
thisDeviceParams = pParamFactory->CreateAllParams(Parameters); |
73 |
} else { |
} else { |
74 |
//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. |
75 |
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."); |
76 |
} |
} |
77 |
//Now create the device using those parameters |
//Now create the device using those parameters |
78 |
MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams); |
MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams, pSampler); |
79 |
//Now attach all parameters to the newely created device. |
//Now attach all parameters to the newely created device. |
80 |
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++) { |
81 |
iter->second->Attach(pDevice); |
iter->second->Attach(pDevice); |
104 |
return result; |
return result; |
105 |
} |
} |
106 |
|
|
107 |
std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) { |
std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) { |
108 |
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 + "'."); |
109 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
110 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
111 |
if (pParamFactory) { |
if (pParamFactory) { |
114 |
return thisDeviceParams; |
return thisDeviceParams; |
115 |
} |
} |
116 |
|
|
117 |
DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) { |
DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) { |
118 |
std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName); |
std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName); |
119 |
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 + "'."); |
120 |
return parameters[ParameterName]; |
return parameters[ParameterName]; |
121 |
} |
} |
122 |
|
|
123 |
String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) { |
String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) { |
124 |
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 + "'."); |
125 |
return InnerFactories[DriverName]->Description(); |
return InnerFactories[DriverName]->Description(); |
126 |
} |
} |
127 |
|
|
128 |
String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) { |
String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) { |
129 |
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 + "'."); |
130 |
return InnerFactories[DriverName]->Version(); |
return InnerFactories[DriverName]->Version(); |
131 |
} |
} |
132 |
|
|