/[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 981 by iliev, Sun Dec 17 22:35:01 2006 UTC revision 1754 by iliev, Tue Aug 12 16:18:59 2008 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   Copyright (C) 2006 Christian Schoenebeck                              *   *   Copyright (C) 2006 - 2007 Christian Schoenebeck                       *
4   *                                                                         *   *                                                                         *
5   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
6   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# 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"
 #include "../../network/lscpserver.h"  
27    
28  namespace LinuxSampler {  namespace LinuxSampler {
29    
# Line 48  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;
52        ListenerList<MidiInstrumentInfoListener*> MidiInstrumentMapper::llMidiInstrumentInfoListeners;
53        ListenerList<MidiInstrumentMapCountListener*> MidiInstrumentMapper::llMidiInstrumentMapCountListeners;
54        ListenerList<MidiInstrumentMapInfoListener*> MidiInstrumentMapper::llMidiInstrumentMapInfoListeners;
55        int MidiInstrumentMapper::DefaultMap;
56        
57        void MidiInstrumentMapper::AddMidiInstrumentCountListener(MidiInstrumentCountListener* l) {
58            llMidiInstrumentCountListeners.AddListener(l);
59        }
60    
61        void MidiInstrumentMapper::RemoveMidiInstrumentCountListener(MidiInstrumentCountListener* l) {
62            llMidiInstrumentCountListeners.RemoveListener(l);
63        }
64    
65        void MidiInstrumentMapper::fireMidiInstrumentCountChanged(int MapId, int NewCount) {
66            for (int i = 0; i < llMidiInstrumentCountListeners.GetListenerCount(); i++) {
67                llMidiInstrumentCountListeners.GetListener(i)->MidiInstrumentCountChanged(MapId, NewCount);
68            }
69        }
70    
71        void MidiInstrumentMapper::AddMidiInstrumentInfoListener(MidiInstrumentInfoListener* l) {
72            llMidiInstrumentInfoListeners.AddListener(l);
73        }
74    
75        void MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(MidiInstrumentInfoListener* l) {
76            llMidiInstrumentInfoListeners.RemoveListener(l);
77        }
78    
79        void MidiInstrumentMapper::fireMidiInstrumentInfoChanged(int MapId, int Bank, int Program) {
80            for (int i = 0; i < llMidiInstrumentInfoListeners.GetListenerCount(); i++) {
81                llMidiInstrumentInfoListeners.GetListener(i)->MidiInstrumentInfoChanged(MapId, Bank, Program);
82            }
83        }
84    
85        void MidiInstrumentMapper::AddMidiInstrumentMapCountListener(MidiInstrumentMapCountListener* l) {
86            llMidiInstrumentMapCountListeners.AddListener(l);
87        }
88    
89        void MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(MidiInstrumentMapCountListener* l) {
90            llMidiInstrumentMapCountListeners.RemoveListener(l);
91        }
92    
93        void MidiInstrumentMapper::fireMidiInstrumentMapCountChanged(int NewCount) {
94            for (int i = 0; i < llMidiInstrumentMapCountListeners.GetListenerCount(); i++) {
95                llMidiInstrumentMapCountListeners.GetListener(i)->MidiInstrumentMapCountChanged(NewCount);
96            }
97        }
98    
99        void MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(MidiInstrumentMapInfoListener* l) {
100            llMidiInstrumentMapInfoListeners.AddListener(l);
101        }
102    
103        void MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(MidiInstrumentMapInfoListener* l) {
104            llMidiInstrumentMapInfoListeners.RemoveListener(l);
105        }
106    
107        void MidiInstrumentMapper::fireMidiInstrumentMapInfoChanged(int MapId) {
108            for (int i = 0; i < llMidiInstrumentMapInfoListeners.GetListenerCount(); i++) {
109                llMidiInstrumentMapInfoListeners.GetListener(i)->MidiInstrumentMapInfoChanged(MapId);
110            }
111        }
112    
113      void MidiInstrumentMapper::AddOrReplaceEntry(int Map, midi_prog_index_t Index, entry_t Entry, bool bInBackground) throw (Exception) {      void MidiInstrumentMapper::AddOrReplaceEntry(int Map, midi_prog_index_t Index, entry_t Entry, bool bInBackground) throw (Exception) {
114          if (bInBackground) {          if (bInBackground) {
# Line 73  namespace LinuxSampler { Line 134  namespace LinuxSampler {
134          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
135          if (!Entry.InstrumentFile.size())          if (!Entry.InstrumentFile.size())
136              throw Exception("No instrument file name given");              throw Exception("No instrument file name given");
137            // TODO: an easy one - we should check here if given file exists and throw an exception if it doesn't
138          if (Entry.Volume < 0.0)          if (Entry.Volume < 0.0)
139              throw Exception("Volume may not be a negative value");              throw Exception("Volume may not be a negative value");
140          Engine* pEngine = EngineFactory::Create(Entry.EngineName);          Engine* pEngine = EngineFactory::Create(Entry.EngineName);
# Line 83  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 117  namespace LinuxSampler { Line 179  namespace LinuxSampler {
179          EngineFactory::Destroy(pEngine);          EngineFactory::Destroy(pEngine);
180                    
181          if (Replaced) {          if (Replaced) {
182              int Bank = (int(Index.midi_bank_msb) << 7) & int(Index.midi_bank_lsb);              int Bank = (int(Index.midi_bank_msb) << 7) | int(Index.midi_bank_lsb);
183              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, Map, Bank, Index.midi_prog));              fireMidiInstrumentInfoChanged(Map, Bank, Index.midi_prog);
184          } else {          } else {
185              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, Map, InstrCount));              fireMidiInstrumentCountChanged(Map, InstrCount);
186          }          }
187      }      }
188    
# Line 136  namespace LinuxSampler { Line 198  namespace LinuxSampler {
198          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
199                    
200          if (InstrCount != -1) {          if (InstrCount != -1) {
201              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, Map, InstrCount));              fireMidiInstrumentCountChanged(Map, InstrCount);
202          }          }
203      }      }
204    
# Line 152  namespace LinuxSampler { Line 214  namespace LinuxSampler {
214          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
215                    
216          if (InstrCount != -1) {          if (InstrCount != -1) {
217              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, Map, InstrCount));              fireMidiInstrumentCountChanged(Map, InstrCount);
218          }          }
219      }      }
220    
# Line 217  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 239  namespace LinuxSampler { Line 308  namespace LinuxSampler {
308          }          }
309          __create_map:          __create_map:
310          midiMaps[ID].name = MapName;          midiMaps[ID].name = MapName;
311            
312            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();          midiMapsMutex.Unlock();
316            
         LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, Maps().size()));  
