/[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 1130 by iliev, Sun Mar 25 18:59:14 2007 UTC revision 1481 by senoner, Wed Nov 14 23:42:15 2007 UTC
# Line 20  Line 20 
20    
21  #include "MidiInstrumentMapper.h"  #include "MidiInstrumentMapper.h"
22    
23    #include "../../common/global_private.h"
24  #include "../../common/Mutex.h"  #include "../../common/Mutex.h"
25  #include "../../engines/EngineFactory.h"  #include "../../engines/EngineFactory.h"
26  #include "../../engines/Engine.h"  #include "../../engines/Engine.h"
# Line 47  namespace LinuxSampler { Line 48  namespace LinuxSampler {
48      // for synchronization of midiMaps      // for synchronization of midiMaps
49      Mutex midiMapsMutex;      Mutex midiMapsMutex;
50    
   
51      ListenerList<MidiInstrumentCountListener*> MidiInstrumentMapper::llMidiInstrumentCountListeners;      ListenerList<MidiInstrumentCountListener*> MidiInstrumentMapper::llMidiInstrumentCountListeners;
52      ListenerList<MidiInstrumentInfoListener*> MidiInstrumentMapper::llMidiInstrumentInfoListeners;      ListenerList<MidiInstrumentInfoListener*> MidiInstrumentMapper::llMidiInstrumentInfoListeners;
53      ListenerList<MidiInstrumentMapCountListener*> MidiInstrumentMapper::llMidiInstrumentMapCountListeners;      ListenerList<MidiInstrumentMapCountListener*> MidiInstrumentMapper::llMidiInstrumentMapCountListeners;
54      ListenerList<MidiInstrumentMapInfoListener*> MidiInstrumentMapper::llMidiInstrumentMapInfoListeners;      ListenerList<MidiInstrumentMapInfoListener*> MidiInstrumentMapper::llMidiInstrumentMapInfoListeners;
55        int MidiInstrumentMapper::DefaultMap;
56            
57      void MidiInstrumentMapper::AddMidiInstrumentCountListener(MidiInstrumentCountListener* l) {      void MidiInstrumentMapper::AddMidiInstrumentCountListener(MidiInstrumentCountListener* l) {
58          llMidiInstrumentCountListeners.AddListener(l);          llMidiInstrumentCountListeners.AddListener(l);
# Line 144  namespace LinuxSampler { Line 145  namespace LinuxSampler {
145              InstrumentManager::instrument_id_t id;              InstrumentManager::instrument_id_t id;
146              id.FileName = Entry.InstrumentFile;              id.FileName = Entry.InstrumentFile;
147              id.Index    = Entry.InstrumentIndex;              id.Index    = Entry.InstrumentIndex;
148              if (Entry.LoadMode != VOID) {              if (Entry.LoadMode != DONTCARE) {
149                  if (bInBackground)                  if (bInBackground)
150                      pEngine->GetInstrumentManager()->SetModeInBackground(id, static_cast<InstrumentManager::mode_t>(Entry.LoadMode));                      pEngine->GetInstrumentManager()->SetModeInBackground(id, static_cast<InstrumentManager::mode_t>(Entry.LoadMode));
151                  else                  else
# Line 278  namespace LinuxSampler { Line 279  namespace LinuxSampler {
279          return result;          return result;
280      }      }
281    
282        int MidiInstrumentMapper::GetMapCount() {
283            midiMapsMutex.Lock();
284            int i = midiMaps.size();
285            midiMapsMutex.Unlock();
286            return i;
287        }
288    
289      int MidiInstrumentMapper::AddMap(String MapName) throw (Exception) {      int MidiInstrumentMapper::AddMap(String MapName) throw (Exception) {
290          int ID;          int ID;
291          midiMapsMutex.Lock();          midiMapsMutex.Lock();
# Line 300  namespace LinuxSampler { Line 308  namespace LinuxSampler {
308          }          }
309          __create_map:          __create_map:
310          midiMaps[ID].name = MapName;          midiMaps[ID].name = MapName;
311          midiMapsMutex.Unlock();          
   
312          fireMidiInstrumentMapCountChanged(Maps().size());          fireMidiInstrumentMapCountChanged(Maps().size());
313            // If there were no maps until now we must set a default map.
314            if (midiMaps.size() == 1) SetDefaultMap(ID);
315            midiMapsMutex.Unlock();
316            
317          return ID;          return ID;
318      }      }
319    
# Line 334  namespace LinuxSampler { Line 345  namespace LinuxSampler {
345      void MidiInstrumentMapper::RemoveMap(int Map) {      void MidiInstrumentMapper::RemoveMap(int Map) {
346          midiMapsMutex.Lock();          midiMapsMutex.Lock();
347          midiMaps.erase(Map);          midiMaps.erase(Map);
348          midiMapsMutex.Unlock();          if(Map == GetDefaultMap()) {
349                SetDefaultMap(midiMaps.empty() ? -1 : (*(midiMaps.begin())).first);
350            }
351          fireMidiInstrumentMapCountChanged(Maps().size());          fireMidiInstrumentMapCountChanged(Maps().size());
352            midiMapsMutex.Unlock();
353      }      }
354    
355      void MidiInstrumentMapper::RemoveAllMaps() {      void MidiInstrumentMapper::RemoveAllMaps() {
356          midiMapsMutex.Lock();          midiMapsMutex.Lock();
357          midiMaps.clear();          midiMaps.clear();
358          midiMapsMutex.Unlock();          SetDefaultMap(-1);
359          fireMidiInstrumentMapCountChanged(Maps().size());          fireMidiInstrumentMapCountChanged(Maps().size());
360            midiMapsMutex.Unlock();
361        }
362    
363        int MidiInstrumentMapper::GetDefaultMap() {
364            midiMapsMutex.Lock();
365            int i = DefaultMap;
366            midiMapsMutex.Unlock();
367            return i;
368        }
369    
370        void MidiInstrumentMapper::SetDefaultMap(int MapId) {
371            midiMapsMutex.Lock();
372            DefaultMap = MapId;
373            midiMapsMutex.Unlock();
374            
375            if (MapId != -1) fireMidiInstrumentMapInfoChanged(MapId);
376      }      }
377    
378      optional<MidiInstrumentMapper::entry_t> MidiInstrumentMapper::GetEntry(int Map, midi_prog_index_t Index) {      optional<MidiInstrumentMapper::entry_t> MidiInstrumentMapper::GetEntry(int Map, midi_prog_index_t Index) {

Legend:
Removed from v.1130  
changed lines
  Added in v.1481

  ViewVC Help
Powered by ViewVC