47 |
// for synchronization of midiMaps |
// for synchronization of midiMaps |
48 |
Mutex midiMapsMutex; |
Mutex midiMapsMutex; |
49 |
|
|
|
|
|
50 |
ListenerList<MidiInstrumentCountListener*> MidiInstrumentMapper::llMidiInstrumentCountListeners; |
ListenerList<MidiInstrumentCountListener*> MidiInstrumentMapper::llMidiInstrumentCountListeners; |
51 |
ListenerList<MidiInstrumentInfoListener*> MidiInstrumentMapper::llMidiInstrumentInfoListeners; |
ListenerList<MidiInstrumentInfoListener*> MidiInstrumentMapper::llMidiInstrumentInfoListeners; |
52 |
ListenerList<MidiInstrumentMapCountListener*> MidiInstrumentMapper::llMidiInstrumentMapCountListeners; |
ListenerList<MidiInstrumentMapCountListener*> MidiInstrumentMapper::llMidiInstrumentMapCountListeners; |
53 |
ListenerList<MidiInstrumentMapInfoListener*> MidiInstrumentMapper::llMidiInstrumentMapInfoListeners; |
ListenerList<MidiInstrumentMapInfoListener*> MidiInstrumentMapper::llMidiInstrumentMapInfoListeners; |
54 |
|
int MidiInstrumentMapper::DefaultMap; |
55 |
|
|
56 |
void MidiInstrumentMapper::AddMidiInstrumentCountListener(MidiInstrumentCountListener* l) { |
void MidiInstrumentMapper::AddMidiInstrumentCountListener(MidiInstrumentCountListener* l) { |
57 |
llMidiInstrumentCountListeners.AddListener(l); |
llMidiInstrumentCountListeners.AddListener(l); |
278 |
return result; |
return result; |
279 |
} |
} |
280 |
|
|
281 |
|
int MidiInstrumentMapper::GetMapCount() { |
282 |
|
midiMapsMutex.Lock(); |
283 |
|
int i = midiMaps.size(); |
284 |
|
midiMapsMutex.Unlock(); |
285 |
|
return i; |
286 |
|
} |
287 |
|
|
288 |
int MidiInstrumentMapper::AddMap(String MapName) throw (Exception) { |
int MidiInstrumentMapper::AddMap(String MapName) throw (Exception) { |
289 |
int ID; |
int ID; |
290 |
midiMapsMutex.Lock(); |
midiMapsMutex.Lock(); |
307 |
} |
} |
308 |
__create_map: |
__create_map: |
309 |
midiMaps[ID].name = MapName; |
midiMaps[ID].name = MapName; |
310 |
midiMapsMutex.Unlock(); |
|
|
|
|
311 |
fireMidiInstrumentMapCountChanged(Maps().size()); |
fireMidiInstrumentMapCountChanged(Maps().size()); |
312 |
|
// If there were no maps until now we must set a default map. |
313 |
|
if (midiMaps.size() == 1) SetDefaultMap(ID); |
314 |
|
midiMapsMutex.Unlock(); |
315 |
|
|
316 |
return ID; |
return ID; |
317 |
} |
} |
318 |
|
|
344 |
void MidiInstrumentMapper::RemoveMap(int Map) { |
void MidiInstrumentMapper::RemoveMap(int Map) { |
345 |
midiMapsMutex.Lock(); |
midiMapsMutex.Lock(); |
346 |
midiMaps.erase(Map); |
midiMaps.erase(Map); |
347 |
midiMapsMutex.Unlock(); |
if(Map == GetDefaultMap()) { |
348 |
|
SetDefaultMap(midiMaps.empty() ? -1 : (*(midiMaps.begin())).first); |
349 |
|
} |
350 |
fireMidiInstrumentMapCountChanged(Maps().size()); |
fireMidiInstrumentMapCountChanged(Maps().size()); |
351 |
|
midiMapsMutex.Unlock(); |
352 |
} |
} |
353 |
|
|
354 |
void MidiInstrumentMapper::RemoveAllMaps() { |
void MidiInstrumentMapper::RemoveAllMaps() { |
355 |
midiMapsMutex.Lock(); |
midiMapsMutex.Lock(); |
356 |
midiMaps.clear(); |
midiMaps.clear(); |
357 |
midiMapsMutex.Unlock(); |
SetDefaultMap(-1); |
358 |
fireMidiInstrumentMapCountChanged(Maps().size()); |
fireMidiInstrumentMapCountChanged(Maps().size()); |
359 |
|
midiMapsMutex.Unlock(); |
360 |
|
} |
361 |
|
|
362 |
|
int MidiInstrumentMapper::GetDefaultMap() { |
363 |
|
midiMapsMutex.Lock(); |
364 |
|
int i = DefaultMap; |
365 |
|
midiMapsMutex.Unlock(); |
366 |
|
return i; |
367 |
|
} |
368 |
|
|
369 |
|
void MidiInstrumentMapper::SetDefaultMap(int MapId) { |
370 |
|
midiMapsMutex.Lock(); |
371 |
|
DefaultMap = MapId; |
372 |
|
midiMapsMutex.Unlock(); |
373 |
|
|
374 |
|
if (MapId != -1) fireMidiInstrumentMapInfoChanged(MapId); |
375 |
} |
} |
376 |
|
|
377 |
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) { |