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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1523 - (hide annotations) (download)
Sun Nov 25 11:40:47 2007 UTC (16 years, 4 months ago) by capela
File size: 7799 byte(s)
* Qt4 migration: fixed instrument map list sorting.

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 schoenebeck 1461 using namespace QSampler;
32 capela 964
33     //-------------------------------------------------------------------------
34     // qsamplerInstrument - MIDI instrument map structure.
35     //
36    
37     // Constructor.
38 capela 980 qsamplerInstrument::qsamplerInstrument ( 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     qsamplerInstrument::~qsamplerInstrument (void)
50     {
51     }
52    
53    
54     // Instrument accessors.
55 capela 980 void qsamplerInstrument::setMap ( int iMap )
56     {
57     m_iMap = iMap;
58     }
59    
60     int qsamplerInstrument::map (void) const
61     {
62     return m_iMap;
63     }
64    
65    
66 capela 964 void qsamplerInstrument::setBank ( int iBank )
67     {
68     m_iBank = iBank;
69     }
70    
71     int qsamplerInstrument::bank (void) const
72     {
73     return m_iBank;
74     }
75    
76    
77 capela 980 void qsamplerInstrument::setProg ( int iProg )
78 capela 964 {
79 capela 980 m_iProg = iProg;
80 capela 964 }
81    
82 capela 980 int qsamplerInstrument::prog (void) const
83 capela 964 {
84 capela 980 return m_iProg;
85 capela 964 }
86    
87    
88     void qsamplerInstrument::setName ( const QString& sName )
89     {
90     m_sName = sName;
91     }
92    
93     const QString& qsamplerInstrument::name (void) const
94     {
95     return m_sName;
96     }
97    
98    
99     void qsamplerInstrument::setEngineName ( const QString& sEngineName )
100     {
101     m_sEngineName = sEngineName;
102     }
103    
104     const QString& qsamplerInstrument::engineName (void) const
105     {
106     return m_sEngineName;
107     }
108    
109    
110     void qsamplerInstrument::setInstrumentFile ( const QString& sInstrumentFile )
111     {
112     m_sInstrumentFile = sInstrumentFile;
113     }
114    
115     const QString& qsamplerInstrument::instrumentFile (void) const
116     {
117     return m_sInstrumentFile;
118     }
119    
120    
121     const QString& qsamplerInstrument::instrumentName (void) const
122     {
123     return m_sInstrumentName;
124     }
125    
126    
127     void qsamplerInstrument::setInstrumentNr ( int iInstrumentNr )
128     {
129     m_iInstrumentNr = iInstrumentNr;
130     }
131    
132     int qsamplerInstrument::instrumentNr (void) const
133     {
134     return m_iInstrumentNr;
135     }
136    
137    
138     void qsamplerInstrument::setVolume ( float fVolume )
139     {
140     m_fVolume = fVolume;
141     }
142    
143     float qsamplerInstrument::volume (void) const
144     {
145     return m_fVolume;
146     }
147    
148    
149     void qsamplerInstrument::setLoadMode ( int iLoadMode )
150     {
151     m_iLoadMode = iLoadMode;
152     }
153    
154     int qsamplerInstrument::loadMode (void) const
155     {
156     return m_iLoadMode;
157     }
158    
159    
160     // Sync methods.
161 capela 980 bool qsamplerInstrument::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 980 bool qsamplerInstrument::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 980 bool qsamplerInstrument::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     QStringList qsamplerInstrument::getMapNames (void)
318     {
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     QString qsamplerInstrument::getMapName ( int iMidiMap )
346     {
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    
371 capela 964 // end of qsamplerInstrument.cpp

  ViewVC Help
Powered by ViewVC