/[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 212 by schoenebeck, Wed Jul 28 14:17:29 2004 UTC revision 551 by schoenebeck, Tue May 17 18:16:54 2005 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 31  Line 32 
32  #include "../../common/global.h"  #include "../../common/global.h"
33  #include "../../common/LinuxSamplerException.h"  #include "../../common/LinuxSamplerException.h"
34  #include "../DeviceParameter.h"  #include "../DeviceParameter.h"
35    #include "MidiInputPort.h"
36  #include "../../engines/common/Engine.h"  #include "../../engines/common/Engine.h"
37    
38  namespace LinuxSampler {  namespace LinuxSampler {
39    
40      // just symbol prototyping      // just symbol prototyping
41        class MidiInputPort;
42      class Engine;      class Engine;
43    
44        /**
45         * Midi input exception that should be thrown by the MidiInputDevice
46         * descendants in case initialization of the MIDI input system failed
47         * (which should be done in the constructor of the MidiInputDevice
48         * descendant).
49         */
50        class MidiInputException : public LinuxSamplerException {
51            public:
52                MidiInputException(const std::string& msg) : LinuxSamplerException(msg) {}
53        };
54    
55      /** Abstract base class for MIDI input drivers in LinuxSampler      /** Abstract base class for MIDI input drivers in LinuxSampler
56       *       *
57       * 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 67  namespace LinuxSampler {
67              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
68              // type definitions              // type definitions
69    
70                /** Device Parameter 'ACTIVE'
71                 *
72                 * Used to activate / deactivate the MIDI input device.
73                 */
74              class ParameterActive : public DeviceCreationParameterBool {              class ParameterActive : public DeviceCreationParameterBool {
75                      public:                  public:
76                              ParameterActive( void ) : DeviceCreationParameterBool()                     { InitWithDefault(); }                      ParameterActive();
77                              ParameterActive( String active ) : DeviceCreationParameterBool(active)      { }                      ParameterActive(String active);
78                              virtual String Description()                                                { return "Enable / disable device";  }                      virtual String Description();
79                              virtual bool   Fix()                                                        { return false;                      }                      virtual bool   Fix();
80                              virtual bool   Mandatory()                                                  { return false;                      }                      virtual bool   Mandatory();
81                              virtual std::map<String,DeviceCreationParameter*> DependsAsParameters()     { return std::map<String,DeviceCreationParameter*>(); }                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
82                              virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters)    { return true;                       }                      virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters);
83                              virtual void OnSetValue(bool b) throw (LinuxSamplerException)               { if (b) ((MidiInputDevice*)pDevice)->Listen(); else ((MidiInputDevice*)pDevice)->StopListen(); }                      virtual void OnSetValue(bool b) throw (LinuxSamplerException);
84                              static String Name( void ) { return "active"; }                      static String Name();
85              };              };
   
             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;  
86    
87          protected:              /** Device Parameter 'PORTS'
88              std::map<String,DeviceCreationParameter*> Parameters;  ///< All device parameters.               *
89              std::map<int,MidiInputPort*> Ports;               * Used to increase / decrease the number of MIDI ports of the
90                 * MIDI input device.
91                 */
92                class ParameterPorts : public DeviceCreationParameterInt {
93                    public:
94                        ParameterPorts();
95                        ParameterPorts(String val);
96                        virtual String Description();
97                        virtual bool   Fix();
98                        virtual bool   Mandatory();
99                        virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
100                        virtual optional<int>    DefaultAsInt(std::map<String,String> Parameters);
101                        virtual optional<int>    RangeMinAsInt(std::map<String,String> Parameters);
102                        virtual optional<int>    RangeMaxAsInt(std::map<String,String> Parameters);
103                        virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
104                        virtual void             OnSetValue(int i) throw (LinuxSamplerException);
105                        static String Name();
106                };
107    
108    
109    
110                /////////////////////////////////////////////////////////////////
111                // abstract methods
112                //     (these have to be implemented by the descendant)
113    
114                /**
115                 * Start listen to MIDI input events on the MIDI input port.
116                 * The MIDIInputPort descendant should forward all MIDI input
117                 * events by calling the appropriate (protected) Dispatch*
118                 * method of class MidiInputPort.
119                 */
120                virtual void Listen() = 0;
121    
122                /**
123                 * Stop to listen to MIDI input events on the MIDI input port.
124                 * After this method was called, the MidiInputPort descendant
125                 * should ignore all MIDI input events.
126                 */
127                virtual void StopListen() = 0;
128    
129                /**
130                 * Return device driver name
131                 */
132                virtual String Driver() = 0;
133    
134              MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters);              /**
135                 * Create new Midi port
136                 * This will be called by AcquirePorts
137                 * Each individual device must implement this.
138                 */
139                virtual MidiInputPort* CreateMidiPort() = 0;
140    
             virtual ~MidiInputDevice();  
141    
142    
143              friend class Sampler; // allow Sampler class to destroy midi devices              /////////////////////////////////////////////////////////////////
144                // normal methods
145                //     (usually not to be overriden by descendant)
146    
147                /**
148                 * Return midi port \a iPort.
149                 *
150                 * @throws MidiInputException  if index out of bounds
151                 */
152                MidiInputPort* GetPort(uint iPort) throw (MidiInputException);
153    
154                /**
155                 * Return all device parameter settings.
156                 */
157                std::map<String,DeviceCreationParameter*> DeviceParameters();
158    
159            protected:
160                std::map<String,DeviceCreationParameter*> Parameters;  ///< All device parameters.
161                std::map<int,MidiInputPort*> Ports;                    ///< All MIDI ports.
162                void* pSampler;                                        ///< Sampler instance. FIXME: should actually be of type Sampler*
163    
164                /**
165                 * Constructor
166                 *
167                 * FIXME: the pointer argument \a pSapmler should actually be of type Sampler*.
168                 * Unfortunately the bidirectional relationship between this
169                 * header and Sampler.h would clash on header file inclusion,
170                 * so that's why I had to make it of type void* here. This is
171                 * an annoying constraint of C++.
172                 */
173                MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters, void* pSampler);
174    
175                /**
176                 * Destructor
177                 */
178                virtual ~MidiInputDevice();
179    
180              /**              /**
181               * Set number of MIDI ports required by the engine               * Set number of MIDI ports required by the engine
182               * This can either do nothing, create more ports               * This can either do nothing, create more ports
183               * or destroy ports depenging on the parameter               * or destroy ports depenging on the parameter
184               * and how many ports already exist on this driver.               * and how many ports already exist on this driver.
185               *               *
186               * @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.
187               */               */
188              void AcquirePorts(uint Ports);              void AcquirePorts(uint Ports);
     };  
189    
190      /**              friend class ParameterActive;
191       * Midi input exception that should be thrown by the MidiInputDevice              friend class ParameterPorts;
192       * descendants in case initialization of the MIDI input system failed              friend class Sampler; // allow Sampler class to destroy midi devices
193       * (which should be done in the constructor of the MidiInputDevice              friend class MidiInputPort; // allow MidiInputPort to access pSampler
      * descendant).  
      */  
     class MidiInputException : public LinuxSamplerException {  
         public:  
             MidiInputException(const std::string& msg) : LinuxSamplerException(msg) {}  
194      };      };
195  }  }
196    

Legend:
Removed from v.212  
changed lines
  Added in v.551

  ViewVC Help
Powered by ViewVC