/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInputDeviceFactory.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/midi/MidiInputDeviceFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1481 - (show annotations) (download)
Wed Nov 14 23:42:15 2007 UTC (16 years, 5 months ago) by senoner
File size: 6814 byte(s)
* win32 port work in progress:
* - implemented win32 support in the following classes:
* Thread, Condition, Mutex, Path, LscpServer
* - lscp.y use DONTCARE instead of VOID
*  (a win32 symbol defined)
* - completed win32 editor plugin loader

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * 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 *
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 namespace LinuxSampler {
44
45 std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories;
46 std::map<String, DeviceParameterFactory*> MidiInputDeviceFactory::ParameterFactories;
47
48 #if HAVE_ALSA
49 REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceAlsa);
50 /* Common parameters */
51 REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterActive);
52 REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts);
53 #endif // HAVE_ALSA
54
55 #if HAVE_COREMIDI
56 REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceCoreMidi);
57 /* Common parameters */
58 REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterActive);
59 REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterPorts);
60 #endif // HAVE_COREMIDI
61
62 #if HAVE_MIDISHARE
63 REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMidiShare);
64 /* Common parameters */
65 REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterActive);
66 REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterPorts);
67 #endif // HAVE_MIDISHARE
68
69 #if HAVE_MME_MIDI
70 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
79 std::map<String,DeviceCreationParameter*> thisDeviceParams;
80 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
81 if (pParamFactory) {
82 thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
83 } else {
84 //No parameters are registered by the driver. Throw if any parameters were specified.
85 if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters.");
86 }
87 //Now create the device using those parameters
88 MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams, pSampler);
89 //Now attach all parameters to the newely created device.
90 for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
91 iter->second->Attach(pDevice);
92 }
93 return pDevice;
94 }
95
96 std::vector<String> MidiInputDeviceFactory::AvailableDrivers() {
97 std::vector<String> result;
98 std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
99 while (iter != InnerFactories.end()) {
100 result.push_back(iter->first);
101 iter++;
102 }
103 return result;
104 }
105
106 String MidiInputDeviceFactory::AvailableDriversAsString() {
107 std::vector<String> drivers = AvailableDrivers();
108 String result;
109 std::vector<String>::iterator iter = drivers.begin();
110 for (; iter != drivers.end(); iter++) {
111 if (result != "") result += ",";
112 result += *iter;
113 }
114 return result;
115 }
116
117 std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) {
118 if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'.");
119 std::map<String,DeviceCreationParameter*> thisDeviceParams;
120 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
121 if (pParamFactory) {
122 thisDeviceParams = pParamFactory->CreateAllParams();
123 }
124 return thisDeviceParams;
125 }
126
127 DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
128 std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
129 if (!parameters.count(ParameterName)) throw Exception("Midi input driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
130 return parameters[ParameterName];
131 }
132
133 String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
134 if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'.");
135 return InnerFactories[DriverName]->Description();
136 }
137
138 String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
139 if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'.");
140 return InnerFactories[DriverName]->Version();
141 }
142
143 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC