1 |
// qsamplerInstrument.cpp |
// qsamplerInstrument.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
Copyright (C) 2007, Christian Schoenebeck |
6 |
This program is free software; you can redistribute it and/or |
|
7 |
modify it under the terms of the GNU General Public License |
This program is free software; you can redistribute it and/or |
8 |
as published by the Free Software Foundation; either version 2 |
modify it under the terms of the GNU General Public License |
9 |
of the License, or (at your option) any later version. |
as published by the Free Software Foundation; either version 2 |
10 |
|
of the License, or (at your option) any later version. |
11 |
This program is distributed in the hope that it will be useful, |
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
This program is distributed in the hope that it will be useful, |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
GNU General Public License for more details. |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
GNU General Public License for more details. |
16 |
You should have received a copy of the GNU General Public License along |
|
17 |
with this program; if not, write to the Free Software Foundation, Inc., |
You should have received a copy of the GNU General Public License along |
18 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
*****************************************************************************/ |
|
21 |
|
*****************************************************************************/ |
22 |
#include "qsamplerAbout.h" |
|
23 |
#include "qsamplerInstrument.h" |
#include "qsamplerAbout.h" |
24 |
|
#include "qsamplerInstrument.h" |
25 |
#include "qsamplerMainForm.h" |
#include "qsamplerUtilities.h" |
26 |
|
|
27 |
|
#include "qsamplerOptions.h" |
28 |
//------------------------------------------------------------------------- |
#include "qsamplerMainForm.h" |
29 |
// qsamplerInstrument - MIDI instrument map structure. |
|
30 |
// |
|
31 |
|
using namespace QSampler; |
32 |
// Constructor. |
|
33 |
qsamplerInstrument::qsamplerInstrument ( int iBank, int iProgram ) |
//------------------------------------------------------------------------- |
34 |
{ |
// qsamplerInstrument - MIDI instrument map structure. |
35 |
m_iBank = iBank; |
// |
36 |
m_iProgram = iProgram; |
|
37 |
m_iInstrumentNr = 0;; |
// Constructor. |
38 |
m_fVolume = 1.0f; |
qsamplerInstrument::qsamplerInstrument ( int iMap, int iBank, int iProg ) |
39 |
m_iLoadMode = 0; |
{ |
40 |
} |
m_iMap = iMap; |
41 |
|
m_iBank = iBank; |
42 |
// Default destructor. |
m_iProg = iProg; |
43 |
qsamplerInstrument::~qsamplerInstrument (void) |
m_iInstrumentNr = 0; |
44 |
{ |
m_fVolume = 1.0f; |
45 |
} |
m_iLoadMode = 0; |
46 |
|
} |
47 |
|
|
48 |
// Instrument accessors. |
// Default destructor. |
49 |
void qsamplerInstrument::setBank ( int iBank ) |
qsamplerInstrument::~qsamplerInstrument (void) |
50 |
{ |
{ |
51 |
m_iBank = iBank; |
} |
52 |
} |
|
53 |
|
|
54 |
int qsamplerInstrument::bank (void) const |
// Instrument accessors. |
55 |
{ |
void qsamplerInstrument::setMap ( int iMap ) |
56 |
return m_iBank; |
{ |
57 |
} |
m_iMap = iMap; |
58 |
|
} |
59 |
|
|
60 |
void qsamplerInstrument::setProgram ( int iProgram ) |
int qsamplerInstrument::map (void) const |
61 |
{ |
{ |
62 |
m_iProgram = iProgram; |
return m_iMap; |
63 |
} |
} |
64 |
|
|
65 |
int qsamplerInstrument::program (void) const |
|
66 |
{ |
void qsamplerInstrument::setBank ( int iBank ) |
67 |
return m_iProgram; |
{ |
68 |
} |
m_iBank = iBank; |
69 |
|
} |
70 |
|
|
71 |
void qsamplerInstrument::setName ( const QString& sName ) |
int qsamplerInstrument::bank (void) const |
72 |
{ |
{ |
73 |
m_sName = sName; |
return m_iBank; |
74 |
} |
} |
75 |
|
|
76 |
const QString& qsamplerInstrument::name (void) const |
|
77 |
{ |
void qsamplerInstrument::setProg ( int iProg ) |
78 |
return m_sName; |
{ |
79 |
} |
m_iProg = iProg; |
80 |
|
} |
81 |
|
|
82 |
void qsamplerInstrument::setEngineName ( const QString& sEngineName ) |
int qsamplerInstrument::prog (void) const |
83 |
{ |
{ |
84 |
m_sEngineName = sEngineName; |
return m_iProg; |
85 |
} |
} |
86 |
|
|
87 |
const QString& qsamplerInstrument::engineName (void) const |
|
88 |
{ |
void qsamplerInstrument::setName ( const QString& sName ) |
89 |
return m_sEngineName; |
{ |
90 |
} |
m_sName = sName; |
91 |
|
} |
92 |
|
|
93 |
void qsamplerInstrument::setInstrumentFile ( const QString& sInstrumentFile ) |
const QString& qsamplerInstrument::name (void) const |
94 |
{ |
{ |
95 |
m_sInstrumentFile = sInstrumentFile; |
return m_sName; |
96 |
} |
} |
97 |
|
|
98 |
const QString& qsamplerInstrument::instrumentFile (void) const |
|
99 |
{ |
void qsamplerInstrument::setEngineName ( const QString& sEngineName ) |
100 |
return m_sInstrumentFile; |
{ |
101 |
} |
m_sEngineName = sEngineName; |
102 |
|
} |
103 |
|
|
104 |
const QString& qsamplerInstrument::instrumentName (void) const |
const QString& qsamplerInstrument::engineName (void) const |
105 |
{ |
{ |
106 |
return m_sInstrumentName; |
return m_sEngineName; |
107 |
} |
} |
108 |
|
|
109 |
|
|
110 |
void qsamplerInstrument::setInstrumentNr ( int iInstrumentNr ) |
void qsamplerInstrument::setInstrumentFile ( const QString& sInstrumentFile ) |
111 |
{ |
{ |
112 |
m_iInstrumentNr = iInstrumentNr; |
m_sInstrumentFile = sInstrumentFile; |
113 |
} |
} |
114 |
|
|
115 |
int qsamplerInstrument::instrumentNr (void) const |
const QString& qsamplerInstrument::instrumentFile (void) const |
116 |
{ |
{ |
117 |
return m_iInstrumentNr; |
return m_sInstrumentFile; |
118 |
} |
} |
119 |
|
|
120 |
|
|
121 |
void qsamplerInstrument::setVolume ( float fVolume ) |
const QString& qsamplerInstrument::instrumentName (void) const |
122 |
{ |
{ |
123 |
m_fVolume = fVolume; |
return m_sInstrumentName; |
124 |
} |
} |
125 |
|
|
126 |
float qsamplerInstrument::volume (void) const |
|
127 |
{ |
void qsamplerInstrument::setInstrumentNr ( int iInstrumentNr ) |
128 |
return m_fVolume; |
{ |
129 |
} |
m_iInstrumentNr = iInstrumentNr; |
130 |
|
} |
131 |
|
|
132 |
void qsamplerInstrument::setLoadMode ( int iLoadMode ) |
int qsamplerInstrument::instrumentNr (void) const |
133 |
{ |
{ |
134 |
m_iLoadMode = iLoadMode; |
return m_iInstrumentNr; |
135 |
} |
} |
136 |
|
|
137 |
int qsamplerInstrument::loadMode (void) const |
|
138 |
{ |
void qsamplerInstrument::setVolume ( float fVolume ) |
139 |
return m_iLoadMode; |
{ |
140 |
} |
m_fVolume = fVolume; |
141 |
|
} |
142 |
|
|
143 |
// Sync methods. |
float qsamplerInstrument::volume (void) const |
144 |
bool qsamplerInstrument::map (void) |
{ |
145 |
{ |
return m_fVolume; |
146 |
#ifdef CONFIG_MIDI_INSTRUMENT |
} |
147 |
|
|
148 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
|
149 |
if (pMainForm) |
void qsamplerInstrument::setLoadMode ( int iLoadMode ) |
150 |
return false; |
{ |
151 |
if (pMainForm->client() == NULL) |
m_iLoadMode = iLoadMode; |
152 |
return false; |
} |
153 |
|
|
154 |
if (m_iBank < 0 || m_iProgram < 0) |
int qsamplerInstrument::loadMode (void) const |
155 |
return false; |
{ |
156 |
|
return m_iLoadMode; |
157 |
lscp_midi_instrument_t instr; |
} |
158 |
|
|
159 |
instr.bank_msb = (m_iBank & 0x3f80) >> 7; |
|
160 |
instr.bank_lsb = (m_iBank & 0x7f); |
// Sync methods. |
161 |
instr.program = (m_iProgram & 0x7f); |
bool qsamplerInstrument::mapInstrument (void) |
162 |
|
{ |
163 |
lscp_load_mode_t load_mode; |
#ifdef CONFIG_MIDI_INSTRUMENT |
164 |
switch (m_iLoadMode) { |
|
165 |
case 3: |
MainForm *pMainForm = MainForm::getInstance(); |
166 |
load_mode = LSCP_LOAD_PERSISTENT; |
if (pMainForm == NULL) |
167 |
break; |
return false; |
168 |
case 2: |
if (pMainForm->client() == NULL) |
169 |
load_mode = LSCP_LOAD_ON_DEMAND_HOLD; |
return false; |
170 |
break; |
|
171 |
case 1: |
if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0) |
172 |
load_mode = LSCP_LOAD_ON_DEMAND; |
return false; |
173 |
break; |
|
174 |
case 0: |
lscp_midi_instrument_t instr; |
175 |
default: |
|
176 |
load_mode = LSCP_LOAD_DEFAULT; |
instr.map = m_iMap; |
177 |
break; |
instr.bank = (m_iBank & 0x0fff); |
178 |
} |
instr.prog = (m_iProg & 0x7f); |
179 |
|
|
180 |
if (::lscp_map_midi_instrument(pMainForm->client(), &instr, |
lscp_load_mode_t load_mode; |
181 |
m_sEngineName.latin1(), |
switch (m_iLoadMode) { |
182 |
m_sInstrumentFile.latin1(), |
case 3: |
183 |
m_iInstrumentNr, |
load_mode = LSCP_LOAD_PERSISTENT; |
184 |
m_fVolume, |
break; |
185 |
load_mode, |
case 2: |
186 |
m_sName.latin1()) != LSCP_OK) { |
load_mode = LSCP_LOAD_ON_DEMAND_HOLD; |
187 |
pMainForm->appendMessagesClient("lscp_map_midi_instrument"); |
break; |
188 |
return false; |
case 1: |
189 |
} |
load_mode = LSCP_LOAD_ON_DEMAND; |
190 |
|
break; |
191 |
return true; |
case 0: |
192 |
|
default: |
193 |
#else |
load_mode = LSCP_LOAD_DEFAULT; |
194 |
|
break; |
195 |
return false; |
} |
196 |
|
|
197 |
#endif |
if (::lscp_map_midi_instrument(pMainForm->client(), &instr, |
198 |
} |
m_sEngineName.toUtf8().constData(), |
199 |
|
qsamplerUtilities::lscpEscapePath( |
200 |
|
m_sInstrumentFile).toUtf8().constData(), |
201 |
bool qsamplerInstrument::unmap (void) |
m_iInstrumentNr, m_fVolume, load_mode, |
202 |
{ |
m_sName.toUtf8().constData()) != LSCP_OK) { |
203 |
#ifdef CONFIG_MIDI_INSTRUMENT |
pMainForm->appendMessagesClient("lscp_map_midi_instrument"); |
204 |
|
return false; |
205 |
if (m_iBank < 0 || m_iProgram < 0) |
} |
206 |
return false; |
|
207 |
|
return true; |
208 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
|
209 |
if (pMainForm) |
#else |
210 |
return false; |
|
211 |
if (pMainForm->client() == NULL) |
return false; |
212 |
return false; |
|
213 |
|
#endif |
214 |
lscp_midi_instrument_t instr; |
} |
215 |
|
|
216 |
instr.bank_msb = (m_iBank & 0x3f80) >> 7; |
|
217 |
instr.bank_lsb = (m_iBank & 0x7f); |
bool qsamplerInstrument::unmapInstrument (void) |
218 |
instr.program = (m_iProgram & 0x7f); |
{ |
219 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
220 |
if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) { |
|
221 |
pMainForm->appendMessagesClient("lscp_unmap_midi_instrument"); |
if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0) |
222 |
return false; |
return false; |
223 |
} |
|
224 |
|
MainForm *pMainForm = MainForm::getInstance(); |
225 |
return true; |
if (pMainForm == NULL) |
226 |
|
return false; |
227 |
#else |
if (pMainForm->client() == NULL) |
228 |
|
return false; |
229 |
return false; |
|
230 |
|
lscp_midi_instrument_t instr; |
231 |
#endif |
|
232 |
} |
instr.map = m_iMap; |
233 |
|
instr.bank = (m_iBank & 0x0fff); |
234 |
|
instr.prog = (m_iProg & 0x7f); |
235 |
bool qsamplerInstrument::get (void) |
|
236 |
{ |
if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) { |
237 |
#ifdef CONFIG_MIDI_INSTRUMENT |
pMainForm->appendMessagesClient("lscp_unmap_midi_instrument"); |
238 |
|
return false; |
239 |
if (m_iBank < 0 || m_iProgram < 0) |
} |
240 |
return false; |
|
241 |
|
return true; |
242 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
|
243 |
if (pMainForm) |
#else |
244 |
return false; |
|
245 |
if (pMainForm->client() == NULL) |
return false; |
246 |
return false; |
|
247 |
|
#endif |
248 |
lscp_midi_instrument_t instr; |
} |
249 |
|
|
250 |
instr.bank_msb = (m_iBank & 0x3f80) >> 7; |
|
251 |
instr.bank_lsb = (m_iBank & 0x7f); |
bool qsamplerInstrument::getInstrument (void) |
252 |
instr.program = (m_iProgram & 0x7f); |
{ |
253 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
254 |
lscp_midi_instrument_info_t *pInstrInfo |
|
255 |
= ::lscp_get_midi_instrument_info(pMainForm->client(), &instr); |
if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0) |
256 |
if (pInstrInfo == NULL) { |
return false; |
257 |
pMainForm->appendMessagesClient("lscp_get_midi_instrument_info"); |
|
258 |
return false; |
MainForm *pMainForm = MainForm::getInstance(); |
259 |
} |
if (pMainForm == NULL) |
260 |
|
return false; |
261 |
m_sName = pInstrInfo->name; |
if (pMainForm->client() == NULL) |
262 |
m_sEngineName = pInstrInfo->engine_name; |
return false; |
263 |
m_sInstrumentName = pInstrInfo->instrument_name; |
|
264 |
m_sInstrumentFile = pInstrInfo->instrument_file; |
lscp_midi_instrument_t instr; |
265 |
m_iInstrumentNr = pInstrInfo->instrument_nr; |
|
266 |
m_fVolume = pInstrInfo->volume; |
instr.map = m_iMap; |
267 |
|
instr.bank = (m_iBank & 0x0fff); |
268 |
switch (pInstrInfo->load_mode) { |
instr.prog = (m_iProg & 0x7f); |
269 |
case LSCP_LOAD_PERSISTENT: |
|
270 |
m_iLoadMode = 3; |
lscp_midi_instrument_info_t *pInstrInfo |
271 |
break; |
= ::lscp_get_midi_instrument_info(pMainForm->client(), &instr); |
272 |
case LSCP_LOAD_ON_DEMAND_HOLD: |
if (pInstrInfo == NULL) { |
273 |
m_iLoadMode = 2; |
pMainForm->appendMessagesClient("lscp_get_midi_instrument_info"); |
274 |
break; |
return false; |
275 |
case LSCP_LOAD_ON_DEMAND: |
} |
276 |
m_iLoadMode = 1; |
|
277 |
break; |
m_sName = qsamplerUtilities::lscpEscapedTextToRaw(pInstrInfo->name); |
278 |
case LSCP_LOAD_DEFAULT: |
m_sEngineName = pInstrInfo->engine_name; |
279 |
default: |
m_sInstrumentName = qsamplerUtilities::lscpEscapedTextToRaw( |
280 |
m_iLoadMode = 0; |
pInstrInfo->instrument_name); |
281 |
break; |
m_sInstrumentFile = qsamplerUtilities::lscpEscapedPathToPosix( |
282 |
} |
pInstrInfo->instrument_file); |
283 |
|
m_iInstrumentNr = pInstrInfo->instrument_nr; |
284 |
// Fix something. |
m_fVolume = pInstrInfo->volume; |
285 |
if (m_sName.isEmpty()) |
|
286 |
m_sName = m_sInstrumentName; |
switch (pInstrInfo->load_mode) { |
287 |
|
case LSCP_LOAD_PERSISTENT: |
288 |
return true; |
m_iLoadMode = 3; |
289 |
|
break; |
290 |
#else |
case LSCP_LOAD_ON_DEMAND_HOLD: |
291 |
|
m_iLoadMode = 2; |
292 |
return false; |
break; |
293 |
|
case LSCP_LOAD_ON_DEMAND: |
294 |
#endif |
m_iLoadMode = 1; |
295 |
} |
break; |
296 |
|
case LSCP_LOAD_DEFAULT: |
297 |
|
default: |
298 |
// end of qsamplerInstrument.cpp |
m_iLoadMode = 0; |
299 |
|
break; |
300 |
|
} |
301 |
|
|
302 |
|
// Fix something. |
303 |
|
if (m_sName.isEmpty()) |
304 |
|
m_sName = m_sInstrumentName; |
305 |
|
|
306 |
|
return true; |
307 |
|
|
308 |
|
#else |
309 |
|
|
310 |
|
return false; |
311 |
|
|
312 |
|
#endif |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
// Instrument map name enumerator. |
317 |
|
QStringList qsamplerInstrument::getMapNames (void) |
318 |
|
{ |
319 |
|
QStringList maps; |
320 |
|
|
321 |
|
MainForm *pMainForm = MainForm::getInstance(); |
322 |
|
if (pMainForm == NULL) |
323 |
|
return maps; |
324 |
|
if (pMainForm->client() == NULL) |
325 |
|
return maps; |
326 |
|
|
327 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
328 |
|
int *piMaps = ::lscp_list_midi_instrument_maps(pMainForm->client()); |
329 |
|
if (piMaps == NULL) { |
330 |
|
if (::lscp_client_get_errno(pMainForm->client())) |
331 |
|
pMainForm->appendMessagesClient("lscp_list_midi_instruments"); |
332 |
|
} else { |
333 |
|
for (int iMap = 0; piMaps[iMap] >= 0; iMap++) { |
334 |
|
const QString& sMapName = getMapName(piMaps[iMap]); |
335 |
|
if (!sMapName.isEmpty()) |
336 |
|
maps.append(sMapName); |
337 |
|
} |
338 |
|
} |
339 |
|
#endif |
340 |
|
|
341 |
|
return maps; |
342 |
|
} |
343 |
|
|
344 |
|
// Instrument map name enumerator. |
345 |
|
QString qsamplerInstrument::getMapName ( int iMidiMap ) |
346 |
|
{ |
347 |
|
QString sMapName; |
348 |
|
|
349 |
|
MainForm *pMainForm = MainForm::getInstance(); |
350 |
|
if (pMainForm == NULL) |
351 |
|
return sMapName; |
352 |
|
if (pMainForm->client() == NULL) |
353 |
|
return sMapName; |
354 |
|
|
355 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
356 |
|
const char *pszMapName |
357 |
|
= ::lscp_get_midi_instrument_map_name(pMainForm->client(), iMidiMap); |
358 |
|
if (pszMapName == NULL) { |
359 |
|
pszMapName = " -"; |
360 |
|
if (::lscp_client_get_errno(pMainForm->client())) |
361 |
|
pMainForm->appendMessagesClient("lscp_get_midi_instrument_name"); |
362 |
|
} |
363 |
|
sMapName = QString("%1 - %2").arg(iMidiMap) |
364 |
|
.arg(qsamplerUtilities::lscpEscapedTextToRaw(pszMapName)); |
365 |
|
#endif |
366 |
|
|
367 |
|
return sMapName; |
368 |
|
} |
369 |
|
|
370 |
|
|
371 |
|
// end of qsamplerInstrument.cpp |