/[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 2500 - (hide annotations) (download) (as text)
Fri Jan 10 12:20:05 2014 UTC (10 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 10728 byte(s)
* Added support for multiple MIDI input ports per sampler channel (added
  various new C++ API methods for this new feature/design, old C++ API
  methods are now marked as deprecated but should still provide full
  behavior backward compatibility).
* LSCP Network interface: Added the following new LSCP commands for the new
  feature mentioned above: "ADD CHANNEL MIDI_INPUT",
  "REMOVE CHANNEL MIDI_INPUT" and "LIST CHANNEL MIDI_INPUTS". As with the
  C++ API changes, the old LSCP commands for MIDI input management are now
  marked as deprecated, but are still there and should provide full behavior
  backward compatibility.
* New LSCP specification document (LSCP v1.6).
* AbstractEngine::GSCheckSum(): don't allocate memory on the stack (was
  unsafe and caused compilation error with old clang 2.x).
* Bumped version (1.0.0.svn25).

1 schoenebeck 201 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 2500 * Copyright (C) 2005 - 2014 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 schoenebeck 2500 * Returns the unique ID number associated with this MIDIInputDevice
169     * instance. This ID number is unique among all MIDIInputDevice
170     * instances of the same Sampler instance and during the whole
171     * lifetime of the Sampler instance.
172     *
173     * @returns a value equal or larger than 0, a negative value only
174     * on severe internal problems
175     */
176     int MidiInputDeviceID();
177    
178     /**
179 schoenebeck 1695 * Registers the specified listener to be notified
180     * when the number of MIDI input ports is changed.
181     */
182     void AddMidiPortCountListener(MidiPortCountListener* l);
183    
184     /**
185     * Removes the specified listener, to stop being notified of
186     * further MIDI input port count chances.
187     */
188     void RemoveMidiPortCountListener(MidiPortCountListener* l);
189    
190 schoenebeck 201 protected:
191 schoenebeck 221 std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters.
192 schoenebeck 551 std::map<int,MidiInputPort*> Ports; ///< All MIDI ports.
193     void* pSampler; ///< Sampler instance. FIXME: should actually be of type Sampler*
194 schoenebeck 1695 ListenerList<MidiPortCountListener*> portCountListeners;
195 schoenebeck 201
196 schoenebeck 221 /**
197     * Constructor
198 schoenebeck 551 *
199     * FIXME: the pointer argument \a pSapmler should actually be of type Sampler*.
200     * Unfortunately the bidirectional relationship between this
201     * header and Sampler.h would clash on header file inclusion,
202     * so that's why I had to make it of type void* here. This is
203     * an annoying constraint of C++.
204 schoenebeck 221 */
205 schoenebeck 551 MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters, void* pSampler);
206 schoenebeck 201
207 schoenebeck 221 /**
208     * Destructor
209     */
210     virtual ~MidiInputDevice();
211 schoenebeck 201
212     /**
213 schoenebeck 1695 * Notifies listeners that the amount of MIDI inpurt ports have
214     * been changed.
215     * @param NewCount The new number of MIDI input ports.
216     */
217     void fireMidiPortCountChanged(int NewCount);
218    
219     /**
220     * Notifies listeners that the supplied MIDI input port is
221     * going to be removed soon.
222     * @param pPort The MIDI input port that is going to be removed.
223     */
224     void fireMidiPortToBeRemoved(MidiInputPort* pPort);
225    
226     /**
227     * Notifies listeners that the supplied MIDI input port has
228     * just been added.
229     * @param pPort The MIDI input port that has been added.
230     */
231     void fireMidiPortAdded(MidiInputPort* pPort);
232    
233     /**
234 schoenebeck 201 * Set number of MIDI ports required by the engine
235 schoenebeck 221 * This can either do nothing, create more ports
236     * or destroy ports depenging on the parameter
237     * and how many ports already exist on this driver.
238 schoenebeck 201 *
239     * @param Ports - number of ports to be left on this driver after this call.
240     */
241 schoenebeck 221 void AcquirePorts(uint Ports);
242 schoenebeck 201
243 schoenebeck 277 friend class ParameterActive;
244     friend class ParameterPorts;
245 schoenebeck 1934 friend class MidiInputDeviceFactory; // allow MidiInputDeviceFactory class to destroy midi devices
246 schoenebeck 551 friend class MidiInputPort; // allow MidiInputPort to access pSampler
247 schoenebeck 201 };
248     }
249    
250     #endif // __LS_MIDIINPUTDEVICE_H__

  ViewVC Help
Powered by ViewVC