317          return ID;          return ID;
318      }      }
319    
# Line 267  namespace LinuxSampler { Line 339  namespace LinuxSampler {
339          }          }
340          iterMap->second.name = NewName;          iterMap->second.name = NewName;
341          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
342          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, Map));          fireMidiInstrumentMapInfoChanged(Map);
343      }      }
344    
345      void MidiInstrumentMapper::RemoveMap(int Map) {      void MidiInstrumentMapper::RemoveMap(int Map) {
346          midiMapsMutex.Lock();          midiMapsMutex.Lock();
347          midiMaps.erase(Map);          midiMaps.erase(Map);
348            if(Map == GetDefaultMap()) {
349                SetDefaultMap(midiMaps.empty() ? -1 : (*(midiMaps.begin())).first);
350            }
351            fireMidiInstrumentMapCountChanged(Maps().size());
352          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
         LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, Maps().size()));  
353      }      }
354    
355      void MidiInstrumentMapper::RemoveAllMaps() {      void MidiInstrumentMapper::RemoveAllMaps() {
356          midiMapsMutex.Lock();          midiMapsMutex.Lock();
357          midiMaps.clear();          midiMaps.clear();
358            SetDefaultMap(-1);
359            fireMidiInstrumentMapCountChanged(Maps().size());
360            midiMapsMutex.Unlock();
361        }
362    
363        int MidiInstrumentMapper::GetDefaultMap() {
364            midiMapsMutex.Lock();
365            int i = DefaultMap;
366          midiMapsMutex.Unlock();          midiMapsMutex.Unlock();
367          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, Maps().size()));          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.981  
changed lines
  Added in v.1754

  ViewVC Help
Powered by ViewVC