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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1558 - (hide annotations) (download)
Thu Dec 6 09:35:33 2007 UTC (16 years, 4 months ago) by capela
File size: 7596 byte(s)
* Qt4 migration: complete QSampler namespace overhaul.

1 capela 964 // qsamplerInstrument.cpp
2     //
3     /****************************************************************************
4 schoenebeck 1386 Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5 capela 1464 Copyright (C) 2007, Christian Schoenebeck
6 capela 964
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (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 along
18     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    
23     #include "qsamplerAbout.h"
24     #include "qsamplerInstrument.h"
25 capela 1499 #include "qsamplerUtilities.h"
26 capela 964
27 capela 1513 #include "qsamplerOptions.h"
28 capela 964 #include "qsamplerMainForm.h"
29    
30 capela 1499
31 capela 1558 namespace QSampler {
32 capela 964
33     //-------------------------------------------------------------------------
34 capela 1558 // QSampler::Instrument - MIDI instrument map structure.
35 capela 964 //
36    
37     // Constructor.
38 capela 1558 Instrument::Instrument ( int iMap, int iBank, int iProg )
39 capela 964 {
40 capela 980 m_iMap = iMap;
41 capela 964 m_iBank = iBank;
42 capela 980 m_iProg = iProg;
43 capela 1523 m_iInstrumentNr = 0;
44 capela 964 m_fVolume = 1.0f;
45     m_iLoadMode = 0;
46     }
47    
48     // Default destructor.
49 capela 1558 Instrument::~Instrument (void)
50 capela 964 {
51     }
52    
53    
54     // Instrument accessors.
55 capela 1558 void Instrument::setMap ( int iMap )
56 capela 980 {
57     m_iMap = iMap;
58     }
59    
60 capela 1558 int Instrument::map (void) const
61 capela 980 {
62     return m_iMap;
63     }
64    
65    
66 capela 1558 void Instrument::setBank ( int iBank )
67 capela 964 {
68     m_iBank = iBank;
69     }
70    
71 capela 1558 int Instrument::bank (void) const
72 capela 964 {
73     return m_iBank;
74     }
75    
76    
77 capela 1558 void Instrument::setProg ( int iProg )
78 capela 964 {
79 capela 980 m_iProg = iProg;
80 capela 964 }
81    
82 capela 1558 int Instrument::prog (void) const
83 capela 964 {
84 capela 980 return m_iProg;
85 capela 964 }
86    
87    
88 capela 1558 void Instrument::setName ( const QString& sName )
89 capela 964 {
90     m_sName = sName;
91     }
92    
93 capela 1558 const QString& Instrument::name (void) const
94 capela 964 {
95     return m_sName;
96     }
97    
98    
99 capela 1558 void Instrument::setEngineName ( const QString& sEngineName )
100 capela 964 {
101     m_sEngineName = sEngineName;
102     }
103    
104 capela 1558 const QString& Instrument::engineName (void) const
105 capela 964 {
106     return m_sEngineName;
107     }
108    
109    
110 capela 1558 void Instrument::setInstrumentFile ( const QString& sInstrumentFile )
111 capela 964 {
112     m_sInstrumentFile = sInstrumentFile;
113     }
114    
115 capela 1558 const QString& Instrument::instrumentFile (void) const
116 capela 964 {
117     return m_sInstrumentFile;
118     }
119    
120    
121 capela 1558 const QString& Instrument::instrumentName (void) const
122 capela 964 {
123     return m_sInstrumentName;
124     }
125    
126    
127 capela 1558 void Instrument::setInstrumentNr ( int iInstrumentNr )
128 capela 964 {
129     m_iInstrumentNr = iInstrumentNr;
130     }
131    
132 capela 1558 int Instrument::instrumentNr (void) const
133 capela 964 {
134     return m_iInstrumentNr;
135     }
136    
137    
138 capela 1558 void Instrument::setVolume ( float fVolume )
139 capela 964 {
140     m_fVolume = fVolume;
141     }
142    
143 capela 1558 float Instrument::volume (void) const
144 capela 964 {
145     return m_fVolume;
146     }
147    
148    
149 capela 1558 void Instrument::setLoadMode ( int iLoadMode )
150 capela 964 {
151     m_iLoadMode = iLoadMode;
152     }
153    
154 capela 1558 int Instrument::loadMode (void) const
155 capela 964 {
156     return m_iLoadMode;
157     }
158    
159    
160     // Sync methods.
161 capela 1558 bool Instrument::mapInstrument (void)
162 capela 964 {
163     #ifdef CONFIG_MIDI_INSTRUMENT
164    
165 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
166 capela 964 if (pMainForm == NULL)
167     return false;
168     if (pMainForm->client() == NULL)
169     return false;
170    
171 capela 980 if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
172 capela 964 return false;
173    
174     lscp_midi_instrument_t instr;
175    
176 capela 980 instr.map = m_iMap;
177     instr.bank = (m_iBank & 0x0fff);
178     instr.prog = (m_iProg & 0x7f);
179 capela 964
180     lscp_load_mode_t load_mode;
181     switch (m_iLoadMode) {
182     case 3:
183     load_mode = LSCP_LOAD_PERSISTENT;
184     break;
185     case 2:
186     load_mode = LSCP_LOAD_ON_DEMAND_HOLD;
187     break;
188     case 1:
189     load_mode = LSCP_LOAD_ON_DEMAND;
190     break;
191     case 0:
192     default:
193     load_mode = LSCP_LOAD_DEFAULT;
194     break;
195     }
196    
197     if (::lscp_map_midi_instrument(pMainForm->client(), &instr,
198 capela 1499 m_sEngineName.toUtf8().constData(),
199     qsamplerUtilities::lscpEscapePath(
200     m_sInstrumentFile).toUtf8().constData(),
201 capela 1505 m_iInstrumentNr, m_fVolume, load_mode,
202 capela 1499 m_sName.toUtf8().constData()) != LSCP_OK) {
203 capela 964 pMainForm->appendMessagesClient("lscp_map_midi_instrument");
204     return false;
205     }
206    
207     return true;
208    
209     #else
210    
211     return false;
212    
213     #endif
214     }
215    
216    
217 capela 1558 bool Instrument::unmapInstrument (void)
218 capela 964 {
219     #ifdef CONFIG_MIDI_INSTRUMENT
220    
221 capela 980 if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
222 capela 964 return false;
223    
224 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
225 capela 964 if (pMainForm == NULL)
226     return false;
227     if (pMainForm->client() == NULL)
228     return false;
229    
230     lscp_midi_instrument_t instr;
231    
232 capela 980 instr.map = m_iMap;
233     instr.bank = (m_iBank & 0x0fff);
234     instr.prog = (m_iProg & 0x7f);
235 capela 964
236     if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) {
237     pMainForm->appendMessagesClient("lscp_unmap_midi_instrument");
238     return false;
239     }
240    
241     return true;
242    
243     #else
244    
245     return false;
246    
247     #endif
248     }
249    
250    
251 capela 1558 bool Instrument::getInstrument (void)
252 capela 964 {
253     #ifdef CONFIG_MIDI_INSTRUMENT
254    
255 capela 980 if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
256 capela 964 return false;
257    
258 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
259 capela 964 if (pMainForm == NULL)
260     return false;
261     if (pMainForm->client() == NULL)
262     return false;
263    
264     lscp_midi_instrument_t instr;
265    
266 capela 980 instr.map = m_iMap;
267     instr.bank = (m_iBank & 0x0fff);
268     instr.prog = (m_iProg & 0x7f);
269 capela 964
270     lscp_midi_instrument_info_t *pInstrInfo
271     = ::lscp_get_midi_instrument_info(pMainForm->client(), &instr);
272     if (pInstrInfo == NULL) {
273     pMainForm->appendMessagesClient("lscp_get_midi_instrument_info");
274     return false;
275     }
276    
277 capela 1509 m_sName = qsamplerUtilities::lscpEscapedTextToRaw(pInstrInfo->name);
278     m_sEngineName = pInstrInfo->engine_name;
279     m_sInstrumentName = qsamplerUtilities::lscpEscapedTextToRaw(
280     pInstrInfo->instrument_name);
281     m_sInstrumentFile = qsamplerUtilities::lscpEscapedPathToPosix(
282     pInstrInfo->instrument_file);
283     m_iInstrumentNr = pInstrInfo->instrument_nr;
284     m_fVolume = pInstrInfo->volume;
285 capela 964
286     switch (pInstrInfo->load_mode) {
287     case LSCP_LOAD_PERSISTENT:
288     m_iLoadMode = 3;
289     break;
290     case LSCP_LOAD_ON_DEMAND_HOLD:
291     m_iLoadMode = 2;
292     break;
293     case LSCP_LOAD_ON_DEMAND:
294     m_iLoadMode = 1;
295     break;
296     case LSCP_LOAD_DEFAULT:
297     default:
298     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 capela 980 // Instrument map name enumerator.
317 capela 1558 QStringList Instrument::getMapNames (void)
318 capela 980 {
319     QStringList maps;
320    
321 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
322 capela 980 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 capela 987 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 capela 980 }
339     #endif
340    
341     return maps;
342     }
343    
344     // Instrument map name enumerator.
345 capela 1558 QString Instrument::getMapName ( int iMidiMap )
346 capela 980 {
347     QString sMapName;
348    
349 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
350 capela 980 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 capela 987 if (pszMapName == NULL) {
359 capela 980 pszMapName = " -";
360 capela 987 if (::lscp_client_get_errno(pMainForm->client()))
361     pMainForm->appendMessagesClient("lscp_get_midi_instrument_name");
362     }
363 capela 1509 sMapName = QString("%1 - %2").arg(iMidiMap)
364     .arg(qsamplerUtilities::lscpEscapedTextToRaw(pszMapName));
365 capela 980 #endif
366    
367     return sMapName;
368     }
369    
370 capela 1558 } // namespace QSampler
371 capela 980
372 capela 964 // end of qsamplerInstrument.cpp

  ViewVC Help
Powered by ViewVC