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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 962 by capela, Sun Dec 3 18:27:23 2006 UTC revision 964 by capela, Mon Dec 4 17:06:04 2006 UTC
# Line 1  Line 1 
1  // qsamplerInstrument.cpp  // qsamplerInstrument.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.     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     This program is free software; you can redistribute it and/or
7     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
8     as published by the Free Software Foundation; either version 2     as published by the Free Software Foundation; either version 2
9     of the License, or (at your option) any later version.     of the License, or (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License along     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.,     with this program; if not, write to the Free Software Foundation, Inc.,
18     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19    
20  *****************************************************************************/  *****************************************************************************/
21    
22  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
23  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
24    
25  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
26    
27    
28  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
29  // qsamplerInstrument - MIDI instrument map structure.  // qsamplerInstrument - MIDI instrument map structure.
30  //  //
31    
32  // Constructor.  // Constructor.
33  qsamplerInstrument::qsamplerInstrument ( int iBank, int iProgram )  qsamplerInstrument::qsamplerInstrument ( int iBank, int iProgram )
34  {  {
35          m_iBank         = iBank;          m_iBank         = iBank;
36          m_iProgram      = iProgram;          m_iProgram      = iProgram;
37          m_iInstrumentNr = 0;;          m_iInstrumentNr = 0;;
38          m_fVolume       = 1.0f;          m_fVolume       = 1.0f;
39          m_iLoadMode     = 0;          m_iLoadMode     = 0;
40  }  }
41    
42  // Default destructor.  // Default destructor.
43  qsamplerInstrument::~qsamplerInstrument (void)  qsamplerInstrument::~qsamplerInstrument (void)
44  {  {
45  }  }
46    
47    
48  // Instrument accessors.  // Instrument accessors.
49  void qsamplerInstrument::setBank ( int iBank )  void qsamplerInstrument::setBank ( int iBank )
50  {  {
51          m_iBank = iBank;          m_iBank = iBank;
52  }  }
53    
54  int qsamplerInstrument::bank (void) const  int qsamplerInstrument::bank (void) const
55  {  {
56          return m_iBank;          return m_iBank;
57  }  }
58    
59    
60  void qsamplerInstrument::setProgram ( int iProgram )  void qsamplerInstrument::setProgram ( int iProgram )
61  {  {
62          m_iProgram = iProgram;          m_iProgram = iProgram;
63  }  }
64    
65  int qsamplerInstrument::program (void) const  int qsamplerInstrument::program (void) const
66  {  {
67          return m_iProgram;          return m_iProgram;
68  }  }
69    
70    
71  void qsamplerInstrument::setName ( const QString& sName )  void qsamplerInstrument::setName ( const QString& sName )
72  {  {
73          m_sName = sName;          m_sName = sName;
74  }  }
75    
76  const QString& qsamplerInstrument::name (void) const  const QString& qsamplerInstrument::name (void) const
77  {  {
78          return m_sName;          return m_sName;
79  }  }
80    
81    
82  void qsamplerInstrument::setEngineName ( const QString& sEngineName )  void qsamplerInstrument::setEngineName ( const QString& sEngineName )
83  {  {
84          m_sEngineName = sEngineName;          m_sEngineName = sEngineName;
85  }  }
86    
87  const QString& qsamplerInstrument::engineName (void) const  const QString& qsamplerInstrument::engineName (void) const
88  {  {
89          return m_sEngineName;          return m_sEngineName;
90  }  }
91    
92    
93  void qsamplerInstrument::setInstrumentFile ( const QString& sInstrumentFile )  void qsamplerInstrument::setInstrumentFile ( const QString& sInstrumentFile )
94  {  {
95          m_sInstrumentFile = sInstrumentFile;          m_sInstrumentFile = sInstrumentFile;
96  }  }
97    
98  const QString& qsamplerInstrument::instrumentFile (void) const  const QString& qsamplerInstrument::instrumentFile (void) const
99  {  {
100          return m_sInstrumentFile;          return m_sInstrumentFile;
101  }  }
102    
103    
104  const QString& qsamplerInstrument::instrumentName (void) const  const QString& qsamplerInstrument::instrumentName (void) const
105  {  {
106          return m_sInstrumentName;          return m_sInstrumentName;
107  }  }
108    
109    
110  void qsamplerInstrument::setInstrumentNr ( int iInstrumentNr )  void qsamplerInstrument::setInstrumentNr ( int iInstrumentNr )
111  {  {
112          m_iInstrumentNr = iInstrumentNr;          m_iInstrumentNr = iInstrumentNr;
113  }  }
114    
115  int qsamplerInstrument::instrumentNr (void) const  int qsamplerInstrument::instrumentNr (void) const
116  {  {
117          return m_iInstrumentNr;          return m_iInstrumentNr;
118  }  }
119    
120    
121  void qsamplerInstrument::setVolume ( float fVolume )  void qsamplerInstrument::setVolume ( float fVolume )
122  {  {
123          m_fVolume = fVolume;          m_fVolume = fVolume;
124  }  }
125    
126  float qsamplerInstrument::volume (void) const  float qsamplerInstrument::volume (void) const
127  {  {
128          return m_fVolume;          return m_fVolume;
129  }  }
130    
131    
132  void qsamplerInstrument::setLoadMode ( int iLoadMode )  void qsamplerInstrument::setLoadMode ( int iLoadMode )
133  {  {
134          m_iLoadMode = iLoadMode;          m_iLoadMode = iLoadMode;
135  }  }
136    
137  int qsamplerInstrument::loadMode (void) const  int qsamplerInstrument::loadMode (void) const
138  {  {
139          return m_iLoadMode;          return m_iLoadMode;
140  }  }
141    
142    
143  // Sync methods.  // Sync methods.
144  bool qsamplerInstrument::map (void)  bool qsamplerInstrument::map (void)
145  {  {
146  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
147    
148          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
149          if (pMainForm)          if (pMainForm == NULL)
150                  return false;                  return false;
151          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
152                  return false;                  return false;
153    
154          if (m_iBank < 0 || m_iProgram < 0)          if (m_iBank < 0 || m_iProgram < 0)
155                  return false;                  return false;
156    
157          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
158    
159          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.bank_msb = (m_iBank & 0x3f80) >> 7;
160          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank_lsb = (m_iBank & 0x7f);
161          instr.program  = (m_iProgram & 0x7f);          instr.program  = (m_iProgram & 0x7f);
162    
163          lscp_load_mode_t load_mode;          lscp_load_mode_t load_mode;
164          switch (m_iLoadMode) {          switch (m_iLoadMode) {
165                  case 3:                  case 3:
166                          load_mode = LSCP_LOAD_PERSISTENT;                          load_mode = LSCP_LOAD_PERSISTENT;
167                          break;                          break;
168                  case 2:                  case 2:
169                          load_mode = LSCP_LOAD_ON_DEMAND_HOLD;                          load_mode = LSCP_LOAD_ON_DEMAND_HOLD;
170                          break;                          break;
171                  case 1:                  case 1:
172                          load_mode = LSCP_LOAD_ON_DEMAND;                          load_mode = LSCP_LOAD_ON_DEMAND;
173                          break;                          break;
174                  case 0:                  case 0:
175                  default:                  default:
176                          load_mode = LSCP_LOAD_DEFAULT;                          load_mode = LSCP_LOAD_DEFAULT;
177                          break;                          break;
178          }          }
179    
180          if (::lscp_map_midi_instrument(pMainForm->client(), &instr,          if (::lscp_map_midi_instrument(pMainForm->client(), &instr,
181                  m_sEngineName.latin1(),                  m_sEngineName.latin1(),
182                  m_sInstrumentFile.latin1(),                  m_sInstrumentFile.latin1(),
183                  m_iInstrumentNr,                  m_iInstrumentNr,
184                  m_fVolume,                  m_fVolume,
185                  load_mode,                  load_mode,
186                  m_sName.latin1()) != LSCP_OK) {                  m_sName.latin1()) != LSCP_OK) {
187                  pMainForm->appendMessagesClient("lscp_map_midi_instrument");                  pMainForm->appendMessagesClient("lscp_map_midi_instrument");
188                  return false;                  return false;
189          }          }
190    
191          return true;          return true;
192    
193  #else  #else
194    
195          return false;          return false;
196    
197  #endif  #endif
198  }  }
199    
200    
201  bool qsamplerInstrument::unmap (void)  bool qsamplerInstrument::unmap (void)
202  {  {
203  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
204    
205          if (m_iBank < 0 || m_iProgram < 0)          if (m_iBank < 0 || m_iProgram < 0)
206                  return false;                  return false;
207    
208          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
209          if (pMainForm)          if (pMainForm == NULL)
210                  return false;                  return false;
211          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
212                  return false;                  return false;
213    
214          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
215    
216          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.bank_msb = (m_iBank & 0x3f80) >> 7;
217          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank_lsb = (m_iBank & 0x7f);
218          instr.program  = (m_iProgram & 0x7f);          instr.program  = (m_iProgram & 0x7f);
219    
220          if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) {          if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) {
221                  pMainForm->appendMessagesClient("lscp_unmap_midi_instrument");                  pMainForm->appendMessagesClient("lscp_unmap_midi_instrument");
222                  return false;                  return false;
223          }          }
224    
225          return true;          return true;
226    
227  #else  #else
228    
229          return false;          return false;
230    
231  #endif  #endif
232  }  }
233    
234    
235  bool qsamplerInstrument::get (void)  bool qsamplerInstrument::get (void)
236  {  {
237  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
238    
239          if (m_iBank < 0 || m_iProgram < 0)          if (m_iBank < 0 || m_iProgram < 0)
240                  return false;                  return false;
241    
242          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
243          if (pMainForm)          if (pMainForm == NULL)
244                  return false;                  return false;
245          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
246                  return false;                  return false;
247    
248          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
249    
250          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.bank_msb = (m_iBank & 0x3f80) >> 7;
251          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank_lsb = (m_iBank & 0x7f);
252          instr.program  = (m_iProgram & 0x7f);          instr.program  = (m_iProgram & 0x7f);
253    
254          lscp_midi_instrument_info_t *pInstrInfo          lscp_midi_instrument_info_t *pInstrInfo
255                  = ::lscp_get_midi_instrument_info(pMainForm->client(), &instr);                  = ::lscp_get_midi_instrument_info(pMainForm->client(), &instr);
256          if (pInstrInfo == NULL) {          if (pInstrInfo == NULL) {
257                  pMainForm->appendMessagesClient("lscp_get_midi_instrument_info");                  pMainForm->appendMessagesClient("lscp_get_midi_instrument_info");
258                  return false;                  return false;
259          }          }
260    
261          m_sName           = pInstrInfo->name;          m_sName           = pInstrInfo->name;
262          m_sEngineName     = pInstrInfo->engine_name;          m_sEngineName     = pInstrInfo->engine_name;
263          m_sInstrumentName = pInstrInfo->instrument_name;          m_sInstrumentName = pInstrInfo->instrument_name;
264          m_sInstrumentFile = pInstrInfo->instrument_file;          m_sInstrumentFile = pInstrInfo->instrument_file;
265          m_iInstrumentNr   = pInstrInfo->instrument_nr;          m_iInstrumentNr   = pInstrInfo->instrument_nr;
266          m_fVolume         = pInstrInfo->volume;          m_fVolume         = pInstrInfo->volume;
267    
268          switch (pInstrInfo->load_mode) {          switch (pInstrInfo->load_mode) {
269                  case LSCP_LOAD_PERSISTENT:                  case LSCP_LOAD_PERSISTENT:
270                          m_iLoadMode = 3;                          m_iLoadMode = 3;
271                          break;                          break;
272                  case LSCP_LOAD_ON_DEMAND_HOLD:                  case LSCP_LOAD_ON_DEMAND_HOLD:
273                          m_iLoadMode = 2;                          m_iLoadMode = 2;
274                          break;                          break;
275                  case LSCP_LOAD_ON_DEMAND:                  case LSCP_LOAD_ON_DEMAND:
276                          m_iLoadMode = 1;                          m_iLoadMode = 1;
277                          break;                          break;
278                  case LSCP_LOAD_DEFAULT:                  case LSCP_LOAD_DEFAULT:
279                  default:                  default:
280                          m_iLoadMode = 0;                          m_iLoadMode = 0;
281                          break;                          break;
282          }          }
283    
284          // Fix something.          // Fix something.
285          if (m_sName.isEmpty())          if (m_sName.isEmpty())
286                  m_sName = m_sInstrumentName;                  m_sName = m_sInstrumentName;
287    
288          return true;          return true;
289    
290  #else  #else
291    
292          return false;          return false;
293    
294  #endif  #endif
295  }  }
296    
297    
298  // end of qsamplerInstrument.cpp  // end of qsamplerInstrument.cpp

Legend:
Removed from v.962  
changed lines
  Added in v.964

  ViewVC Help
Powered by ViewVC