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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1499 - (hide annotations) (download)
Tue Nov 20 16:48:04 2007 UTC (16 years, 5 months ago) by capela
File size: 7792 byte(s)
* Qt4 migration: one first step forward to kiss Qt3Support goodbye.

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

  ViewVC Help
Powered by ViewVC