/[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 1835 - (hide annotations) (download)
Mon Feb 16 17:56:50 2009 UTC (15 years, 2 months ago) by iliev
File size: 7447 byte(s)
* Adapted drivers/Plugin class to be used as a base class for the
  AudioUnit plugin and fixed orphaned pointers when deleting PluginGlobal
* Fixed possible iterator invalidations when resetting the sampler
* Fixed memory leaks when issuing the following LSCP commands:
  GET AUDIO_OUTPUT_DRIVER INFO
  GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO
  GET MIDI_INPUT_DRIVER INFO
  GET MIDI_INPUT_DRIVER_PARAMETER INFO
* Fixed possible compilation error when sqlite is not present

1 schoenebeck 201 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 persson 1651 * Copyright (C) 2005 - 2008 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 senoner 1481 #if HAVE_MME_MIDI
41     # include "MidiInputDeviceMme.h"
42     #endif // HAVE_MME_MIDI
43 persson 1651
44     #if HAVE_JACK_MIDI
45     # include "MidiInputDeviceJack.h"
46     #endif // HAVE_JACK_MIDI
47    
48 schoenebeck 201 namespace LinuxSampler {
49    
50     std::map<String, MidiInputDeviceFactory::InnerFactory*> MidiInputDeviceFactory::InnerFactories;
51     std::map<String, DeviceParameterFactory*> MidiInputDeviceFactory::ParameterFactories;
52    
53 schoenebeck 289 #if HAVE_ALSA
54     REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceAlsa);
55     /* Common parameters */
56     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterActive);
57     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts);
58     #endif // HAVE_ALSA
59 schoenebeck 288
60 wylder 817 #if HAVE_COREMIDI
61 schoenebeck 361 REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceCoreMidi);
62     /* Common parameters */
63     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterActive);
64     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceCoreMidi, ParameterPorts);
65 wylder 817 #endif // HAVE_COREMIDI
66 schoenebeck 361
67     #if HAVE_MIDISHARE
68     REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMidiShare);
69     /* Common parameters */
70     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterActive);
71     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMidiShare, ParameterPorts);
72     #endif // HAVE_MIDISHARE
73    
74 senoner 1481 #if HAVE_MME_MIDI
75     REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceMme);
76     /* Common parameters */
77     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMme, ParameterActive);
78     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceMme, ParameterPorts);
79     #endif // HAVE_MME_MIDI
80    
81 persson 1651 #if HAVE_JACK_MIDI
82     REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceJack);
83     /* Common parameters */
84     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceJack, ParameterActive);
85     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceJack, ParameterPorts);
86     /* Driver specific parameters */
87     REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceJack, ParameterName);
88     #endif // HAVE_JACK_MIDI
89    
90 schoenebeck 880 MidiInputDevice* MidiInputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters, Sampler* pSampler) throw (Exception) {
91     if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'.");
92 schoenebeck 201 //Let's see if we need to create parameters
93     std::map<String,DeviceCreationParameter*> thisDeviceParams;
94     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
95     if (pParamFactory) {
96     thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
97     } else {
98     //No parameters are registered by the driver. Throw if any parameters were specified.
99 schoenebeck 880 if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters.");
100 schoenebeck 201 }
101     //Now create the device using those parameters
102 schoenebeck 551 MidiInputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams, pSampler);
103 schoenebeck 201 //Now attach all parameters to the newely created device.
104     for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
105     iter->second->Attach(pDevice);
106     }
107     return pDevice;
108     }
109    
110     std::vector<String> MidiInputDeviceFactory::AvailableDrivers() {
111     std::vector<String> result;
112     std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
113     while (iter != InnerFactories.end()) {
114     result.push_back(iter->first);
115     iter++;
116     }
117     return result;
118     }
119    
120     String MidiInputDeviceFactory::AvailableDriversAsString() {
121     std::vector<String> drivers = AvailableDrivers();
122     String result;
123     std::vector<String>::iterator iter = drivers.begin();
124     for (; iter != drivers.end(); iter++) {
125     if (result != "") result += ",";
126     result += *iter;
127     }
128     return result;
129     }
130    
131 schoenebeck 880 std::map<String,DeviceCreationParameter*> MidiInputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) {
132     if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'.");
133 schoenebeck 201 std::map<String,DeviceCreationParameter*> thisDeviceParams;
134     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
135     if (pParamFactory) {
136     thisDeviceParams = pParamFactory->CreateAllParams();
137     }
138     return thisDeviceParams;
139     }
140    
141 schoenebeck 880 DeviceCreationParameter* MidiInputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
142 iliev 1835 if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'.");
143     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
144     if (pParamFactory) {
145     try { return pParamFactory->Create(ParameterName); }
146     catch(Exception e) { }
147     }
148     throw Exception("Midi input driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
149 schoenebeck 201 }
150    
151 schoenebeck 880 String MidiInputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
152     if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'.");
153 schoenebeck 201 return InnerFactories[DriverName]->Description();
154     }
155    
156 schoenebeck 880 String MidiInputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
157     if (!InnerFactories.count(DriverName)) throw Exception("There is no midi input driver '" + DriverName + "'.");
158 schoenebeck 201 return InnerFactories[DriverName]->Version();
159     }
160    
161     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC