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

Diff of /linuxsampler/trunk/src/drivers/midi/MidiInputDevice.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 220 by schoenebeck, Wed Jul 28 14:17:29 2004 UTC revision 221 by schoenebeck, Fri Aug 20 17:25:19 2004 UTC
# Line 31  Line 31 
31  #include "../../common/global.h"  #include "../../common/global.h"
32  #include "../../common/LinuxSamplerException.h"  #include "../../common/LinuxSamplerException.h"
33  #include "../DeviceParameter.h"  #include "../DeviceParameter.h"
34    #include "MidiInputPort.h"
35  #include "../../engines/common/Engine.h"  #include "../../engines/common/Engine.h"
36    
37  namespace LinuxSampler {  namespace LinuxSampler {
38    
39      // just symbol prototyping      // just symbol prototyping
40        class MidiInputPort;
41      class Engine;      class Engine;
42    
43        /**
44         * Midi input exception that should be thrown by the MidiInputDevice
45         * descendants in case initialization of the MIDI input system failed
46         * (which should be done in the constructor of the MidiInputDevice
47         * descendant).
48         */
49        class MidiInputException : public LinuxSamplerException {
50            public:
51                MidiInputException(const std::string& msg) : LinuxSamplerException(msg) {}
52        };
53    
54      /** Abstract base class for MIDI input drivers in LinuxSampler      /** Abstract base class for MIDI input drivers in LinuxSampler
55       *       *
56       * This class will be derived by specialized classes which implement the       * This class will be derived by specialized classes which implement the
# Line 53  namespace LinuxSampler { Line 66  namespace LinuxSampler {
66              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
67              // type definitions              // type definitions
68    
69                /** Device Parameter 'ACTIVE'
70                 *
71                 * Used to activate / deactivate the MIDI input device.
72                 */
73              class ParameterActive : public DeviceCreationParameterBool {              class ParameterActive : public DeviceCreationParameterBool {
74                      public:                  public:
75                              ParameterActive( void ) : DeviceCreationParameterBool()                     { InitWithDefault(); }                      ParameterActive();
76                              ParameterActive( String active ) : DeviceCreationParameterBool(active)      { }                      ParameterActive(String active);
77                              virtual String Description()                                                { return "Enable / disable device";  }                      virtual String Description();
78                              virtual bool   Fix()                                                        { return false;                      }                      virtual bool   Fix();
79                              virtual bool   Mandatory()                                                  { return false;                      }                      virtual bool   Mandatory();
80                              virtual std::map<String,DeviceCreationParameter*> DependsAsParameters()     { return std::map<String,DeviceCreationParameter*>(); }                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
81                              virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters)    { return true;                       }                      virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters);
82                              virtual void OnSetValue(bool b) throw (LinuxSamplerException)               { if (b) ((MidiInputDevice*)pDevice)->Listen(); else ((MidiInputDevice*)pDevice)->StopListen(); }                      virtual void OnSetValue(bool b) throw (LinuxSamplerException);
83                              static String Name( void ) { return "active"; }                      static String Name();
84              };              };
   
             class ParameterPorts : public DeviceCreationParameterInt {  
                     public:  
                             ParameterPorts( void ) : DeviceCreationParameterInt()                           { InitWithDefault(); }  
                             ParameterPorts( String val ) : DeviceCreationParameterInt(val)                  { }  
                             virtual String Description()                                                    { return "Number of ports";   }  
                             virtual bool   Fix()                                                            { return false;   }  
                             virtual bool   Mandatory()                                                      { return false;   }  
                             virtual std::map<String,DeviceCreationParameter*> DependsAsParameters()         { return std::map<String,DeviceCreationParameter*>(); }  
                             virtual optional<int>    DefaultAsInt(std::map<String,String> Parameters)       { return 0; }  
                             virtual optional<int>    RangeMinAsInt(std::map<String,String> Parameters)      { return optional<int>::nothing;   }  
                             virtual optional<int>    RangeMaxAsInt(std::map<String,String> Parameters)      { return optional<int>::nothing;   }  
                             virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>();   }  
                             virtual void             OnSetValue(int i) throw (LinuxSamplerException)        { ((MidiInputDevice*)pDevice)->AcquirePorts(i); }  
                             static String Name( void ) { return "ports"; }  
             };  
   
             class MidiInputPort {  
   
                     public:  
                             /**  
                              * MIDI channels  
                              */  
                             enum midi_chan_t {  
                                     midi_chan_all = 0,  
                                     midi_chan_1   = 1,  
                                     midi_chan_2   = 2,  
                                     midi_chan_3   = 3,  
                                     midi_chan_4   = 4,  
                                     midi_chan_5   = 5,  
                                     midi_chan_6   = 6,  
                                     midi_chan_7   = 7,  
                                     midi_chan_8   = 8,  
                                     midi_chan_9   = 9,  
                                     midi_chan_10  = 10,  
                                     midi_chan_11  = 11,  
                                     midi_chan_12  = 12,  
                                     midi_chan_13  = 13,  
                                     midi_chan_14  = 14,  
                                     midi_chan_15  = 15,  
                                     midi_chan_16  = 16  
                             };  
   
                             class ParameterName : public DeviceCreationParameterString {  
                                     public:  
                                             ParameterName(MidiInputPort* pPort) { this->pPort = pPort; InitWithDefault();}  
                                             ParameterName(MidiInputPort* pPort, String val) : DeviceCreationParameterString(val) { this->pPort = pPort; }  
                                             virtual String Description()        { return "Name for this port"; }  
                                             virtual bool   Fix()                { return false; }  
                                             virtual bool   Mandatory()          { return false; }  
                                             virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); }  
                                             virtual optional<String>    DefaultAsString(std::map<String,String> Parameters) { return ""; }  
                                             virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) { return std::vector<String>(); }  
                                             virtual void OnSetValue(String s) throw (LinuxSamplerException) { return; /* FIXME: Nothing to do here */ }  
                                     protected:  
                                             MidiInputPort * pPort;  
                             };  
   
                             /////////////////////////////////////////////////////////////////  
                             // normal methods  
                             //     (usually not to be overriden by descendant)  
   
                             /**  
                              * Connect given sampler engine with this MIDI input device.  
                              * The engine can either be connected to one specific MIDI  
                              * channel or all MIDI channels. If an engine gets connected  
                              * twice to this MIDI input device, then the engine's old  
                              * connection will be detached (no matter on which MIDI channel).  
                              *  
                              * @param pEngine     - sampler engine  
                              * @param MidiChannel - MIDI channel to connect to  
                              * @throws MidiInputException  if MidiChannel argument invalid  
                              */  
                             void Connect(Engine* pEngine, midi_chan_t MidiChannel);  
   
                             /**  
                              * Disconnect given sampler engine from this MIDI input device.  
                              *  
                              * @param pEngine - sampler engine  
                              */  
                             void Disconnect(Engine* pEngine);  
   
                             MidiInputDevice* GetDevice();  
                             uint GetPortNumber();  
                             std::map<String,DeviceCreationParameter*> DeviceParameters();  
   
                             /////////////////////////////////////////////////////////////////  
                             // dispatch methods  
                             //     (should be called by the MidiInputDevice descendant on events)  
   
                             /**  
                              * Should be called by the implementing MIDI input device  
                              * whenever a note on event arrived, this will cause the note on  
                              * event to be forwarded to all connected engines on the  
                              * corresponding MIDI channel.  
                              *  
                              * @param Key         - MIDI key number of the triggered key  
                              * @param Velocity    - MIDI velocity of the triggered key  
                              * @param MidiChannel - MIDI channel on which event occured on  
                              */  
                             void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel);  
   
                             /**  
                              * Should be called by the implementing MIDI input device  
                              * whenever a note off event arrived, this will cause the note  
                              * off event to be forwarded to all connected engines on the  
                              * corresponding MIDI channel.  
                              *  
                              * @param Key         - MIDI key number of the released key  
                              * @param Velocity    - MIDI velocity of the released key  
                              * @param MidiChannel - MIDI channel on which event occured on  
                              */  
                             void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel);  
   
                             /**  
                              * Should be called by the implementing MIDI input device  
                              * whenever a pitchbend event arrived, this will cause the  
                              * pitchbend event to be forwarded to all connected engines.  
                              *  
                              * @param Pitch       - MIDI pitch value  
                              * @param MidiChannel - MIDI channel on which event occured on  
                              */  
                             void DispatchPitchbend(int Pitch, uint MidiChannel);  
   
                             /**  
                              * Should be called by the implementing MIDI input device  
                              * whenever a control change event arrived, this will cause the  
                              * control change event to be forwarded to all engines on the  
                              * corresponding MIDI channel.  
                              *  
                              * @param Controller  - MIDI controller number  
                              * @param Value       - MIDI control change value  
                              * @param MidiChannel - MIDI channel on which event occured on  
                              */  
                             void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel);  
   
                             MidiInputPort(MidiInputDevice* pDevice, int portNumber);  
   
                     protected:  
                             MidiInputDevice* pDevice;  
                             int portNumber;  
                             std::map<String,DeviceCreationParameter*> Parameters;  ///< All port parameters.  
                             std::set<Engine*> MidiChannelMap[17]; ///< Contains the list of connected engines for each MIDI channel, where index 0 points to the list of engines which are connected to all MIDI channels. Usually it's not necessary for the descendant to use this map, instead it should just use the Dispatch* methods.  
                             virtual ~MidiInputPort();  
   
                             friend class MidiInputDevice;  
             };  
   
             /**  
              * Return midi port  
              */  
             MidiInputPort* GetPort(int i) { return Ports[i]; }  
   
             /**  
              * Create new Midi port  
              * This will be called by AcquirePorts  
              * Each individual device must implement this.  
              */  
             virtual MidiInputPort* CreateMidiPort( void ) = 0;  
   
             std::map<String,DeviceCreationParameter*> DeviceParameters();  
   
             /////////////////////////////////////////////////////////////////  
             // abstract methods  
             //     (these have to be implemented by the descendant)  
   
             /**  
              * Start listen to MIDI input events on the MIDI input port.  
              * The MIDIInputPort descendant should forward all MIDI input  
              * events by calling the appropriate (protected) Dispatch*  
              * method of class MidiInputPort.  
              */  
             virtual void Listen() = 0;  
   
             /**  
              * Stop to listen to MIDI input events on the MIDI input port.  
              * After this method was called, the MidiInputPort descendant  
              * should ignore all MIDI input events.  
              */  
             virtual void StopListen() = 0;  
   
             /**  
              * Return device driver name  
              */  
             virtual String Driver() = 0;  
