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

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

  ViewVC Help
Powered by ViewVC