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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 890 - (show annotations) (download) (as text)
Sat Jul 1 13:43:04 2006 UTC (17 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8493 byte(s)
just some refactoring work, moved the following files:

- src/engines/common/Engine.h -> src/engines/Engine.h,

- src/engines/common/EngineChannel.h ->
  src/engines/EngineChannel.h,

- src/engines/common/EngineChannel.cpp ->
  src/engines/EngineChannel.cpp

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005, 2006 Christian Schoenebeck *
7 * *
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 #include "../../common/Exception.h"
34 #include "../DeviceParameter.h"
35 #include "MidiInputPort.h"
36 #include "../../engines/Engine.h"
37
38 namespace LinuxSampler {
39
40 // just symbol prototyping
41 class MidiInputPort;
42 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 Exception {
51 public:
52 MidiInputException(const std::string& msg) : Exception(msg) {}
53 };
54
55 /** Abstract base class for MIDI input drivers in LinuxSampler
56 *
57 * This class will be derived by specialized classes which implement the
58 * connection to a specific MIDI input system (e.g. Alsa Sequencer,
59 * CoreMIDI). The MidiInputDevice desendant should just call the
60 * appropriate (protected) Dispatch* method here when an MIDI event
61 * occured. The dispatch* methods here will automatically forward the
62 * MIDI event to the appropriate, connected sampler engines.
63 */
64 class MidiInputDevice : public Device {
65 public:
66
67 /////////////////////////////////////////////////////////////////
68 // type definitions
69
70 /** Device Parameter 'ACTIVE'
71 *
72 * Used to activate / deactivate the MIDI input device.
73 */
74 class ParameterActive : public DeviceCreationParameterBool {
75 public:
76 ParameterActive();
77 ParameterActive(String active);
78 virtual String Description();
79 virtual bool Fix();
80 virtual bool Mandatory();
81 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
82 virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters);
83 virtual void OnSetValue(bool b) throw (Exception);
84 static String Name();
85 };
86
87 /** Device Parameter 'PORTS'
88 *
89 * 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 (Exception);
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 /**
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
141
142
143 /////////////////////////////////////////////////////////////////
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
182 * This can either do nothing, create more ports
183 * or destroy ports depenging on the parameter
184 * 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.
187 */
188 void AcquirePorts(uint Ports);
189
190 friend class ParameterActive;
191 friend class ParameterPorts;
192 friend class Sampler; // allow Sampler class to destroy midi devices
193 friend class MidiInputPort; // allow MidiInputPort to access pSampler
194 };
195 }
196
197 #endif // __LS_MIDIINPUTDEVICE_H__

  ViewVC Help
Powered by ViewVC