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

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

  ViewVC Help
Powered by ViewVC