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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1464 - (hide annotations) (download)
Thu Nov 1 17:14:21 2007 UTC (16 years, 6 months ago) by capela
File size: 7750 byte(s)
- Qt4 migration: missing copyright headers update.

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

  ViewVC Help
Powered by ViewVC