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" |
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); |
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(); |
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 |
|
|
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) { |