/[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 361 - (hide annotations) (download)
Wed Feb 9 01:22:18 2005 UTC (19 years, 2 months ago) by schoenebeck
File size: 6446 byte(s)
* bunch of fixes for OSX (patch by Stephane Letz)

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 361 #if HAVE_CORE_MIDI
30     # include "MidiInputDeviceCoreMidi.h"
31     #endif // HAVE_CORE_MIDI
32    
33     #if HAVE_MIDISHARE
34     # include "MidiInputDeviceMidiShare.h"
35     #endif // HAVE_MIDISHARE
36    
37 schoenebeck 201 namespace LinuxSampler {
38    
39     std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories;
40     std::map<String, DeviceParameterFactory*> MidiInputDeviceFactory::ParameterFactories;
41    
42 schoenebeck 289 #if HAVE_ALSA
43     REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceAlsa);
44     /* Common parameters */
45     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterActive);
46     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts);
47     #endif // HAVE_ALSA
48 schoenebeck 288
49 schoenebeck 361 #if HAVE_CORE_MIDI
50     REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceCoreMidi);
51     /* Common parameters */
52     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterActive);
53     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterPorts);
54     #endif // HAVE_CORE_MIDI
55    
56     #if HAVE_MIDISHARE
57     REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMidiShare);
58     /* Common parameters */
59     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterActive);
60     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterPorts);
61     #endif // HAVE_MIDISHARE
62    
63 schoenebeck 201 MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) {
64     if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'.");
65     //Let's see if we need to create parameters
66     std::map<String,DeviceCreationParameter*> thisDeviceParams;
67     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
68     if (pParamFactory) {
69     thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
70     } else {
71     //No parameters are registered by the driver. Throw if any parameters were specified.
72     if (Parameters.size() != 0) throw LinuxSamplerException("Driver '" + DriverName + "' does not have any parameters.");
73     }
74     //Now create the device using those parameters
75     MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
76     //Now attach all parameters to the newely created device.
77     for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
78     iter->second->Attach(pDevice);
79     }
80     return pDevice;
81     }
82    
83     std::vector<String> MidiInputDeviceFactory::AvailableDrivers() {
84     std::vector<String> result;
85     std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
86     while (iter != InnerFactories.end()) {
87     result.push_back(iter->first);
88     iter++;
89     }
90     return result;
91     }
92    
93     String MidiInputDeviceFactory::AvailableDriversAsString() {
94     std::vector<String> drivers = AvailableDrivers();
95     String result;
96     std::vector<String>::iterator iter = drivers.begin();
97     for (; iter != drivers.end(); iter++) {
98     if (result != "") result += ",";
99     result += *iter;
100     }
101     return result;
102     }
103    
104     std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) {
105     if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'.");
106     std::map<String,DeviceCreationParameter*> thisDeviceParams;
107     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
108     if (pParamFactory) {
109     thisDeviceParams = pParamFactory->CreateAllParams();
110     }
111     return thisDeviceParams;
112     }
113    
114     DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) {
115     std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
116     if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi input driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
117     return parameters[ParameterName];
118     }
119    
120     String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) {
121     if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'.");
122     return InnerFactories[DriverName]->Description();
123     }
124    
125     String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) {
126     if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no midi input driver '" + DriverName + "'.");
127     return InnerFactories[DriverName]->Version();
128     }
129    
130     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC