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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 289 - (hide annotations) (download)
Tue Oct 19 14:41:38 2004 UTC (19 years, 6 months ago) by schoenebeck
File size: 5682 byte(s)
* LinuxSampler was badly broken with last commit, fixed that
* using now James Klicman's proposol to fix the reported linker problem
* Mutex.cpp: try to force UNIX98 compatibility (if not already supported)
* Makefile.cvs: generate (and clean) all necessary autotools files

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

  ViewVC Help
Powered by ViewVC