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

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

  ViewVC Help
Powered by ViewVC