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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 964 - (hide annotations) (download)
Mon Dec 4 17:06:04 2006 UTC (17 years, 4 months ago) by capela
File size: 6040 byte(s)
* Bare MIDI instrument map editing is now effective.

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     qsamplerInstrument::qsamplerInstrument ( int iBank, int iProgram )
34     {
35     m_iBank = iBank;
36     m_iProgram = iProgram;
37     m_iInstrumentNr = 0;;
38     m_fVolume = 1.0f;
39     m_iLoadMode = 0;
40     }
41    
42     // Default destructor.
43     qsamplerInstrument::~qsamplerInstrument (void)
44     {
45     }
46    
47    
48     // Instrument accessors.
49     void qsamplerInstrument::setBank ( int iBank )
50     {
51     m_iBank = iBank;
52     }
53    
54     int qsamplerInstrument::bank (void) const
55     {
56     return m_iBank;
57     }
58    
59    
60     void qsamplerInstrument::setProgram ( int iProgram )
61     {
62     m_iProgram = iProgram;
63     }
64    
65     int qsamplerInstrument::program (void) const
66     {
67     return m_iProgram;
68     }
69    
70    
71     void qsamplerInstrument::setName ( const QString& sName )
72     {
73     m_sName = sName;
74     }
75    
76     const QString& qsamplerInstrument::name (void) const
77     {
78     return m_sName;
79     }
80    
81    
82     void qsamplerInstrument::setEngineName ( const QString& sEngineName )
83     {
84     m_sEngineName = sEngineName;
85     }
86    
87     const QString& qsamplerInstrument::engineName (void) const
88     {
89     return m_sEngineName;
90     }
91    
92    
93     void qsamplerInstrument::setInstrumentFile ( const QString& sInstrumentFile )
94     {
95     m_sInstrumentFile = sInstrumentFile;
96     }
97    
98     const QString& qsamplerInstrument::instrumentFile (void) const
99     {
100     return m_sInstrumentFile;
101     }
102    
103    
104     const QString& qsamplerInstrument::instrumentName (void) const
105     {
106     return m_sInstrumentName;
107     }
108    
109    
110     void qsamplerInstrument::setInstrumentNr ( int iInstrumentNr )
111     {
112     m_iInstrumentNr = iInstrumentNr;
113     }
114    
115     int qsamplerInstrument::instrumentNr (void) const
116     {
117     return m_iInstrumentNr;
118     }
119    
120    
121     void qsamplerInstrument::setVolume ( float fVolume )
122     {
123     m_fVolume = fVolume;
124     }
125    
126     float qsamplerInstrument::volume (void) const
127     {
128     return m_fVolume;
129     }
130    
131    
132     void qsamplerInstrument::setLoadMode ( int iLoadMode )
133     {
134     m_iLoadMode = iLoadMode;
135     }
136    
137     int qsamplerInstrument::loadMode (void) const
138     {
139     return m_iLoadMode;
140     }
141    
142    
143     // Sync methods.
144     bool qsamplerInstrument::map (void)
145     {
146     #ifdef CONFIG_MIDI_INSTRUMENT
147    
148     qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
149     if (pMainForm == NULL)
150     return false;
151     if (pMainForm->client() == NULL)
152     return false;
153    
154     if (m_iBank < 0 || m_iProgram < 0)
155     return false;
156    
157     lscp_midi_instrument_t instr;
158    
159     instr.bank_msb = (m_iBank & 0x3f80) >> 7;
160     instr.bank_lsb = (m_iBank & 0x7f);
161     instr.program = (m_iProgram & 0x7f);
162    
163     lscp_load_mode_t load_mode;
164     switch (m_iLoadMode) {
165     case 3:
166     load_mode = LSCP_LOAD_PERSISTENT;
167     break;
168     case 2:
169     load_mode = LSCP_LOAD_ON_DEMAND_HOLD;
170     break;
171     case 1:
172     load_mode = LSCP_LOAD_ON_DEMAND;
173     break;
174     case 0:
175     default:
176     load_mode = LSCP_LOAD_DEFAULT;
177     break;
178     }
179    
180     if (::lscp_map_midi_instrument(pMainForm->client(), &instr,
181     m_sEngineName.latin1(),
182     m_sInstrumentFile.latin1(),
183     m_iInstrumentNr,
184     m_fVolume,
185     load_mode,
186     m_sName.latin1()) != LSCP_OK) {
187     pMainForm->appendMessagesClient("lscp_map_midi_instrument");
188     return false;
189     }
190    
191     return true;
192    
193     #else
194    
195     return false;
196    
197     #endif
198     }
199    
200    
201     bool qsamplerInstrument::unmap (void)
202     {
203     #ifdef CONFIG_MIDI_INSTRUMENT
204    
205     if (m_iBank < 0 || m_iProgram < 0)
206     return false;
207    
208     qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
209     if (pMainForm == NULL)
210     return false;
211     if (pMainForm->client() == NULL)
212     return false;
213    
214     lscp_midi_instrument_t instr;
215    
216     instr.bank_msb = (m_iBank & 0x3f80) >> 7;
217     instr.bank_lsb = (m_iBank & 0x7f);
218     instr.program = (m_iProgram & 0x7f);
219    
220     if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) {
221     pMainForm->appendMessagesClient("lscp_unmap_midi_instrument");
222     return false;
223     }
224    
225     return true;
226    
227     #else
228    
229     return false;
230    
231     #endif
232     }
233    
234    
235     bool qsamplerInstrument::get (void)
236     {
237     #ifdef CONFIG_MIDI_INSTRUMENT
238    
239     if (m_iBank < 0 || m_iProgram < 0)
240     return false;
241    
242     qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
243     if (pMainForm == NULL)
244     return false;
245     if (pMainForm->client() == NULL)
246     return false;
247    
248     lscp_midi_instrument_t instr;
249    
250     instr.bank_msb = (m_iBank & 0x3f80) >> 7;
251     instr.bank_lsb = (m_iBank & 0x7f);
252     instr.program = (m_iProgram & 0x7f);
253    
254     lscp_midi_instrument_info_t *pInstrInfo
255     = ::lscp_get_midi_instrument_info(pMainForm->client(), &instr);
256     if (pInstrInfo == NULL) {
257     pMainForm->appendMessagesClient("lscp_get_midi_instrument_info");
258     return false;
259     }
260    
261     m_sName = pInstrInfo->name;
262     m_sEngineName = pInstrInfo->engine_name;
263     m_sInstrumentName = pInstrInfo->instrument_name;
264     m_sInstrumentFile = pInstrInfo->instrument_file;
265     m_iInstrumentNr = pInstrInfo->instrument_nr;
266     m_fVolume = pInstrInfo->volume;
267    
268     switch (pInstrInfo->load_mode) {
269     case LSCP_LOAD_PERSISTENT:
270     m_iLoadMode = 3;
271     break;
272     case LSCP_LOAD_ON_DEMAND_HOLD:
273     m_iLoadMode = 2;
274     break;
275     case LSCP_LOAD_ON_DEMAND:
276     m_iLoadMode = 1;
277     break;
278     case LSCP_LOAD_DEFAULT:
279     default:
280     m_iLoadMode = 0;
281     break;
282     }
283    
284     // Fix something.
285     if (m_sName.isEmpty())
286     m_sName = m_sInstrumentName;
287    
288     return true;
289    
290     #else
291    
292     return false;
293    
294     #endif
295     }
296    
297    
298     // end of qsamplerInstrument.cpp

  ViewVC Help
Powered by ViewVC