208 |
} |
} |
209 |
|
|
210 |
/** |
/** |
211 |
|
* Gets a free entry. |
212 |
|
*/ |
213 |
|
public MidiInstrumentEntry |
214 |
|
getAvailableEntry() { |
215 |
|
int i = CC.getViewConfig().preferences().getIntProperty("lastUsedMidiBank", 0); |
216 |
|
int firstFreePgm = -1, bank = -1, tmpBank = -1, tmpPgm = -1; |
217 |
|
|
218 |
|
for(MidiInstrument instr : instrMap.values()) { |
219 |
|
int p = instr.getInfo().getMidiProgram(); |
220 |
|
int b = instr.getInfo().getMidiBank(); |
221 |
|
if(b < i) continue; |
222 |
|
|
223 |
|
if(firstFreePgm != -1) { |
224 |
|
if(b > bank) { |
225 |
|
if(tmpPgm < 127) { |
226 |
|
return new MidiInstrumentEntry(bank, tmpPgm + 1); |
227 |
|
} else { |
228 |
|
return new MidiInstrumentEntry(bank, firstFreePgm); |
229 |
|
} |
230 |
|
} |
231 |
|
|
232 |
|
tmpPgm = p; |
233 |
|
} else { |
234 |
|
if(tmpBank != b) { |
235 |
|
if(tmpBank != -1 && tmpPgm < 127) { |
236 |
|
return new MidiInstrumentEntry(tmpBank, tmpPgm + 1); |
237 |
|
} |
238 |
|
tmpPgm = -1; |
239 |
|
tmpBank = b; |
240 |
|
} |
241 |
|
|
242 |
|
if(p - tmpPgm > 1) { |
243 |
|
firstFreePgm = tmpPgm + 1; |
244 |
|
bank = b; |
245 |
|
} |
246 |
|
tmpPgm = p; |
247 |
|
} |
248 |
|
} |
249 |
|
|
250 |
|
if(tmpBank == -1) return new MidiInstrumentEntry(i, 0); |
251 |
|
|
252 |
|
if(firstFreePgm != -1) { |
253 |
|
if(tmpPgm < 127) return new MidiInstrumentEntry(bank, tmpPgm + 1); |
254 |
|
else return new MidiInstrumentEntry(bank, firstFreePgm); |
255 |
|
} |
256 |
|
|
257 |
|
if(tmpBank == 16129 && tmpPgm == 127) return null; |
258 |
|
|
259 |
|
if(tmpPgm < 127) return new MidiInstrumentEntry(tmpBank, tmpPgm + 1); |
260 |
|
else return new MidiInstrumentEntry(tmpBank + 1, 0); |
261 |
|
} |
262 |
|
|
263 |
|
/** |
264 |
* Returns the name of this map. |
* Returns the name of this map. |
265 |
* @return The name of this map. |
* @return The name of this map. |
266 |
*/ |
*/ |