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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1934 - (hide annotations) (download) (as text)
Sun Jul 12 10:35:55 2009 UTC (14 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6651 byte(s)
* bugfix: don't allow to create or destroy audio devices and MIDI devices
  of host plugin implementations (e.g VST, AU, DSSI, LV2) on their own,
  as they only exist in the context of the plugin instance and would
  otherwise crash the application

1 schoenebeck 201 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 persson 1889 * Copyright (C) 2005 - 2009 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     #ifndef __LS_MIDI_INPUT_DEVICE_FACTORY_H__
25     #define __LS_MIDI_INPUT_DEVICE_FACTORY_H__
26    
27     #include <map>
28     #include <vector>
29    
30 schoenebeck 880 #include "../../common/Exception.h"
31 schoenebeck 201 #include "../DeviceParameterFactory.h"
32     #include "MidiInputDevice.h"
33 schoenebeck 551 #include "../../Sampler.h"
34 schoenebeck 201
35     #define REGISTER_MIDI_INPUT_DRIVER(DriverClass) static LinuxSampler::MidiInputDeviceFactory::InnerFactoryRegistrator<DriverClass> __auto_register_midi_input_driver__##DriverClass
36     #define REGISTER_MIDI_INPUT_DRIVER_PARAMETER(DriverClass, ParameterClass) static LinuxSampler::MidiInputDeviceFactory::ParameterRegistrator<DriverClass, DriverClass::ParameterClass> __auto_register_midi_input_driver_parameter__##DriverClass##ParameterClass
37    
38     namespace LinuxSampler {
39    
40 schoenebeck 1934 class Plugin;
41    
42 schoenebeck 201 class MidiInputDeviceFactory {
43     public:
44     class InnerFactory {
45     public:
46 schoenebeck 551 virtual MidiInputDevice* Create(std::map<String,DeviceCreationParameter*>& Parameters, Sampler* pSampler) = 0;
47 schoenebeck 201 virtual String Description() = 0;
48     virtual String Version() = 0;
49 schoenebeck 1934 virtual bool isAutonomousDriver() = 0;
50 schoenebeck 201 };
51    
52     template <class Driver_T>
53     class InnerFactoryTemplate : public InnerFactory {
54     public:
55 schoenebeck 551 virtual MidiInputDevice* Create(std::map<String,DeviceCreationParameter*>& Parameters, Sampler* pSampler) { return new Driver_T(Parameters, pSampler); }
56 schoenebeck 201 virtual String Description() { return Driver_T::Description(); }
57     virtual String Version() { return Driver_T::Version(); }
58 schoenebeck 1934 virtual bool isAutonomousDriver() { return Driver_T::isAutonomousDriver(); }
59 schoenebeck 201 };
60    
61     template <class Driver_T>
62     class InnerFactoryRegistrator {
63     public:
64     InnerFactoryRegistrator() {
65 schoenebeck 277 MidiInputDeviceFactory::InnerFactories[Driver_T::Name()] = new MidiInputDeviceFactory::InnerFactoryTemplate<Driver_T>;
66 schoenebeck 1934 MidiInputDeviceFactory::ParameterFactories[Driver_T::Name()] = new DeviceParameterFactory();
67 schoenebeck 201 }
68 persson 1248 ~InnerFactoryRegistrator() {
69     std::map<String, InnerFactory*>::iterator iter = MidiInputDeviceFactory::InnerFactories.find(Driver_T::Name());
70     delete iter->second;
71     MidiInputDeviceFactory::InnerFactories.erase(iter);
72    
73     std::map<String, DeviceParameterFactory*>::iterator iterpf = MidiInputDeviceFactory::ParameterFactories.find(Driver_T::Name());
74     delete iterpf->second;
75     MidiInputDeviceFactory::ParameterFactories.erase(iterpf);
76     }
77 schoenebeck 201 };
78    
79 schoenebeck 1934 template <class Driver_T, class Parameter_T>
80     class ParameterRegistrator {
81     public:
82     ParameterRegistrator() {
83 persson 1248 DeviceParameterFactory::Register<Parameter_T>(MidiInputDeviceFactory::ParameterFactories[Driver_T::Name()]);
84 schoenebeck 1934 }
85     };
86 schoenebeck 201
87 schoenebeck 880 static MidiInputDevice* Create(String DriverName, std::map<String,String> Parameters, Sampler* pSampler) throw (Exception);
88 schoenebeck 1934 static void Destroy(MidiInputDevice* pDevice) throw (Exception);
89 schoenebeck 201 static std::vector<String> AvailableDrivers();
90     static String AvailableDriversAsString();
91 schoenebeck 880 static std::map<String,DeviceCreationParameter*> GetAvailableDriverParameters(String DriverName) throw (Exception);
92     static DeviceCreationParameter* GetDriverParameter(String DriverName, String ParameterName) throw (Exception);
93     static String GetDriverDescription(String DriverName) throw (Exception);
94     static String GetDriverVersion(String DriverName) throw (Exception);
95 schoenebeck 1934 static std::map<uint, MidiInputDevice*> Devices();
96 schoenebeck 201
97 schoenebeck 1934 protected:
98     static MidiInputDevice* CreatePrivate(String DriverName, std::map<String,String> Parameters, Sampler* pSampler) throw (Exception);
99     static void DestroyPrivate(MidiInputDevice* pDevice) throw (Exception);
100     friend class Plugin; // host plugin base class (e.g. for VST, AU, DSSI, LV2)
101    
102     public: /* FIXME: fields below should be protected, causes errors on gcc 2.95 though */
103 schoenebeck 201 static std::map<String, InnerFactory*> InnerFactories;
104 schoenebeck 1934 static std::map<String, DeviceParameterFactory*> ParameterFactories;
105    
106     private:
107     typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
108     static MidiInputDeviceMap mMidiInputDevices; ///< contains all created MIDI input devices
109 schoenebeck 201 };
110    
111     } // namespace LinuxSampler
112    
113     #endif // __LS_AUDIO_OUTPUT_DEVICE_FACTORY_H__

  ViewVC Help
Powered by ViewVC