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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 980 - (hide annotations) (download)
Sun Dec 17 22:29:29 2006 UTC (17 years, 4 months ago) by capela
File size: 7246 byte(s)
* Revised and extended MIDI instrument mapping feature; this time
  two (2) MIDI maps are being implicitly created, ones designated
  as 'Chromatic' (0) and another as 'Drum Kits' (1), which can be
  assigned to each sampler channel. (ATTN: this commit elevates the
  requirements for liblscp >= 0.5.0, also on todays CVS and pending
  proper release very soon).

1 capela 964 // 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 capela 980 qsamplerInstrument::qsamplerInstrument ( int iMap, int iBank, int iProg )
34 capela 964 {
35 capela 980 m_iMap = iMap;
36 capela 964 m_iBank = iBank;
37 capela 980 m_iProg = iProg;
38 capela 964 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 capela 980 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 capela 964 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 capela 980 void qsamplerInstrument::setProg ( int iProg )
73 capela 964 {
74 capela 980 m_iProg = iProg;
75 capela 964 }
76    
77 capela 980 int qsamplerInstrument::prog (void) const
78 capela 964 {
79 capela 980 return m_iProg;
80 capela 964 }
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 capela 980 bool qsamplerInstrument::mapInstrument (void)
157 capela 964 {
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 capela 980 if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
167 capela 964 return false;
168    
169     lscp_midi_instrument_t instr;
170    
171 capela 980 instr.map = m_iMap;
172     instr.bank = (m_iBank & 0x0fff);
173     instr.prog = (m_iProg & 0x7f);
174 capela 964
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 capela 980 bool qsamplerInstrument::unmapInstrument (void)
214 capela 964 {
215     #ifdef CONFIG_MIDI_INSTRUMENT
216    
217 capela 980 if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
218 capela 964 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 capela 980 instr.map = m_iMap;
229     instr.bank = (m_iBank & 0x0fff);
230     instr.prog = (m_iProg & 0x7f);
231 capela 964
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 capela 980 bool qsamplerInstrument::getInstrument (void)
248 capela 964 {
249     #ifdef CONFIG_MIDI_INSTRUMENT
250    
251 capela 980 if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
252 capela 964 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 capela 980 instr.map = m_iMap;
263     instr.bank = (m_iBank & 0x0fff);
264     instr.prog = (m_iProg & 0x7f);
265 capela 964
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 capela 980 // 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     for (int iMap = 0; piMaps && piMaps[iMap] >= 0; iMap++) {
324     const QString& sMapName = getMapName(piMaps[iMap]);
325     if (!sMapName.isEmpty())
326     maps.append(sMapName);
327     }
328     #endif
329    
330     return maps;
331     }
332    
333     // Instrument map name enumerator.
334     QString qsamplerInstrument::getMapName ( int iMidiMap )
335     {
336     QString sMapName;
337    
338     qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
339     if (pMainForm == NULL)
340     return sMapName;
341     if (pMainForm->client() == NULL)
342     return sMapName;
343    
344     #ifdef CONFIG_MIDI_INSTRUMENT
345     const char *pszMapName
346     = ::lscp_get_midi_instrument_map_name(pMainForm->client(), iMidiMap);
347     if (pszMapName == NULL)
348     pszMapName = " -";
349     sMapName = QString("%1 - %2").arg(iMidiMap).arg(pszMapName);
350     #endif
351    
352     return sMapName;
353     }
354    
355    
356 capela 964 // end of qsamplerInstrument.cpp

  ViewVC Help
Powered by ViewVC