85    
86          protected:              /** Device Parameter 'PORTS'
87              std::map<String,DeviceCreationParameter*> Parameters;  ///< All device parameters.               *
88              std::map<int,MidiInputPort*> Ports;               * Used to increase / decrease the number of MIDI ports of the
89                 * MIDI input device.
90                 */
91                class ParameterPorts : public DeviceCreationParameterInt {
92                    public:
93                        ParameterPorts();
94                        ParameterPorts(String val);
95                        virtual String Description();
96                        virtual bool   Fix();
97                        virtual bool   Mandatory();
98                        virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
99                        virtual optional<int>    DefaultAsInt(std::map<String,String> Parameters);
100                        virtual optional<int>    RangeMinAsInt(std::map<String,String> Parameters);
101                        virtual optional<int>    RangeMaxAsInt(std::map<String,String> Parameters);
102                        virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
103                        virtual void             OnSetValue(int i) throw (LinuxSamplerException);
104                        static String Name();
105                };
106    
             MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters);  
107    
             virtual ~MidiInputDevice();  
108    
109                /////////////////////////////////////////////////////////////////
110                // abstract methods
111                //     (these have to be implemented by the descendant)
112    
113                /**
114                 * Start listen to MIDI input events on the MIDI input port.
115                 * The MIDIInputPort descendant should forward all MIDI input
116                 * events by calling the appropriate (protected) Dispatch*
117                 * method of class MidiInputPort.
118                 */
119                virtual void Listen() = 0;
120    
121              friend class Sampler; // allow Sampler class to destroy midi devices              /**
122                 * Stop to listen to MIDI input events on the MIDI input port.
123                 * After this method was called, the MidiInputPort descendant
124                 * should ignore all MIDI input events.
125                 */
126                virtual void StopListen() = 0;
127    
128                /**
129                 * Return device driver name
130                 */
131                virtual String Driver() = 0;
132    
133                /**
134                 * Create new Midi port
135                 * This will be called by AcquirePorts
136                 * Each individual device must implement this.
137                 */
138                virtual MidiInputPort* CreateMidiPort() = 0;
139    
140    
141    
142                /////////////////////////////////////////////////////////////////
143                // normal methods
144                //     (usually not to be overriden by descendant)
145    
146                /**
147                 * Return midi port \a iPort.
148                 *
149                 * @throws MidiInputException  if index out of bounds
150                 */
151                MidiInputPort* GetPort(uint iPort) throw (MidiInputException);
152    
153                /**
154                 * Return all device parameter settings.
155                 */
156                std::map<String,DeviceCreationParameter*> DeviceParameters();
157    
158            protected:
159                std::map<String,DeviceCreationParameter*> Parameters;  ///< All device parameters.
160                std::map<int,MidiInputPort*> Ports;                         ///< All MIDI ports.
161    
162                /**
163                 * Constructor
164                 */
165                MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters);
166    
167                /**
168                 * Destructor
169                 */
170                virtual ~MidiInputDevice();
171    
172              /**              /**
173               * Set number of MIDI ports required by the engine               * Set number of MIDI ports required by the engine
174               * This can either do nothing, create more ports               * This can either do nothing, create more ports
175               * or destroy ports depenging on the parameter               * or destroy ports depenging on the parameter
176               * and how many ports already exist on this driver.               * and how many ports already exist on this driver.
177               *               *
178               * @param Ports - number of ports to be left on this driver after this call.               * @param Ports - number of ports to be left on this driver after this call.
179               */               */
180              void AcquirePorts(uint Ports);              void AcquirePorts(uint Ports);
     };  
181    
182      /**              friend class Sampler; // allow Sampler class to destroy midi devices
      * Midi input exception that should be thrown by the MidiInputDevice  
      * descendants in case initialization of the MIDI input system failed  
      * (which should be done in the constructor of the MidiInputDevice  
      * descendant).  
      */  
     class MidiInputException : public LinuxSamplerException {  
         public:  
             MidiInputException(const std::string& msg) : LinuxSamplerException(msg) {}  
183      };      };
184  }  }
185    

Legend:
Removed from v.220  
changed lines
  Added in v.221

  ViewVC Help
Powered by ViewVC