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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2434 - (hide annotations) (download) (as text)
Thu Mar 7 19:23:24 2013 UTC (11 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 10232 byte(s)
* Started to spread new C++ keyword "override" over the code base
  (keyword introduced with C++11 standard).

1 schoenebeck 201 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 2434 * Copyright (C) 2005 - 2013 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_MIDIINPUTDEVICE_H__
25     #define __LS_MIDIINPUTDEVICE_H__
26    
27     #include <stdexcept>
28     #include <set>
29     #include <map>
30     #include <vector>
31    
32     #include "../../common/global.h"
33 schoenebeck 880 #include "../../common/Exception.h"
34 schoenebeck 201 #include "../DeviceParameter.h"
35 schoenebeck 221 #include "MidiInputPort.h"
36 schoenebeck 890 #include "../../engines/Engine.h"
37 schoenebeck 1695 #include "../../EventListeners.h"
38 schoenebeck 201
39     namespace LinuxSampler {
40    
41     // just symbol prototyping
42 schoenebeck 221 class MidiInputPort;
43 schoenebeck 201 class Engine;
44 schoenebeck 1934 class MidiInputDeviceFactory;
45 schoenebeck 201
46 schoenebeck 221 /**
47     * Midi input exception that should be thrown by the MidiInputDevice
48     * descendants in case initialization of the MIDI input system failed
49     * (which should be done in the constructor of the MidiInputDevice
50     * descendant).
51     */
52 schoenebeck 880 class MidiInputException : public Exception {
53 schoenebeck 221 public:
54 schoenebeck 880 MidiInputException(const std::string& msg) : Exception(msg) {}
55 schoenebeck 221 };
56    
57 schoenebeck 201 /** Abstract base class for MIDI input drivers in LinuxSampler
58     *
59     * This class will be derived by specialized classes which implement the
60     * connection to a specific MIDI input system (e.g. Alsa Sequencer,
61     * CoreMIDI). The MidiInputDevice desendant should just call the
62     * appropriate (protected) Dispatch* method here when an MIDI event
63     * occured. The dispatch* methods here will automatically forward the
64     * MIDI event to the appropriate, connected sampler engines.
65     */
66 schoenebeck 207 class MidiInputDevice : public Device {
67 schoenebeck 201 public:
68    
69     /////////////////////////////////////////////////////////////////
70     // type definitions
71    
72 schoenebeck 221 /** Device Parameter 'ACTIVE'
73     *
74     * Used to activate / deactivate the MIDI input device.
75     */
76 schoenebeck 201 class ParameterActive : public DeviceCreationParameterBool {
77 schoenebeck 221 public:
78     ParameterActive();
79     ParameterActive(String active);
80 schoenebeck 2434 virtual String Description() OVERRIDE;
81     virtual bool Fix() OVERRIDE;
82     virtual bool Mandatory() OVERRIDE;
83     virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() OVERRIDE;
84     virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters) OVERRIDE;
85     virtual void OnSetValue(bool b) throw (Exception) OVERRIDE;
86 schoenebeck 221 static String Name();
87     };
88 schoenebeck 201
89 schoenebeck 221 /** Device Parameter 'PORTS'
90     *
91     * Used to increase / decrease the number of MIDI ports of the
92     * MIDI input device.
93     */
94     class ParameterPorts : public DeviceCreationParameterInt {
95     public:
96     ParameterPorts();
97     ParameterPorts(String val);
98 schoenebeck 2434 virtual String Description() OVERRIDE;
99     virtual bool Fix() OVERRIDE;
100     virtual bool Mandatory() OVERRIDE;
101     virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() OVERRIDE;
102     virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) OVERRIDE;
103     virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) OVERRIDE;
104     virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) OVERRIDE;
105     virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) OVERRIDE;
106     virtual void OnSetValue(int i) throw (Exception) OVERRIDE;
107 schoenebeck 221 static String Name();
108     };
109 schoenebeck 201
110    
111    
112 schoenebeck 221 /////////////////////////////////////////////////////////////////
113     // abstract methods
114     // (these have to be implemented by the descendant)
115 schoenebeck 201
116 schoenebeck 221 /**
117     * Start listen to MIDI input events on the MIDI input port.
118     * The MIDIInputPort descendant should forward all MIDI input
119     * events by calling the appropriate (protected) Dispatch*
120     * method of class MidiInputPort.
121     */
122     virtual void Listen() = 0;
123 schoenebeck 201
124 schoenebeck 221 /**
125     * Stop to listen to MIDI input events on the MIDI input port.
126     * After this method was called, the MidiInputPort descendant
127     * should ignore all MIDI input events.
128     */
129     virtual void StopListen() = 0;
130 schoenebeck 201
131 schoenebeck 221 /**
132     * Return device driver name
133     */
134     virtual String Driver() = 0;
135 schoenebeck 201
136 schoenebeck 221 /**
137     * Create new Midi port
138     * This will be called by AcquirePorts
139     * Each individual device must implement this.
140     */
141     virtual MidiInputPort* CreateMidiPort() = 0;
142 schoenebeck 201
143    
144    
145 schoenebeck 221 /////////////////////////////////////////////////////////////////
146     // normal methods
147     // (usually not to be overriden by descendant)
148 schoenebeck 201
149 schoenebeck 221 /**
150     * Return midi port \a iPort.
151     *
152     * @throws MidiInputException if index out of bounds
153     */
154     MidiInputPort* GetPort(uint iPort) throw (MidiInputException);
155 schoenebeck 201
156 schoenebeck 221 /**
157 schoenebeck 1695 * Returns amount of MIDI ports this MIDI input device currently
158     * provides.
159     */
160     uint PortCount();
161    
162     /**
163 schoenebeck 221 * Return all device parameter settings.
164     */
165     std::map<String,DeviceCreationParameter*> DeviceParameters();
166 schoenebeck 201
167 schoenebeck 1695 /**
168     * Registers the specified listener to be notified
169     * when the number of MIDI input ports is changed.
170     */
171     void AddMidiPortCountListener(MidiPortCountListener* l);
172    
173     /**
174     * Removes the specified listener, to stop being notified of
175     * further MIDI input port count chances.
176     */
177     void RemoveMidiPortCountListener(MidiPortCountListener* l);
178    
179 schoenebeck 201 protected:
180 schoenebeck 221 std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters.
181 schoenebeck 551 std::map<int,MidiInputPort*> Ports; ///< All MIDI ports.
182     void* pSampler; ///< Sampler instance. FIXME: should actually be of type Sampler*
183 schoenebeck 1695 ListenerList<MidiPortCountListener*> portCountListeners;
184 schoenebeck 201
185 schoenebeck 221 /**
186     * Constructor
187 schoenebeck 551 *
188     * FIXME: the pointer argument \a pSapmler should actually be of type Sampler*.
189     * Unfortunately the bidirectional relationship between this
190     * header and Sampler.h would clash on header file inclusion,
191     * so that's why I had to make it of type void* here. This is
192     * an annoying constraint of C++.
193 schoenebeck 221 */
194 schoenebeck 551 MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters, void* pSampler);
195 schoenebeck 201
196 schoenebeck 221 /**
197     * Destructor
198     */
199     virtual ~MidiInputDevice();
200 schoenebeck 201
201     /**
202 schoenebeck 1695 * Notifies listeners that the amount of MIDI inpurt ports have
203     * been changed.
204     * @param NewCount The new number of MIDI input ports.
205     */
206     void fireMidiPortCountChanged(int NewCount);
207    
208     /**
209     * Notifies listeners that the supplied MIDI input port is
210     * going to be removed soon.
211     * @param pPort The MIDI input port that is going to be removed.
212     */
213     void fireMidiPortToBeRemoved(MidiInputPort* pPort);
214    
215     /**
216     * Notifies listeners that the supplied MIDI input port has
217     * just been added.
218     * @param pPort The MIDI input port that has been added.
219     */
220     void fireMidiPortAdded(MidiInputPort* pPort);
221    
222     /**
223 schoenebeck 201 * Set number of MIDI ports required by the engine
224 schoenebeck 221 * This can either do nothing, create more ports
225     * or destroy ports depenging on the parameter
226     * and how many ports already exist on this driver.
227 schoenebeck 201 *
228     * @param Ports - number of ports to be left on this driver after this call.
229     */
230 schoenebeck 221 void AcquirePorts(uint Ports);
231 schoenebeck 201
232 schoenebeck 277 friend class ParameterActive;
233     friend class ParameterPorts;
234 schoenebeck 1934 friend class MidiInputDeviceFactory; // allow MidiInputDeviceFactory class to destroy midi devices
235 schoenebeck 551 friend class MidiInputPort; // allow MidiInputPort to access pSampler
236 schoenebeck 201 };
237     }
238    
239     #endif // __LS_MIDIINPUTDEVICE_H__

  ViewVC Help
Powered by ViewVC