1 |
schoenebeck |
201 |
/*************************************************************************** |
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 |
|
|
#include "MidiInputDevice.h" |
24 |
|
|
|
25 |
|
|
namespace LinuxSampler { |
26 |
|
|
|
27 |
schoenebeck |
221 |
// *************** ParameterActive *************** |
28 |
|
|
// * |
29 |
|
|
|
30 |
|
|
MidiInputDevice::ParameterActive::ParameterActive() : DeviceCreationParameterBool() { |
31 |
|
|
InitWithDefault(); |
32 |
schoenebeck |
201 |
} |
33 |
|
|
|
34 |
schoenebeck |
221 |
MidiInputDevice::ParameterActive::ParameterActive(String active) : DeviceCreationParameterBool(active) { |
35 |
schoenebeck |
201 |
} |
36 |
|
|
|
37 |
schoenebeck |
221 |
String MidiInputDevice::ParameterActive::Description() { |
38 |
|
|
return "Enable / disable device"; |
39 |
schoenebeck |
201 |
} |
40 |
|
|
|
41 |
schoenebeck |
221 |
bool MidiInputDevice::ParameterActive::Fix() { |
42 |
|
|
return false; |
43 |
schoenebeck |
201 |
} |
44 |
|
|
|
45 |
schoenebeck |
221 |
bool MidiInputDevice::ParameterActive::Mandatory() { |
46 |
|
|
return false; |
47 |
schoenebeck |
201 |
} |
48 |
|
|
|
49 |
schoenebeck |
221 |
std::map<String,DeviceCreationParameter*> MidiInputDevice::ParameterActive::DependsAsParameters() { |
50 |
|
|
return std::map<String,DeviceCreationParameter*>(); |
51 |
schoenebeck |
201 |
} |
52 |
|
|
|
53 |
schoenebeck |
221 |
optional<bool> MidiInputDevice::ParameterActive::DefaultAsBool(std::map<String,String> Parameters) { |
54 |
|
|
return true; |
55 |
schoenebeck |
201 |
} |
56 |
|
|
|
57 |
schoenebeck |
221 |
void MidiInputDevice::ParameterActive::OnSetValue(bool b) throw (LinuxSamplerException) { |
58 |
|
|
if (b) ((MidiInputDevice*)pDevice)->Listen(); |
59 |
|
|
else ((MidiInputDevice*)pDevice)->StopListen(); |
60 |
schoenebeck |
201 |
} |
61 |
|
|
|
62 |
schoenebeck |
221 |
String MidiInputDevice::ParameterActive::Name() { |
63 |
|
|
return "ACTIVE"; |
64 |
schoenebeck |
201 |
} |
65 |
|
|
|
66 |
schoenebeck |
221 |
|
67 |
|
|
|
68 |
|
|
// *************** ParameterPorts *************** |
69 |
|
|
// * |
70 |
|
|
|
71 |
|
|
MidiInputDevice::ParameterPorts::ParameterPorts() : DeviceCreationParameterInt() { |
72 |
|
|
InitWithDefault(); |
73 |
schoenebeck |
201 |
} |
74 |
|
|
|
75 |
schoenebeck |
221 |
MidiInputDevice::ParameterPorts::ParameterPorts(String val) : DeviceCreationParameterInt(val) { |
76 |
schoenebeck |
201 |
} |
77 |
|
|
|
78 |
schoenebeck |
221 |
String MidiInputDevice::ParameterPorts::Description() { |
79 |
|
|
return "Number of ports"; |
80 |
schoenebeck |
201 |
} |
81 |
|
|
|
82 |
schoenebeck |
221 |
bool MidiInputDevice::ParameterPorts::Fix() { |
83 |
|
|
return false; |
84 |
schoenebeck |
201 |
} |
85 |
|
|
|
86 |
schoenebeck |
221 |
bool MidiInputDevice::ParameterPorts::Mandatory() { |
87 |
|
|
return false; |
88 |
schoenebeck |
201 |
} |
89 |
|
|
|
90 |
schoenebeck |
221 |
std::map<String,DeviceCreationParameter*> MidiInputDevice::ParameterPorts::DependsAsParameters() { |
91 |
|
|
return std::map<String,DeviceCreationParameter*>(); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
optional<int> MidiInputDevice::ParameterPorts::DefaultAsInt(std::map<String,String> Parameters) { |
95 |
|
|
return 0; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
optional<int> MidiInputDevice::ParameterPorts::RangeMinAsInt(std::map<String,String> Parameters) { |
99 |
|
|
return optional<int>::nothing; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
optional<int> MidiInputDevice::ParameterPorts::RangeMaxAsInt(std::map<String,String> Parameters) { |
103 |
|
|
return optional<int>::nothing; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
std::vector<int> MidiInputDevice::ParameterPorts::PossibilitiesAsInt(std::map<String,String> Parameters) { |
107 |
|
|
return std::vector<int>(); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
void MidiInputDevice::ParameterPorts::OnSetValue(int i) throw (LinuxSamplerException) { |
111 |
|
|
((MidiInputDevice*)pDevice)->AcquirePorts(i); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
String MidiInputDevice::ParameterPorts::Name() { |
115 |
|
|
return "PORTS"; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
// *************** MidiInputDevice *************** |
121 |
|
|
// * |
122 |
|
|
|
123 |
|
|
MidiInputDevice::MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) { |
124 |
|
|
this->Parameters = DriverParameters; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
MidiInputDevice::~MidiInputDevice() { |
128 |
|
|
std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin(); |
129 |
|
|
while (iter != Parameters.end()) { |
130 |
|
|
Parameters.erase(iter); |
131 |
|
|
delete iter->second; |
132 |
|
|
iter++; |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
MidiInputPort* MidiInputDevice::GetPort(uint iPort) throw (MidiInputException) { |
137 |
|
|
if (iPort >= Ports.size()) throw MidiInputException("There is no port " + ToString(iPort)); |
138 |
|
|
return Ports[iPort]; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
std::map<String,DeviceCreationParameter*> MidiInputDevice::DeviceParameters() { |
142 |
|
|
return Parameters; |
143 |
|
|
} |
144 |
|
|
|
145 |
schoenebeck |
201 |
void MidiInputDevice::AcquirePorts(uint newPorts) { |
146 |
|
|
int diff = this->Ports.size() - newPorts; |
147 |
|
|
if (!diff) |
148 |
|
|
return; //Number of ports matches already, nothing to do. |
149 |
|
|
|
150 |
|
|
while (diff != 0) { |
151 |
|
|
if (diff > 0) { //We've got too many ports, remove one |
152 |
|
|
std::map<int,MidiInputPort*>::iterator portsIter = Ports.end(); |
153 |
|
|
--portsIter; |
154 |
|
|
Ports.erase(portsIter); |
155 |
|
|
delete portsIter->second; |
156 |
|
|
diff--; |
157 |
|
|
} |
158 |
|
|
if (diff < 0) { //We don't have enough ports, create one |
159 |
|
|
MidiInputPort* midiPort = this->CreateMidiPort(); |
160 |
|
|
Ports[midiPort->portNumber] = midiPort; |
161 |
|
|
diff++; |
162 |
|
|
} |
163 |
|
|
} |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
} // namespace LinuxSampler |