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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1386 - (hide annotations) (download)
Fri Oct 5 17:41:49 2007 UTC (16 years, 6 months ago) by schoenebeck
File size: 7574 byte(s)
* Added support for LSCP escape sequences to allow loading and
  mapping instrument files with special characters in their
  filename (fixes #47).

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

  ViewVC Help
Powered by ViewVC