/[svn]/qsampler/trunk/src/qsamplerInstrument.cpp
ViewVC logotype

Contents of /qsampler/trunk/src/qsamplerInstrument.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1461 - (show annotations) (download)
Sun Oct 28 23:30:36 2007 UTC (16 years, 5 months ago) by schoenebeck
File size: 7705 byte(s)
* started to port QSampler to Qt4 (NOTE: this version is yet broken, use
  the latest tarball release 0.1.5 until the Qt4 port is completed)

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

  ViewVC Help
Powered by ViewVC