/[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 1424 - (hide annotations) (download)
Sun Oct 14 22:00:17 2007 UTC (16 years, 6 months ago) by schoenebeck
File size: 6459 byte(s)
* code cleanup:
- global.h now only covers global definitions that are needed for the C++
  API header files, all implementation internal global definitions are now
  in global_private.h
- atomic.h is not exposed to the C++ API anymore (replaced the references
  in SynchronizedConfig.h for this with local definitions)
- no need to include config.h anymore for using LS's API header files
- DB instruments classes are not exposed to the C++ API
- POSIX callback functions of Thread.h are hidden
- the (optional) gig Engine benchmark compiles again
- updated Doxyfile.in
- fixed warnings in API doc generation
* preparations for release 0.5.0

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

  ViewVC Help
Powered by ViewVC