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

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

  ViewVC Help
Powered by ViewVC