/[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 964 by capela, Mon Dec 4 17:06:04 2006 UTC revision 1464 by capela, Thu Nov 1 17:14:21 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    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 19  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerUtilities.h"
24  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
25  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
26    
27  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
28    
29    using namespace QSampler;
30    
31  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
32  // qsamplerInstrument - MIDI instrument map structure.  // qsamplerInstrument - MIDI instrument map structure.
33  //  //
34    
35  // Constructor.  // Constructor.
36  qsamplerInstrument::qsamplerInstrument ( int iBank, int iProgram )  qsamplerInstrument::qsamplerInstrument ( int iMap, int iBank, int iProg )
37  {  {
38            m_iMap          = iMap;
39          m_iBank         = iBank;          m_iBank         = iBank;
40          m_iProgram      = iProgram;          m_iProg         = iProg;
41          m_iInstrumentNr = 0;;          m_iInstrumentNr = 0;;
42          m_fVolume       = 1.0f;          m_fVolume       = 1.0f;
43          m_iLoadMode     = 0;          m_iLoadMode     = 0;
# Line 46  qsamplerInstrument::~qsamplerInstrument Line 50  qsamplerInstrument::~qsamplerInstrument
50    
51    
52  // Instrument accessors.  // Instrument accessors.
53    void qsamplerInstrument::setMap ( int iMap )
54    {
55            m_iMap = iMap;
56    }
57    
58    int qsamplerInstrument::map (void) const
59    {
60            return m_iMap;
61    }
62    
63    
64  void qsamplerInstrument::setBank ( int iBank )  void qsamplerInstrument::setBank ( int iBank )
65  {  {
66          m_iBank = iBank;          m_iBank = iBank;
# Line 57  int qsamplerInstrument::bank (void) cons Line 72  int qsamplerInstrument::bank (void) cons
72  }  }
73    
74    
75  void qsamplerInstrument::setProgram ( int iProgram )  void qsamplerInstrument::setProg ( int iProg )
76  {  {
77          m_iProgram = iProgram;          m_iProg = iProg;
78  }  }
79    
80  int qsamplerInstrument::program (void) const  int qsamplerInstrument::prog (void) const
81  {  {
82          return m_iProgram;          return m_iProg;
83  }  }
84    
85    
# Line 141  int qsamplerInstrument::loadMode (void) Line 156  int qsamplerInstrument::loadMode (void)
156    
157    
158  // Sync methods.  // Sync methods.
159  bool qsamplerInstrument::map (void)  bool qsamplerInstrument::mapInstrument (void)
160  {  {
161  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
162    
163          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
164          if (pMainForm == NULL)          if (pMainForm == NULL)
165                  return false;                  return false;
166          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
167                  return false;                  return false;
168    
169          if (m_iBank < 0 || m_iProgram < 0)          if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
170                  return false;                  return false;
171    
172          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
173    
174          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.map  = m_iMap;
175          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank = (m_iBank & 0x0fff);
176          instr.program  = (m_iProgram & 0x7f);          instr.prog = (m_iProg & 0x7f);
177    
178          lscp_load_mode_t load_mode;          lscp_load_mode_t load_mode;
179          switch (m_iLoadMode) {          switch (m_iLoadMode) {
# Line 178  bool qsamplerInstrument::map (void) Line 193  bool qsamplerInstrument::map (void)
193          }          }
194    
195          if (::lscp_map_midi_instrument(pMainForm->client(), &instr,          if (::lscp_map_midi_instrument(pMainForm->client(), &instr,
196                  m_sEngineName.latin1(),                          m_sEngineName.latin1(),
197                  m_sInstrumentFile.latin1(),                          qsamplerUtilities::lscpEscapePath(m_sInstrumentFile).latin1(),
198                  m_iInstrumentNr,                          m_iInstrumentNr,
199                  m_fVolume,                          m_fVolume,
200                  load_mode,                          load_mode,
201                  m_sName.latin1()) != LSCP_OK) {                          m_sName.latin1()) != LSCP_OK) {
202                  pMainForm->appendMessagesClient("lscp_map_midi_instrument");                  pMainForm->appendMessagesClient("lscp_map_midi_instrument");
203                  return false;                  return false;
204          }          }
# Line 198  bool qsamplerInstrument::map (void) Line 213  bool qsamplerInstrument::map (void)
213  }  }
214    
215    
216  bool qsamplerInstrument::unmap (void)  bool qsamplerInstrument::unmapInstrument (void)
217  {  {
218  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
219    
220          if (m_iBank < 0 || m_iProgram < 0)          if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
221                  return false;                  return false;
222    
223          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
224          if (pMainForm == NULL)          if (pMainForm == NULL)
225                  return false;                  return false;
226          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 213  bool qsamplerInstrument::unmap (void) Line 228  bool qsamplerInstrument::unmap (void)
228    
229          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
230    
231          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.map  = m_iMap;
232          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank = (m_iBank & 0x0fff);
233          instr.program  = (m_iProgram & 0x7f);          instr.prog = (m_iProg & 0x7f);
234    
235          if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) {          if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) {
236                  pMainForm->appendMessagesClient("lscp_unmap_midi_instrument");                  pMainForm->appendMessagesClient("lscp_unmap_midi_instrument");
# Line 232  bool qsamplerInstrument::unmap (void) Line 247  bool qsamplerInstrument::unmap (void)
247  }  }
248    
249    
250  bool qsamplerInstrument::get (void)  bool qsamplerInstrument::getInstrument (void)
251  {  {
252  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
253    
254          if (m_iBank < 0 || m_iProgram < 0)          if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
255                  return false;                  return false;
256    
257          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
258          if (pMainForm == NULL)          if (pMainForm == NULL)
259                  return false;                  return false;
260          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 247  bool qsamplerInstrument::get (void) Line 262  bool qsamplerInstrument::get (void)
262    
263          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
264    
265          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.map  = m_iMap;
266          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank = (m_iBank & 0x0fff);
267          instr.program  = (m_iProgram & 0x7f);          instr.prog = (m_iProg & 0x7f);
268    
269          lscp_midi_instrument_info_t *pInstrInfo          lscp_midi_instrument_info_t *pInstrInfo
270                  = ::lscp_get_midi_instrument_info(pMainForm->client(), &instr);                  = ::lscp_get_midi_instrument_info(pMainForm->client(), &instr);
# Line 258  bool qsamplerInstrument::get (void) Line 273  bool qsamplerInstrument::get (void)
273                  return false;                  return false;
274          }          }
275    
276          m_sName           = pInstrInfo->name;          m_sName           = qsamplerUtilities::lscpEscapedTextToRaw(pInstrInfo->name);
277          m_sEngineName     = pInstrInfo->engine_name;          m_sEngineName     = pInstrInfo->engine_name;
278          m_sInstrumentName = pInstrInfo->instrument_name;          m_sInstrumentName = qsamplerUtilities::lscpEscapedTextToRaw(pInstrInfo->instrument_name);
279          m_sInstrumentFile = pInstrInfo->instrument_file;          m_sInstrumentFile = qsamplerUtilities::lscpEscapedPathToPosix(pInstrInfo->instrument_file);
280          m_iInstrumentNr   = pInstrInfo->instrument_nr;          m_iInstrumentNr   = pInstrInfo->instrument_nr;
281          m_fVolume         = pInstrInfo->volume;          m_fVolume         = pInstrInfo->volume;
282    
# Line 295  bool qsamplerInstrument::get (void) Line 310  bool qsamplerInstrument::get (void)
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  // end of qsamplerInstrument.cpp

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

  ViewVC Help
Powered by ViewVC