1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
8 |
* it under the terms of the GNU General Public License as published by * |
9 |
* the Free Software Foundation; either version 2 of the License, or * |
10 |
* (at your option) any later version. * |
11 |
* * |
12 |
* This program is distributed in the hope that it will be useful, * |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
* GNU General Public License for more details. * |
16 |
* * |
17 |
* You should have received a copy of the GNU General Public License * |
18 |
* along with this program; if not, write to the Free Software * |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
* MA 02111-1307 USA * |
21 |
***************************************************************************/ |
22 |
|
23 |
#ifndef __LS_MIDIINPUTDEVICE_H__ |
24 |
#define __LS_MIDIINPUTDEVICE_H__ |
25 |
|
26 |
#include <stdexcept> |
27 |
#include <set> |
28 |
#include <map> |
29 |
#include <vector> |
30 |
|
31 |
#include "../../common/global.h" |
32 |
#include "../../common/LinuxSamplerException.h" |
33 |
#include "../DeviceParameter.h" |
34 |
#include "MidiInputPort.h" |
35 |
#include "../../engines/common/Engine.h" |
36 |
|
37 |
namespace LinuxSampler { |
38 |
|
39 |
// just symbol prototyping |
40 |
class MidiInputPort; |
41 |
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 |
55 |
* |
56 |
* This class will be derived by specialized classes which implement the |
57 |
* connection to a specific MIDI input system (e.g. Alsa Sequencer, |
58 |
* CoreMIDI). The MidiInputDevice desendant should just call the |
59 |
* appropriate (protected) Dispatch* method here when an MIDI event |
60 |
* occured. The dispatch* methods here will automatically forward the |
61 |
* MIDI event to the appropriate, connected sampler engines. |
62 |
*/ |
63 |
class MidiInputDevice : public Device { |
64 |
public: |
65 |
|
66 |
///////////////////////////////////////////////////////////////// |
67 |
// type definitions |
68 |
|
69 |
/** Device Parameter 'ACTIVE' |
70 |
* |
71 |
* Used to activate / deactivate the MIDI input device. |
72 |
*/ |
73 |
class ParameterActive : public DeviceCreationParameterBool { |
74 |
public: |
75 |
ParameterActive(); |
76 |
ParameterActive(String active); |
77 |
virtual String Description(); |
78 |
virtual bool Fix(); |
79 |
virtual bool Mandatory(); |
80 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
81 |
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters); |
82 |
virtual void OnSetValue(bool b) throw (LinuxSamplerException); |
83 |
static String Name(); |
84 |
}; |
85 |
|
86 |
/** Device Parameter 'PORTS' |
87 |
* |
88 |
* 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 |
|
107 |
|
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 |
/** |
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 |
174 |
* This can either do nothing, create more ports |
175 |
* or destroy ports depenging on the parameter |
176 |
* 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. |
179 |
*/ |
180 |
void AcquirePorts(uint Ports); |
181 |
|
182 |
friend class Sampler; // allow Sampler class to destroy midi devices |
183 |
}; |
184 |
} |
185 |
|
186 |
#endif // __LS_MIDIINPUTDEVICE_H__ |