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