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

Diff of /jsampler/trunk/src/org/jsampler/task/Midi.java

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

revision 1866 by iliev, Sun May 4 18:40:13 2008 UTC revision 1867 by iliev, Mon Mar 16 22:12:32 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 21  Line 21 
21   */   */
22  package org.jsampler.task;  package org.jsampler.task;
23    
 import java.util.Vector;  
 import java.util.logging.Level;  
   
 import net.sf.juife.Task;  
   
24  import org.linuxsampler.lscp.BoolParameter;  import org.linuxsampler.lscp.BoolParameter;
25  import org.linuxsampler.lscp.MidiInputDevice;  import org.linuxsampler.lscp.MidiInputDevice;
26  import org.linuxsampler.lscp.MidiInputDriver;  import org.linuxsampler.lscp.MidiInputDriver;
# Line 35  import org.linuxsampler.lscp.MidiInstrum Line 30  import org.linuxsampler.lscp.MidiInstrum
30  import org.linuxsampler.lscp.Parameter;  import org.linuxsampler.lscp.Parameter;
31    
32  import org.jsampler.CC;  import org.jsampler.CC;
 import org.jsampler.HF;  
33  import org.jsampler.MidiDeviceModel;  import org.jsampler.MidiDeviceModel;
34  import org.jsampler.MidiInstrument;  import org.jsampler.MidiInstrument;
35  import org.jsampler.MidiInstrumentMap;  import org.jsampler.MidiInstrumentMap;
# Line 66  public class Midi { Line 60  public class Midi {
60                  }                  }
61                    
62                  /** The entry point of the task. */                  /** The entry point of the task. */
63                    @Override
64                  public void                  public void
65                  run() {                  exec() throws Exception { setResult(CC.getClient().getMidiInputDrivers()); }
                         try { setResult(CC.getClient().getMidiInputDrivers()); }  
                         catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
66          }          }
67                    
68          /**          /**
# Line 98  public class Midi { Line 87  public class Midi {
87                  }                  }
88                    
89                  /** The entry point of the task. */                  /** The entry point of the task. */
90                    @Override
91                  public void                  public void
92                  run() {                  exec() throws Exception {
93                          try {                          MidiInputDriver d;
94                                  MidiInputDriver d;                          d = CC.getClient().getMidiInputDriverInfo(driver, depList);
95                                  d = CC.getClient().getMidiInputDriverInfo(driver, depList);                          setResult(d.getParameters());
                                 setResult(d.getParameters());  
                         }  
                         catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
96                  }                  }
97          }          }
98    
# Line 134  public class Midi { Line 118  public class Midi {
118                  }                  }
119                    
120                  /** The entry point of the task. */                  /** The entry point of the task. */
121                    @Override
122                  public void                  public void
123                  run() {                  exec() throws Exception { run0(); }
                         try {  
                                 run0();  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
124                                    
125                  private void                  private void
126                  run0() throws Exception {                  run0() throws Exception {
# Line 170  public class Midi { Line 148  public class Midi {
148                  }                  }
149                    
150                  /** The entry point of the task. */                  /** The entry point of the task. */
151                    @Override
152                  public void                  public void
153                  run() {                  exec() throws Exception { CC.getClient().destroyMidiInputDevice(deviceId); }
                         try { CC.getClient().destroyMidiInputDevice(deviceId); }  
                         catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
154          }          }
155    
156          /**          /**
# Line 203  public class Midi { Line 176  public class Midi {
176                  }                  }
177                    
178                  /** The entry point of the task. */                  /** The entry point of the task. */
179                    @Override
180                  public void                  public void
181                  run() {                  exec() throws Exception {
182                          try {                          CC.getClient().enableMidiInputDevice(dev, enable);
183                                  CC.getClient().enableMidiInputDevice(dev, enable);                          
184                                                    // Not needed, but eventually speeds up the change.
185                                  // Not needed, but eventually speeds up the change.                          CC.getSamplerModel().getMidiDeviceById(dev).setActive(enable);
                                 CC.getSamplerModel().getMidiDeviceById(dev).setActive(enable);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
186                  }                  }
187          }          }
188    
# Line 250  public class Midi { Line 219  public class Midi {
219                  }                  }
220                    
221                  /** The entry point of the task. */                  /** The entry point of the task. */
222                    @Override
223                  public void                  public void
224                  run() {                  exec() throws Exception {
225                          try {                          CC.getClient().setMidiInputDeviceParameter(dev, prm);
226                                  CC.getClient().setMidiInputDeviceParameter(dev, prm);                          CC.getSamplerModel().getMidiDeviceById(dev);
                                   
                                 CC.getSamplerModel().getMidiDeviceById(dev);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
227                  }                  }
228          }          }
229    
# Line 285  public class Midi { Line 249  public class Midi {
249                  }                  }
250                    
251                  /** The entry point of the task. */                  /** The entry point of the task. */
252                    @Override
253                  public void                  public void
254                  run() {                  exec() throws Exception {
255                          try { CC.getClient().setMidiInputPortCount(deviceId, ports); }                          CC.getClient().setMidiInputPortCount(deviceId, ports);
                         catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
256                  }                  }
257          }          }
258                    
# Line 320  public class Midi { Line 281  public class Midi {
281                  }                  }
282                    
283                  /** The entry point of the task. */                  /** The entry point of the task. */
284                    @Override
285                  public void                  public void
286                  run() {                  exec() throws Exception {
287                          try { CC.getClient().setMidiInputPortParameter(dev, port, prm); }                          CC.getClient().setMidiInputPortParameter(dev, port, prm);
                         catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
288                  }                  }
289          }          }
290    
# Line 349  public class Midi { Line 307  public class Midi {
307                  }                  }
308                    
309                  /** The entry point of the task. */                  /** The entry point of the task. */
310                    @Override
311                  public void                  public void
312                  run() {                  exec() throws Exception {
313                          try {                          MidiInputDevice mid = CC.getClient().getMidiInputDeviceInfo(dev);
314                                  MidiInputDevice mid = CC.getClient().getMidiInputDeviceInfo(dev);                          CC.getSamplerModel().getMidiDeviceById(dev).setDeviceInfo(mid);
                                 CC.getSamplerModel().getMidiDeviceById(dev).setDeviceInfo(mid);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
315                  }                  }
316          }          }
317    
# Line 373  public class Midi { Line 327  public class Midi {
327                  }                  }
328                    
329                  /** The entry point of the task. */                  /** The entry point of the task. */
330                    @Override
331                  public void                  public void
332                  run() {                  exec() throws Exception {
333                          try {                          SamplerModel sm = CC.getSamplerModel();
334                                  SamplerModel sm = CC.getSamplerModel();                          Integer[] deviceIDs = CC.getClient().getMidiInputDeviceIDs();
335                                  Integer[] deviceIDs = CC.getClient().getMidiInputDeviceIDs();                  
336                            boolean found = false;
337                                                    
338                                  boolean found = false;                          for(MidiDeviceModel m : sm.getMidiDevices()) {
339                                                                    for(int i = 0; i < deviceIDs.length; i++) {
340                                  for(MidiDeviceModel m : sm.getMidiDevices()) {                                          if(m.getDeviceId() == deviceIDs[i]) {
341                                          for(int i = 0; i < deviceIDs.length; i++) {                                                  deviceIDs[i] = -1;
342                                                  if(m.getDeviceId() == deviceIDs[i]) {                                                  found = true;
                                                         deviceIDs[i] = -1;  
                                                         found = true;  
                                                 }  
343                                          }                                          }
                                   
                                         if(!found) sm.removeMidiDeviceById(m.getDeviceId());  
                                         found = false;  
344                                  }                                  }
345                                                    
346                                  MidiInputDevice dev;                                  if(!found) sm.removeMidiDeviceById(m.getDeviceId());
347                                                                    found = false;
348                                  for(int id : deviceIDs) {                          }
349                                          if(id >= 0) {                  
350                                                  dev = CC.getClient().getMidiInputDeviceInfo(id);                          MidiInputDevice dev;
351                                                  sm.addMidiDevice(dev);                          
352                                          }                          for(int id : deviceIDs) {
353                                    if(id >= 0) {
354                                            dev = CC.getClient().getMidiInputDeviceInfo(id);
355                                            sm.addMidiDevice(dev);
356                                  }                                  }
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
357                          }                          }
358                  }                  }
359          }          }
# Line 428  public class Midi { Line 378  public class Midi {
378                  }                  }
379                    
380                  /** The entry point of the task. */                  /** The entry point of the task. */
381                    @Override
382                  public void                  public void
383                  run() {                  exec() throws Exception {
384                          try {                          Integer mapId = CC.getClient().addMidiInstrumentMap(name);
385                                  Integer mapId = CC.getClient().addMidiInstrumentMap(name);                          setResult(mapId);
                                 setResult(mapId);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
386                  }                  }
387          }          }
388                    
# Line 460  public class Midi { Line 406  public class Midi {
406                  }                  }
407                    
408                  /** The entry point of the task. */                  /** The entry point of the task. */
409                    @Override
410                  public void                  public void
411                  run() {                  exec() throws Exception { CC.getClient().removeMidiInstrumentMap(mapId); }
                         try {  
                                 CC.getClient().removeMidiInstrumentMap(mapId);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
412          }          }
413                    
414          /**          /**
# Line 493  public class Midi { Line 433  public class Midi {
433                  }                  }
434                    
435                  /** The entry point of the task. */                  /** The entry point of the task. */
436                    @Override
437                  public void                  public void
438                  run() {                  exec() throws Exception { CC.getClient().setMidiInstrumentMapName(mapId, name); }
                         try {  
                                 CC.getClient().setMidiInstrumentMapName(mapId, name);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
439          }          }
440                    
441          /**          /**
# Line 523  public class Midi { Line 457  public class Midi {
457                  }                  }
458                    
459                  /** The entry point of the task. */                  /** The entry point of the task. */
460                    @Override
461                  public void                  public void
462                  run() {                  exec() throws Exception {
463                          try {                          MidiInstrumentMapInfo info = CC.getClient().getMidiInstrumentMapInfo(mapId);
464                                  MidiInstrumentMapInfo info =                          CC.getSamplerModel().getMidiInstrumentMapById(mapId).setInfo(info);
                                         CC.getClient().getMidiInstrumentMapInfo(mapId);  
                                   
                                 CC.getSamplerModel().getMidiInstrumentMapById(mapId).setInfo(info);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
465                  }                  }
466          }          }
467    
# Line 549  public class Midi { Line 477  public class Midi {
477                  }                  }
478                    
479                  /** The entry point of the task. */                  /** The entry point of the task. */
480                    @Override
481                  public void                  public void
482                  run() {                  exec() throws Exception {
483                          try {                          MidiInstrumentMapInfo[] mims;
484                                  MidiInstrumentMapInfo[] mims;                          mims = CC.getClient().getMidiInstrumentMaps();
485                                  mims = CC.getClient().getMidiInstrumentMaps();                          MidiInstrumentMap[] maps = new MidiInstrumentMap[mims.length];
486                                  MidiInstrumentMap[] maps = new MidiInstrumentMap[mims.length];                          
487                                                            for(int i = 0; i < mims.length; i++) {
488                                  for(int i = 0; i < mims.length; i++) {                                  maps[i] = createMap(mims[i]);
                                         maps[i] = createMap(mims[i]);  
                                 }  
                                   
                                 setResult(maps);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
489                          }                          }
490                            
491                            setResult(maps);
492                  }                  }
493                                    
494                  private MidiInstrumentMap                  private MidiInstrumentMap
# Line 593  public class Midi { Line 517  public class Midi {
517                  }                  }
518                    
519                  /** The entry point of the task. */                  /** The entry point of the task. */
520                    @Override
521                  public void                  public void
522                  run() {                  exec() throws Exception {
523                          try {                          SamplerModel sm = CC.getSamplerModel();
524                                  SamplerModel sm = CC.getSamplerModel();                          Integer[] mapIDs = CC.getClient().getMidiInstrumentMapIDs();
525                                  Integer[] mapIDs = CC.getClient().getMidiInstrumentMapIDs();                  
526                            boolean found = false;
527                                                    
528                                  boolean found = false;                          for(MidiInstrumentMap m : sm.getMidiInstrumentMaps()) {
529                                                                    for(int i = 0; i < mapIDs.length; i++) {
530                                  for(MidiInstrumentMap m : sm.getMidiInstrumentMaps()) {                                          if(mapIDs[i] == m.getMapId()) {
531                                          for(int i = 0; i < mapIDs.length; i++) {                                                  mapIDs[i] = -1;
532                                                  if(mapIDs[i] == m.getMapId()) {                                                  found = true;
                                                         mapIDs[i] = -1;  
                                                         found = true;  
                                                 }  
533                                          }                                          }
                                           
                                         if(!found) sm.removeMidiInstrumentMapById(m.getMapId());  
                                         found = false;  
534                                  }                                  }
535                                                                    
536                                  MidiInstrumentMapInfo map;                                  if(!found) sm.removeMidiInstrumentMapById(m.getMapId());
537                                                                    found = false;
538                                  for(int id : mapIDs) {                          }
539                                          if(id >= 0) {                          
540                                                  map = CC.getClient().getMidiInstrumentMapInfo(id);                          MidiInstrumentMapInfo map;
541                                                  sm.addMidiInstrumentMap(new MidiInstrumentMap(map));                          
542                                          }                          for(int id : mapIDs) {
543                                    if(id >= 0) {
544                                            map = CC.getClient().getMidiInstrumentMapInfo(id);
545                                            sm.addMidiInstrumentMap(new MidiInstrumentMap(map));
546                                  }                                  }
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                                 x.printStackTrace();  
547                          }                          }
548                  }                  }
549          }          }
# Line 657  public class Midi { Line 576  public class Midi {
576                  }                  }
577                    
578                  /** The entry point of the task. */                  /** The entry point of the task. */
579                    @Override
580                  public void                  public void
581                  run() {                  exec() throws Exception {
582                          try {                          MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);
583                                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);                          CC.getClient().mapMidiInstrument(mapId, entry, instrInfo, true);
                                 CC.getClient().mapMidiInstrument(mapId, entry, instrInfo, true);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
584                  }                  }
585          }          }
586    
# Line 695  public class Midi { Line 610  public class Midi {
610                  }                  }
611                    
612                  /** The entry point of the task. */                  /** The entry point of the task. */
613                    @Override
614                  public void                  public void
615                  run() {                  exec() throws Exception {
616                          try {                          MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);
617                                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);                          CC.getClient().unmapMidiInstrument(mapId, entry);
                                 CC.getClient().unmapMidiInstrument(mapId, entry);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
618                  }                  }
619          }          }
620    
# Line 732  public class Midi { Line 643  public class Midi {
643                  }                  }
644                    
645                  /** The entry point of the task. */                  /** The entry point of the task. */
646                    @Override
647                  public void                  public void
648                  run() {                  exec() throws Exception {
649                          try {                          MidiInstrumentInfo info =
650                                  MidiInstrumentInfo info =                                  CC.getClient().getMidiInstrumentInfo(mapId, bank, program);
651                                          CC.getClient().getMidiInstrumentInfo(mapId, bank, program);                          
652                                                            MidiInstrumentMap map;
653                                  MidiInstrumentMap map;                          map = CC.getSamplerModel().getMidiInstrumentMapById(mapId);
654                                  map = CC.getSamplerModel().getMidiInstrumentMapById(mapId);                          map.getMidiInstrument(bank, program).setInfo(info);
                                 map.getMidiInstrument(bank, program).setInfo(info);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
655                  }                  }
656          }          }
657    
# Line 764  public class Midi { Line 671  public class Midi {
671                  }                  }
672                    
673                  /** The entry point of the task. */                  /** The entry point of the task. */
674                    @Override
675                  public void                  public void
676                  run() {                  exec() throws Exception {
677                          try {                          SamplerModel sm = CC.getSamplerModel();
678                                  SamplerModel sm = CC.getSamplerModel();                          int[][] entries = CC.getClient().getMidiInstrumentEntries(mapId);
679                                  int[][] entries = CC.getClient().getMidiInstrumentEntries(mapId);                          MidiInstrumentMap map = sm.getMidiInstrumentMapById(mapId);
680                                  MidiInstrumentMap map = sm.getMidiInstrumentMapById(mapId);                          boolean found = false;
681                                  boolean found = false;                          
682                                                            for(MidiInstrument instr : map.getAllMidiInstruments()) {
683                                  for(MidiInstrument instr : map.getAllMidiInstruments()) {                                  for(int i = 0; i < entries.length; i++) {
684                                          for(int i = 0; i < entries.length; i++) {                                          if(entries[i] == null) continue;
685                                                  if(entries[i] == null) continue;                                          
686                                                                                            if(equal(instr, entries[i])) {
687                                                  if(equal(instr, entries[i])) {                                                  entries[i] = null;
688                                                          entries[i] = null;                                                  found = true;
                                                         found = true;  
                                                 }  
                                         }  
                                   
                                         if(!found) {  
                                                 map.unmapMidiInstrument(instr.getInfo().getEntry());  
689                                          }                                          }
                                         found = false;  
690                                  }                                  }
691                                                            
692                                  for(int[] entry : entries) {                                  if(!found) map.unmapMidiInstrument(instr.getInfo().getEntry());
693                                          if(entry != null) {                                  found = false;
694                                                  MidiInstrumentInfo i;                          }
695                                                  i = CC.getClient().getMidiInstrumentInfo (                          
696                            for(int[] entry : entries) {
697                                    if(entry != null) {
698                                            MidiInstrumentInfo i;
699                                            i = CC.getClient().getMidiInstrumentInfo (
700                                                          entry[0], entry[1], entry[2]                                                          entry[0], entry[1], entry[2]
701                                                  );                                          );
702                                                  MidiInstrument instr = new MidiInstrument(i);                                          MidiInstrument instr = new MidiInstrument(i);
703                                                  map.mapMidiInstrument(i.getEntry(), instr);                                          map.mapMidiInstrument(i.getEntry(), instr);
                                         }  
704                                  }                                  }
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
705                          }                          }
706                  }                  }
707                                    
# Line 823  public class Midi { Line 724  public class Midi {
724                   * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.                   * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
725                   * @see org.jsampler.CC#addTask                   * @see org.jsampler.CC#addTask
726                   */                   */
727                    @Override
728                  public boolean                  public boolean
729                  equals(Object obj) {                  equals(Object obj) {
730                          if(obj == null) return false;                          if(obj == null) return false;

Legend:
Removed from v.1866  
changed lines
  Added in v.1867

  ViewVC Help
Powered by ViewVC