/[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 1523 by capela, Sun Nov 25 11:40:47 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 21  Line 22 
22    
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
25    #include "qsamplerUtilities.h"
26    
27    #include "qsamplerOptions.h"
28  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
29    
30    
31    using namespace QSampler;
32    
33  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
34  // qsamplerInstrument - MIDI instrument map structure.  // qsamplerInstrument - MIDI instrument map structure.
35  //  //
36    
37  // Constructor.  // Constructor.
38  qsamplerInstrument::qsamplerInstrument ( int iBank, int iProgram )  qsamplerInstrument::qsamplerInstrument ( int iMap, int iBank, int iProg )
39  {  {
40            m_iMap          = iMap;
41          m_iBank         = iBank;          m_iBank         = iBank;
42          m_iProgram      = iProgram;          m_iProg         = iProg;
43          m_iInstrumentNr = 0;;          m_iInstrumentNr = 0;
44          m_fVolume       = 1.0f;          m_fVolume       = 1.0f;
45          m_iLoadMode     = 0;          m_iLoadMode     = 0;
46  }  }
# Line 46  qsamplerInstrument::~qsamplerInstrument Line 52  qsamplerInstrument::~qsamplerInstrument
52    
53    
54  // Instrument accessors.  // Instrument accessors.
55    void qsamplerInstrument::setMap ( int iMap )
56    {
57            m_iMap = iMap;
58    }
59    
60    int qsamplerInstrument::map (void) const
61    {
62            return m_iMap;
63    }
64    
65    
66  void qsamplerInstrument::setBank ( int iBank )  void qsamplerInstrument::setBank ( int iBank )
67  {  {
68          m_iBank = iBank;          m_iBank = iBank;
# Line 57  int qsamplerInstrument::bank (void) cons Line 74  int qsamplerInstrument::bank (void) cons
74  }  }
75    
76    
77  void qsamplerInstrument::setProgram ( int iProgram )  void qsamplerInstrument::setProg ( int iProg )
78  {  {
79          m_iProgram = iProgram;          m_iProg = iProg;
80  }  }
81    
82  int qsamplerInstrument::program (void) const  int qsamplerInstrument::prog (void) const
83  {  {
84          return m_iProgram;          return m_iProg;
85  }  }
86    
87    
# Line 141  int qsamplerInstrument::loadMode (void) Line 158  int qsamplerInstrument::loadMode (void)
158    
159    
160  // Sync methods.  // Sync methods.
161  bool qsamplerInstrument::map (void)  bool qsamplerInstrument::mapInstrument (void)
162  {  {
163  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
164    
165          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
166          if (pMainForm == NULL)          if (pMainForm == NULL)
167                  return false;                  return false;
168          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
169                  return false;                  return false;
170    
171          if (m_iBank < 0 || m_iProgram < 0)          if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
172                  return false;                  return false;
173    
174          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
175    
176          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.map  = m_iMap;
177          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank = (m_iBank & 0x0fff);
178          instr.program  = (m_iProgram & 0x7f);          instr.prog = (m_iProg & 0x7f);
179    
180          lscp_load_mode_t load_mode;          lscp_load_mode_t load_mode;
181          switch (m_iLoadMode) {          switch (m_iLoadMode) {
# Line 178  bool qsamplerInstrument::map (void) Line 195  bool qsamplerInstrument::map (void)
195          }          }
196    
197          if (::lscp_map_midi_instrument(pMainForm->client(), &instr,          if (::lscp_map_midi_instrument(pMainForm->client(), &instr,
198                  m_sEngineName.latin1(),                          m_sEngineName.toUtf8().constData(),
199                  m_sInstrumentFile.latin1(),                          qsamplerUtilities::lscpEscapePath(
200                  m_iInstrumentNr,                                  m_sInstrumentFile).toUtf8().constData(),
201                  m_fVolume,                          m_iInstrumentNr, m_fVolume, load_mode,
202                  load_mode,                          m_sName.toUtf8().constData()) != LSCP_OK) {
                 m_sName.latin1()) != LSCP_OK) {  
203                  pMainForm->appendMessagesClient("lscp_map_midi_instrument");                  pMainForm->appendMessagesClient("lscp_map_midi_instrument");
204                  return false;                  return false;
205          }          }
# Line 198  bool qsamplerInstrument::map (void) Line 214  bool qsamplerInstrument::map (void)
214  }  }
215    
216    
217  bool qsamplerInstrument::unmap (void)  bool qsamplerInstrument::unmapInstrument (void)
218  {  {
219  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
220    
221          if (m_iBank < 0 || m_iProgram < 0)          if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
222                  return false;                  return false;
223    
224          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
225          if (pMainForm == NULL)          if (pMainForm == NULL)
226                  return false;                  return false;
227          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 213  bool qsamplerInstrument::unmap (void) Line 229  bool qsamplerInstrument::unmap (void)
229    
230          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
231    
232          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.map  = m_iMap;
233          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank = (m_iBank & 0x0fff);
234          instr.program  = (m_iProgram & 0x7f);          instr.prog = (m_iProg & 0x7f);
235    
236          if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) {          if (::lscp_unmap_midi_instrument(pMainForm->client(), &instr) != LSCP_OK) {
237                  pMainForm->appendMessagesClient("lscp_unmap_midi_instrument");                  pMainForm->appendMessagesClient("lscp_unmap_midi_instrument");
# Line 232  bool qsamplerInstrument::unmap (void) Line 248  bool qsamplerInstrument::unmap (void)
248  }  }
249    
250    
251  bool qsamplerInstrument::get (void)  bool qsamplerInstrument::getInstrument (void)
252  {  {
253  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
254    
255          if (m_iBank < 0 || m_iProgram < 0)          if (m_iMap < 0 || m_iBank < 0 || m_iProg < 0)
256                  return false;                  return false;
257    
258          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
259          if (pMainForm == NULL)          if (pMainForm == NULL)
260                  return false;                  return false;
261          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 247  bool qsamplerInstrument::get (void) Line 263  bool qsamplerInstrument::get (void)
263    
264          lscp_midi_instrument_t instr;          lscp_midi_instrument_t instr;
265    
266          instr.bank_msb = (m_iBank & 0x3f80) >> 7;          instr.map  = m_iMap;
267          instr.bank_lsb = (m_iBank & 0x7f);          instr.bank = (m_iBank & 0x0fff);
268          instr.program  = (m_iProgram & 0x7f);          instr.prog = (m_iProg & 0x7f);
269    
270          lscp_midi_instrument_info_t *pInstrInfo          lscp_midi_instrument_info_t *pInstrInfo
271                  = ::lscp_get_midi_instrument_info(pMainForm->client(), &instr);                  = ::lscp_get_midi_instrument_info(pMainForm->client(), &instr);
# Line 258  bool qsamplerInstrument::get (void) Line 274  bool qsamplerInstrument::get (void)
274                  return false;                  return false;
275          }          }
276    
277          m_sName           = pInstrInfo->name;          m_sName = qsamplerUtilities::lscpEscapedTextToRaw(pInstrInfo->name);
278          m_sEngineName     = pInstrInfo->engine_name;          m_sEngineName = pInstrInfo->engine_name;
279          m_sInstrumentName = pInstrInfo->instrument_name;          m_sInstrumentName = qsamplerUtilities::lscpEscapedTextToRaw(
280          m_sInstrumentFile = pInstrInfo->instrument_file;                  pInstrInfo->instrument_name);
281          m_iInstrumentNr   = pInstrInfo->instrument_nr;          m_sInstrumentFile = qsamplerUtilities::lscpEscapedPathToPosix(
282          m_fVolume         = pInstrInfo->volume;                  pInstrInfo->instrument_file);
283            m_iInstrumentNr = pInstrInfo->instrument_nr;
284            m_fVolume = pInstrInfo->volume;
285    
286          switch (pInstrInfo->load_mode) {          switch (pInstrInfo->load_mode) {
287                  case LSCP_LOAD_PERSISTENT:                  case LSCP_LOAD_PERSISTENT:
# Line 295  bool qsamplerInstrument::get (void) Line 313  bool qsamplerInstrument::get (void)
313  }  }
314    
315    
316    // Instrument map name enumerator.
317    QStringList qsamplerInstrument::getMapNames (void)
318    {
319            QStringList maps;
320    
321            MainForm *pMainForm = MainForm::getInstance();
322            if (pMainForm == NULL)
323                    return maps;
324            if (pMainForm->client() == NULL)
325                    return maps;
326    
327    #ifdef CONFIG_MIDI_INSTRUMENT
328            int *piMaps = ::lscp_list_midi_instrument_maps(pMainForm->client());
329            if (piMaps == NULL) {
330                    if (::lscp_client_get_errno(pMainForm->client()))
331                            pMainForm->appendMessagesClient("lscp_list_midi_instruments");
332            } else {
333                    for (int iMap = 0; piMaps[iMap] >= 0; iMap++) {
334                            const QString& sMapName = getMapName(piMaps[iMap]);
335                            if (!sMapName.isEmpty())
336                                    maps.append(sMapName);
337                    }
338            }
339    #endif
340    
341            return maps;
342    }
343    
344    // Instrument map name enumerator.
345    QString qsamplerInstrument::getMapName ( int iMidiMap )
346    {
347            QString sMapName;
348    
349            MainForm *pMainForm = MainForm::getInstance();
350            if (pMainForm == NULL)
351                    return sMapName;
352            if (pMainForm->client() == NULL)
353                    return sMapName;
354    
355    #ifdef CONFIG_MIDI_INSTRUMENT
356            const char *pszMapName
357                    = ::lscp_get_midi_instrument_map_name(pMainForm->client(), iMidiMap);
358            if (pszMapName == NULL) {
359                    pszMapName = " -";
360                    if (::lscp_client_get_errno(pMainForm->client()))
361                            pMainForm->appendMessagesClient("lscp_get_midi_instrument_name");
362            }
363            sMapName = QString("%1 - %2").arg(iMidiMap)
364                    .arg(qsamplerUtilities::lscpEscapedTextToRaw(pszMapName));
365    #endif
366    
367            return sMapName;
368    }
369    
370    
371  // end of qsamplerInstrument.cpp  // end of qsamplerInstrument.cpp

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

  ViewVC Help
Powered by ViewVC