/[svn]/jsampler/trunk/src/org/jsampler/MidiInstrumentMap.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/MidiInstrumentMap.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1754 by iliev, Sat Sep 8 18:33:05 2007 UTC revision 1755 by iliev, Tue Aug 12 16:31:35 2008 UTC
# Line 212  public class MidiInstrumentMap { Line 212  public class MidiInstrumentMap {
212           */           */
213          public MidiInstrumentEntry          public MidiInstrumentEntry
214          getAvailableEntry() {          getAvailableEntry() {
215                  int i = CC.getViewConfig().preferences().getIntProperty("lastUsedMidiBank", 0);                  int lb = CC.getViewConfig().preferences().getIntProperty("lastUsedMidiBank", 0);
216                  int firstFreePgm = -1, bank = -1, tmpBank = -1, tmpPgm = -1;                  int lp = CC.getViewConfig().preferences().getIntProperty("lastUsedMidiProgram", 0);
217                    
218                    MidiInstrumentEntry e = getAvailableEntry(lb, lp + 1);
219                    if(e != null) return e;
220                    
221                    for(int i = lb; i <= 16129; i++) {
222                            e = getAvailableEntry(i);
223                            if(e != null) return e;
224                    }
225                    
226                    for(int i = 0; i < lb; i++) {
227                            e = getAvailableEntry(i);
228                            if(e != null) return e;
229                    }
230                    
231                    return null;
232            }
233            
234            /**
235             * Gets a free entry.
236             * @param bank The bank number in which to search for available entry.
237             */
238            public MidiInstrumentEntry
239            getAvailableEntry(int bank) { return getAvailableEntry(bank, 0); }
240            
241            /**
242             * Gets a free entry.
243             * @param bank The bank number in which to search for available entry.
244             * @param fromProgram the program number to start the search from.
245             */
246            public MidiInstrumentEntry
247            getAvailableEntry(int bank, int fromProgram) {
248                    if(fromProgram > 127) return null;
249                    
250                    Vector<MidiInstrument> instruments = new Vector<MidiInstrument>();
251                                    
252                  for(MidiInstrument instr : instrMap.values()) {                  for(MidiInstrument instr : instrMap.values()) {
253                          int p = instr.getInfo().getMidiProgram();                          int p = instr.getInfo().getMidiProgram();
254                          int b = instr.getInfo().getMidiBank();                          int b = instr.getInfo().getMidiBank();
255                          if(b < i) continue;                          if(b == bank && p >= fromProgram) instruments.add(instr);
256                                                    if(b > bank) break;
257                          if(firstFreePgm != -1) {                  }
258                                  if(b > bank) {                  
259                                          if(tmpPgm < 127) {                  if(instruments.isEmpty()) {
260                                                  return new MidiInstrumentEntry(bank, tmpPgm + 1);                          if(fromProgram < 128) return new MidiInstrumentEntry(bank, fromProgram);
261                                          } else {                          else return new MidiInstrumentEntry(bank, 127);
                                                 return new MidiInstrumentEntry(bank, firstFreePgm);  
                                         }  
                                 }  
                                   
                                 tmpPgm = p;  
                         } else {  
                                 if(tmpBank != b) {  
                                         if(tmpBank != -1 && tmpPgm < 127) {  
                                                 return new MidiInstrumentEntry(tmpBank, tmpPgm + 1);  
                                         }  
                                         tmpPgm = -1;  
                                         tmpBank = b;  
                                 }  
                                   
                                 if(p - tmpPgm > 1) {  
                                         firstFreePgm = tmpPgm + 1;  
                                         bank = b;  
                                 }  
                                 tmpPgm = p;  
                         }  
262                  }                  }
263                                    
264                  if(tmpBank == -1) return new MidiInstrumentEntry(i, 0);                  int prevPrg = instruments.get(0).getInfo().getMidiProgram();
265                    if(fromProgram < prevPrg) return new MidiInstrumentEntry(bank, fromProgram);
266                                    
267                  if(firstFreePgm != -1) {                  for(int i = 1; i < instruments.size(); i++) {
268                          if(tmpPgm < 127) return new MidiInstrumentEntry(bank, tmpPgm + 1);                          int prg = instruments.get(i).getInfo().getMidiProgram();
269                          else return new MidiInstrumentEntry(bank, firstFreePgm);                          if(prg - prevPrg > 1) return new MidiInstrumentEntry(bank, prevPrg + 1);
270                            prevPrg = prg;
271                  }                  }
272                                    
273                  if(tmpBank == 16129 && tmpPgm == 127) return null;                  if(prevPrg < 127)  return new MidiInstrumentEntry(bank, prevPrg + 1);
274                                    
275                  if(tmpPgm < 127) return new MidiInstrumentEntry(tmpBank, tmpPgm + 1);                  return null;
                 else return new MidiInstrumentEntry(tmpBank + 1, 0);  
276          }          }
277                    
278          /**          /**

Legend:
Removed from v.1754  
changed lines
  Added in v.1755

  ViewVC Help
Powered by ViewVC