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

Annotation of /linuxsampler/trunk/src/mididriver/MidiInputDeviceFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 174 - (hide annotations) (download)
Tue Jul 6 03:27:38 2004 UTC (19 years, 9 months ago) by senkov
File size: 5338 byte(s)
* Reworked the infrastructure to allow for parameter
registration and creation
* Changed alsa audio output and midi drivers
to work with new infrastructure

1 senkov 153 /***************************************************************************
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     namespace LinuxSampler {
26    
27     std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories;
28 senkov 174 std::map<String, DeviceParameterFactory*> MidiInputDeviceFactory::ParameterFactories;
29 senkov 153
30 senkov 174 MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) {
31 senkov 169 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'.");
32 senkov 174 //Let's see if we need to create parameters
33     std::map<String,DeviceCreationParameter*> thisDeviceParams;
34     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
35     if (pParamFactory) {
36     thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
37     } else {
38     //No parameters are registered by the driver. Throw if any parameters were specified.
39     if (Parameters.size() != 0) throw LinuxSamplerException("Driver '" + DriverName + "' does not have any parameters.");
40     }
41     //Now create the device using those parameters
42     MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
43     //Now attach all parameters to the newely created device.
44     for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
45     iter->second->Attach(pDevice);
46     }
47     return pDevice;
48 senkov 153 }
49    
50     std::vector<String> MidiInputDeviceFactory::AvailableDrivers() {
51     std::vector<String> result;
52     std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
53     while (iter != InnerFactories.end()) {
54     result.push_back(iter->first);
55     iter++;
56     }
57     return result;
58     }
59    
60     String MidiInputDeviceFactory::AvailableDriversAsString() {
61     std::vector<String> drivers = AvailableDrivers();
62     String result;
63     std::vector<String>::iterator iter = drivers.begin();
64     for (; iter != drivers.end(); iter++) {
65     if (result != "") result += ",";
66     result += *iter;
67     }
68     return result;
69     }
70    
71     std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) {
72 senkov 169 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'.");
73 senkov 174 std::map<String,DeviceCreationParameter*> thisDeviceParams;
74     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
75     if (pParamFactory) {
76     thisDeviceParams = pParamFactory->CreateAllParams();
77     }
78     return thisDeviceParams;
79 senkov 153 }
80    
81     DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) {
82     std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
83 senkov 169 if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi input driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
84 senkov 153 return parameters[ParameterName];
85     }
86    
87     String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) {
88 senkov 169 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'.");
89 senkov 153 return InnerFactories[DriverName]->Description();
90     }
91    
92     String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) {
93 senkov 169 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'.");
94 senkov 153 return InnerFactories[DriverName]->Version();
95     }
96    
97     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC