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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 987 - (show annotations) (download)
Tue Dec 19 11:19:55 2006 UTC (17 years, 4 months ago) by capela
File size: 7527 byte(s)
* Revised error verbosity in general and on session load/save;
  hour-glass wait cursor is now displayed on session load/save;
  keyboard shortcuts changed on MIDI instruments view context;
  improved channel strip arrangement on session open/load;
  instrument map entry removal confirmation (as optional);
  corrected some tooltip text strings.

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

  ViewVC Help
Powered by ViewVC