/[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 980 by iliev, Sun Dec 17 10:43:22 2006 UTC revision 981 by iliev, Sun Dec 17 22:35:01 2006 UTC
# Line 23  Line 23 
23  #include "../../common/Mutex.h"  #include "../../common/Mutex.h"
24  #include "../../engines/EngineFactory.h"  #include "../../engines/EngineFactory.h"
25  #include "../../engines/Engine.h"  #include "../../engines/Engine.h"
26    #include "../../network/lscpserver.h"
27    
28  namespace LinuxSampler {  namespace LinuxSampler {
29    
# Line 97  namespace LinuxSampler { Line 98  namespace LinuxSampler {
98          privateEntry.InstrumentIndex = Entry.InstrumentIndex;          privateEntry.InstrumentIndex = Entry.InstrumentIndex;
99          privateEntry.Volume          = Entry.Volume;          privateEntry.Volume          = Entry.Volume;
100          privateEntry.Name            = Entry.Name;          privateEntry.Name            = Entry.Name;
101    
102            bool Replaced = false;
103            int InstrCount = 0;
104    
105          midiMapsMutex.Lock();          midiMapsMutex.Lock();
106          std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.find(Map);          std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.find(Map);
107          if (iterMap != midiMaps.end()) { // map found          if (iterMap != midiMaps.end()) { // map found
108                Replaced = (iterMap->second.find(Index) != iterMap->second.end());
109              iterMap->second[Index] = privateEntry;              iterMap->second[Index] = privateEntry;
110                InstrCount = iterMap->second.size();
111          } else { // no such map          } else { // no such map
112              midiMapsMutex.Unlock();              midiMapsMutex.Unlock();
113              EngineFactory::Destroy(pEngine);              EngineFactory::Destroy(pEngine);
# Line 108  namespace LinuxSampler { Line 115  namespace LinuxSampler {
115          }          }
116          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
117          EngineFactory::Destroy(pEngine);          EngineFactory::Destroy(pEngine);
118            
119            if (Replaced) {
120                int Bank = (int(Index.midi_bank_msb) << 7) & int(Index.midi_bank_lsb);
121                LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, Map, Bank, Index.midi_prog));
122            } else {
123                LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, Map, InstrCount));
124            }
125      }      }
126    
127      void MidiInstrumentMapper::RemoveEntry(int Map, midi_prog_index_t Index) {      void MidiInstrumentMapper::RemoveEntry(int Map, midi_prog_index_t Index) {
128            int InstrCount = -1;
129    
130          midiMapsMutex.Lock();          midiMapsMutex.Lock();
131          std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.find(Map);          std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.find(Map);
132          if (iterMap != midiMaps.end()) { // map found          if (iterMap != midiMaps.end()) { // map found
133              iterMap->second.erase(Index); // remove entry              iterMap->second.erase(Index); // remove entry
134                InstrCount = iterMap->second.size();
135          }          }
136          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
137            
138            if (InstrCount != -1) {
139                LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, Map, InstrCount));
140            }
141      }      }
142    
143      void MidiInstrumentMapper::RemoveAllEntries(int Map) {      void MidiInstrumentMapper::RemoveAllEntries(int Map) {
144            int InstrCount = -1;
145    
146          midiMapsMutex.Lock();          midiMapsMutex.Lock();
147          std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.find(Map);          std::map<int,MidiInstrumentMap>::iterator iterMap = midiMaps.find(Map);
148          if (iterMap != midiMaps.end()) { // map found          if (iterMap != midiMaps.end()) { // map found
149              iterMap->second.clear(); // clear that map              iterMap->second.clear(); // clear that map
150                InstrCount = 0;
151          }          }
152          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
153            
154            if (InstrCount != -1) {
155                LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, Map, InstrCount));
156            }
157      }      }
158    
159      std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> MidiInstrumentMapper::Entries(int Map) throw (Exception) {      std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> MidiInstrumentMapper::Entries(int Map) throw (Exception) {
# Line 212  namespace LinuxSampler { Line 240  namespace LinuxSampler {
240          __create_map:          __create_map:
241          midiMaps[ID].name = MapName;          midiMaps[ID].name = MapName;
242          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
243    
244            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, Maps().size()));
245          return ID;          return ID;
246      }      }
247    
# Line 237  namespace LinuxSampler { Line 267  namespace LinuxSampler {
267          }          }
268          iterMap->second.name = NewName;          iterMap->second.name = NewName;
269          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
270            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, Map));
271      }      }
272    
273      void MidiInstrumentMapper::RemoveMap(int Map) {      void MidiInstrumentMapper::RemoveMap(int Map) {
274          midiMapsMutex.Lock();          midiMapsMutex.Lock();
275          midiMaps.erase(Map);          midiMaps.erase(Map);
276          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
277            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, Maps().size()));
278      }      }
279    
280      void MidiInstrumentMapper::RemoveAllMaps() {      void MidiInstrumentMapper::RemoveAllMaps() {
281          midiMapsMutex.Lock();          midiMapsMutex.Lock();
282          midiMaps.clear();          midiMaps.clear();
283          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
284            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, Maps().size()));
285      }      }
286    
287      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.980  
changed lines
  Added in v.981

  ViewVC Help
Powered by ViewVC