linuxsampler 1.0.0
|
00001 /*************************************************************************** 00002 * * 00003 * LinuxSampler - modular, streaming capable sampler * 00004 * * 00005 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * 00006 * Copyright (C) 2005 - 2009 Christian Schoenebeck * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00021 * MA 02111-1307 USA * 00022 ***************************************************************************/ 00023 00024 #ifndef __LS_MIDIINPUTDEVICE_H__ 00025 #define __LS_MIDIINPUTDEVICE_H__ 00026 00027 #include <stdexcept> 00028 #include <set> 00029 #include <map> 00030 #include <vector> 00031 00032 #include "../../common/global.h" 00033 #include "../../common/Exception.h" 00034 #include "../DeviceParameter.h" 00035 #include "MidiInputPort.h" 00036 #include "../../engines/Engine.h" 00037 #include "../../EventListeners.h" 00038 00039 namespace LinuxSampler { 00040 00041 // just symbol prototyping 00042 class MidiInputPort; 00043 class Engine; 00044 class MidiInputDeviceFactory; 00045 00052 class MidiInputException : public Exception { 00053 public: 00054 MidiInputException(const std::string& msg) : Exception(msg) {} 00055 }; 00056 00066 class MidiInputDevice : public Device { 00067 public: 00068 00070 // type definitions 00071 00076 class ParameterActive : public DeviceCreationParameterBool { 00077 public: 00078 ParameterActive(); 00079 ParameterActive(String active); 00080 virtual String Description(); 00081 virtual bool Fix(); 00082 virtual bool Mandatory(); 00083 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); 00084 virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters); 00085 virtual void OnSetValue(bool b) throw (Exception); 00086 static String Name(); 00087 }; 00088 00094 class ParameterPorts : public DeviceCreationParameterInt { 00095 public: 00096 ParameterPorts(); 00097 ParameterPorts(String val); 00098 virtual String Description(); 00099 virtual bool Fix(); 00100 virtual bool Mandatory(); 00101 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); 00102 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); 00103 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); 00104 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); 00105 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); 00106 virtual void OnSetValue(int i) throw (Exception); 00107 static String Name(); 00108 }; 00109 00110 00111 00113 // abstract methods 00114 // (these have to be implemented by the descendant) 00115 00122 virtual void Listen() = 0; 00123 00129 virtual void StopListen() = 0; 00130 00134 virtual String Driver() = 0; 00135 00141 virtual MidiInputPort* CreateMidiPort() = 0; 00142 00143 00144 00146 // normal methods 00147 // (usually not to be overriden by descendant) 00148 00154 MidiInputPort* GetPort(uint iPort) throw (MidiInputException); 00155 00160 uint PortCount(); 00161 00165 std::map<String,DeviceCreationParameter*> DeviceParameters(); 00166 00171 void AddMidiPortCountListener(MidiPortCountListener* l); 00172 00177 void RemoveMidiPortCountListener(MidiPortCountListener* l); 00178 00179 protected: 00180 std::map<String,DeviceCreationParameter*> Parameters; 00181 std::map<int,MidiInputPort*> Ports; 00182 void* pSampler; 00183 ListenerList<MidiPortCountListener*> portCountListeners; 00184 00194 MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters, void* pSampler); 00195 00199 virtual ~MidiInputDevice(); 00200 00206 void fireMidiPortCountChanged(int NewCount); 00207 00213 void fireMidiPortToBeRemoved(MidiInputPort* pPort); 00214 00220 void fireMidiPortAdded(MidiInputPort* pPort); 00221 00230 void AcquirePorts(uint Ports); 00231 00232 friend class ParameterActive; 00233 friend class ParameterPorts; 00234 friend class MidiInputDeviceFactory; // allow MidiInputDeviceFactory class to destroy midi devices 00235 friend class MidiInputPort; // allow MidiInputPort to access pSampler 00236 }; 00237 } 00238 00239 #endif // __LS_MIDIINPUTDEVICE_H__