/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInstrumentMapper.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/drivers/midi/MidiInstrumentMapper.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1762 by iliev, Tue Aug 12 16:18:59 2008 UTC revision 1763 by iliev, Wed Sep 3 17:18:51 2008 UTC
# Line 186  namespace LinuxSampler { Line 186  namespace LinuxSampler {
186          }          }
187      }      }
188    
189        void MidiInstrumentMapper::SetLoadMode(entry_t* pEntry) {
190            Engine* pEngine = EngineFactory::Create(pEntry->EngineName);
191            if (!pEngine) { // invalid mapping
192                throw Exception("Invalid mapping");
193            }
194    
195            InstrumentManager* pManager = pEngine->GetInstrumentManager();
196            if (pManager) { // engine provides an InstrumentManager
197                InstrumentManager::instrument_id_t id;
198                id.FileName = pEntry->InstrumentFile;
199                id.Index    = pEntry->InstrumentIndex;
200                pEntry->LoadMode = static_cast<mode_t>(pManager->GetMode(id));
201            } else { // engine does not provide an InstrumentManager
202                // use default value
203                pEntry->LoadMode = ON_DEMAND;
204            }
205    
206            EngineFactory::Destroy(pEngine);
207        }
208    
209        MidiInstrumentMapper::entry_t MidiInstrumentMapper::GetEntry(int Map, uint MidiBank, uint MidiProg) {
210            midiMapsMutex.Lock();
211            std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.find(Map);
212            if (iterMap == midiMaps.end()) { // no such map
213                midiMapsMutex.Unlock();
214                throw Exception("There is no MIDI instrument map " + ToString(Map));
215            }
216    
217            midi_prog_index_t idx;
218            idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
219            idx.midi_bank_lsb = MidiBank & 0x7f;
220            idx.midi_prog     = MidiProg;
221    
222            std::map<midi_prog_index_t,private_entry_t>::iterator iterEntry = iterMap->second.find(idx);
223            if (iterEntry == iterMap->second.end()) {
224                midiMapsMutex.Unlock();
225                throw Exception("There is no map entry with that index");
226            }
227    
228            entry_t entry;
229            entry.EngineName      = iterEntry->second.EngineName;
230            entry.InstrumentFile  = iterEntry->second.InstrumentFile;
231            entry.InstrumentIndex = iterEntry->second.InstrumentIndex;
232            entry.Volume          = iterEntry->second.Volume;
233            entry.Name            = iterEntry->second.Name;
234    
235            try {
236                SetLoadMode(&entry);
237            } catch(Exception e) {
238                midiMapsMutex.Unlock();
239                throw e;
240            }
241    
242            midiMapsMutex.Unlock();
243            
244            return entry;
245        }
246    
247      void MidiInstrumentMapper::RemoveEntry(int Map, midi_prog_index_t Index) {      void MidiInstrumentMapper::RemoveEntry(int Map, midi_prog_index_t Index) {
248          int InstrCount = -1;          int InstrCount = -1;
249    
# Line 245  namespace LinuxSampler { Line 303  namespace LinuxSampler {
303          for (std::map<midi_prog_index_t,entry_t>::iterator iter = result.begin();          for (std::map<midi_prog_index_t,entry_t>::iterator iter = result.begin();
304               iter != result.end(); iter++)               iter != result.end(); iter++)
305          {          {
306              entry_t& entry = iter->second;              try {
307              Engine* pEngine = EngineFactory::Create(entry.EngineName);                  SetLoadMode(&(iter->second));
308              if (!pEngine) { // invalid mapping              } catch(Exception e) {
309                  RemoveEntry(Map, iter->first);                  RemoveEntry(Map, iter->first);
310                  result.erase(iter);                  result.erase(iter);
                 continue;  
             }  
             InstrumentManager* pManager = pEngine->GetInstrumentManager();  
             if (pManager) { // engine provides an InstrumentManager  
                 InstrumentManager::instrument_id_t id;  
                 id.FileName = entry.InstrumentFile;  
                 id.Index    = entry.InstrumentIndex;  
                 entry.LoadMode = static_cast<mode_t>(pManager->GetMode(id));  
             } else { // engine does not provide an InstrumentManager  
                 // use default value  
                 entry.LoadMode = ON_DEMAND;  
311              }              }
             EngineFactory::Destroy(pEngine);  
312          }          }
313          return result;          return result;
314      }      }
# Line 286  namespace LinuxSampler { Line 332  namespace LinuxSampler {
332          return i;          return i;
333      }      }
334    
335        int MidiInstrumentMapper::GetInstrumentCount(int Map) {
336            midiMapsMutex.Lock();
337            std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.find(Map);
338            if (iterMap == midiMaps.end()) { // no such map
339                midiMapsMutex.Unlock();
340                throw Exception("There is no MIDI instrument map " + ToString(Map));
341            }
342    
343            int i = iterMap->second.size();
344            midiMapsMutex.Unlock();
345            return i;
346        }
347    
348        int MidiInstrumentMapper::GetInstrumentCount() {
349            int count = 0;
350    
351            midiMapsMutex.Lock();
352            std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.begin();
353            for (;iterMap != midiMaps.end(); iterMap++) {
354                count += iterMap->second.size();
355            }
356            midiMapsMutex.Unlock();
357    
358            return count;
359        }
360    
361      int MidiInstrumentMapper::AddMap(String MapName) throw (Exception) {      int MidiInstrumentMapper::AddMap(String MapName) throw (Exception) {
362          int ID;          int ID;
363          midiMapsMutex.Lock();          midiMapsMutex.Lock();

Legend:
Removed from v.1762  
changed lines
  Added in v.1763

  ViewVC Help
Powered by ViewVC