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

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

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

revision 1144 by iliev, Mon Apr 2 21:39:15 2007 UTC revision 1313 by iliev, Thu Aug 30 22:44:29 2007 UTC
# Line 28  import net.sf.juife.Task; Line 28  import net.sf.juife.Task;
28    
29  import org.jsampler.CC;  import org.jsampler.CC;
30  import org.jsampler.HF;  import org.jsampler.HF;
31    import org.jsampler.JSPrefs;
32  import org.jsampler.SamplerChannelModel;  import org.jsampler.SamplerChannelModel;
33  import org.jsampler.SamplerModel;  import org.jsampler.SamplerModel;
34    
35  import org.linuxsampler.lscp.FxSend;  import org.linuxsampler.lscp.FxSend;
36    
37  import static org.jsampler.JSI18n.i18n;  import static org.jsampler.JSI18n.i18n;
38    import static org.jsampler.JSPrefs.*;
39    
40    
41  /**  /**
# Line 60  public class Channel { Line 62  public class Channel {
62                  /** The entry point of the task. */                  /** The entry point of the task. */
63                  public void                  public void
64                  run() {                  run() {
65                          try { setResult(CC.getClient().addSamplerChannel()); }                          try {
66                          catch(Exception x) {                                  setResult(CC.getClient().addSamplerChannel());
67                                    
68                                    JSPrefs p = CC.getViewConfig().preferences();
69                                    if(!p.getBoolProperty(USE_CHANNEL_DEFAULTS)) return;
70                                    
71                                    String s = p.getStringProperty(DEFAULT_ENGINE);
72                                    if(s != null && s.length() > 0) {
73                                            CC.getClient().loadSamplerEngine(s, getResult());
74                                    }
75                                    
76                                    s = p.getStringProperty(DEFAULT_MIDI_INPUT);
77                                    if(s != null && s.equals("firstDevice")) {
78                                            assignFirstMidiDevice();
79                                    } else if(s != null && s.equals("firstDeviceNextChannel")) {
80                                            assignFirstMidiDeviceNextChannel();
81                                    }
82                                    
83                                    s = p.getStringProperty(DEFAULT_AUDIO_OUTPUT);
84                                    if(s != null && s.equals("firstDevice")) {
85                                            assignFirstAudioDevice();
86                                    }
87                            } catch(Exception x) {
88                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
89                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);
90                          }                          }
91                  }                  }
92                    
93                    private void
94                    assignFirstMidiDevice() throws Exception {
95                            if(CC.getSamplerModel().getMidiDeviceCount() < 1) return;
96                            int id = CC.getSamplerModel().getMidiDevices()[0].getDeviceId();
97                            CC.getClient().setChannelMidiInputDevice(getResult(), id);
98                    }
99                    
100                    private void
101                    assignFirstMidiDeviceNextChannel() throws Exception {
102                            int channelId = getResult();
103                            if(CC.getSamplerModel().getMidiDeviceCount() < 1) return;
104                            int id = CC.getSamplerModel().getMidiDevices()[0].getDeviceId();
105                            CC.getClient().setChannelMidiInputDevice(channelId, id);
106                            
107                            boolean[] usedChannels = new boolean[16];
108                            for(int i = 0; i < usedChannels.length; i++) usedChannels[i] = false;
109                            
110                            for(SamplerChannelModel m : CC.getSamplerModel().getChannels()) {
111                                    if(m.getChannelId() == channelId) continue;
112                                    if(m.getChannelInfo().getMidiInputDevice() != id) continue;
113                                    if(m.getChannelInfo().getMidiInputPort() != 0) continue;
114                                    int chn = m.getChannelInfo().getMidiInputChannel();
115                                    if(chn >= 0 && chn < 16) usedChannels[chn] = true;
116                            }
117                            
118                            int lastUsed = -1;
119                            for(int i = 0; i < usedChannels.length; i++) {
120                                    if(usedChannels[i]) lastUsed = i;
121                            }
122                            
123                            if(lastUsed == -1) {
124                                    CC.getClient().setChannelMidiInputChannel(channelId, 0);
125                                    return;
126                            }
127                            
128                            if(lastUsed < 15) {
129                                    CC.getClient().setChannelMidiInputChannel(channelId, lastUsed + 1);
130                                    return;
131                            }
132                            
133                            int firstUnused = -1;
134                            for(int i = 0; i < usedChannels.length; i++) {
135                                    if(!usedChannels[i]) {
136                                            firstUnused = i;
137                                            break;
138                                    }
139                            }
140                            
141                            if(firstUnused == -1) {
142                                    CC.getClient().setChannelMidiInputChannel(channelId, 0);
143                                    return;
144                            }
145                            
146                            CC.getClient().setChannelMidiInputChannel(channelId, firstUnused);
147                    }
148                    
149                    private void
150                    assignFirstAudioDevice() throws Exception {
151                            if(CC.getSamplerModel().getAudioDeviceCount() < 1) return;
152                            int id = CC.getSamplerModel().getAudioDevices()[0].getDeviceId();
153                            CC.getClient().setChannelAudioOutputDevice(getResult(), id);
154                    }
155          }          }
156    
157          /**          /**
# Line 298  public class Channel { Line 384  public class Channel {
384          }          }
385                    
386          /**          /**
387             * This task loads a sampler engine in a specific sampler channel.
388             * @author Grigor Iliev
389             */
390            public static class LoadEngine extends EnhancedTask {
391                    private String engine;
392                    private int channel;
393                    
394                    /**
395                     * Creates new instance of <code>LoadEngine</code>.
396                     * @param engine The name of the engine to load.
397                     * @param channel The number of the sampler channel
398                     * the deployed engine should be assigned to.
399                     */
400                    public
401                    LoadEngine(String engine, int channel) {
402                            this.engine = engine;
403                            this.channel = channel;
404                            
405                            setTitle("Channel.LoadEngine_task");
406                            
407                            Object[] objs = { engine, new Integer(channel) };
408                            setDescription(i18n.getMessage("Channel.LoadEngine.desc", objs));
409                    }
410                    
411                    /** The entry point of the task. */
412                    public void
413                    run() {
414                            try { CC.getClient().loadSamplerEngine(engine, channel); }
415                            catch(Exception x) {
416                                    setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
417                                    CC.getLogger().log(Level.FINE, getErrorMessage(), x);
418                            }
419                    }
420            }
421            
422            /**
423             * This task loads and assigns an instrument to a sampler channel.
424             * @author Grigor Iliev
425             */
426            public static class LoadInstrument extends EnhancedTask {
427                    private String filename;
428                    private int instrIndex;
429                    private int channel;
430                    
431                    /**
432                     * Creates new instance of <code>LoadInstrument</code>.
433                     * @param filename The name of the instrument file
434                     * on the LinuxSampler instance's host system.
435                     * @param instrIndex The index of the instrument in the instrument file.
436                     * @param channel The number of the sampler channel the
437                     * instrument should be assigned to.
438                     */
439                    public
440                    LoadInstrument(String filename, int instrIndex, int channel) {
441                            this.filename = filename;
442                            this.instrIndex = instrIndex;
443                            this.channel = channel;
444                            
445                            setTitle("Channel.LoadInstrument_task");
446                            setDescription(i18n.getMessage("Channel.LoadInstrument.desc"));
447                    }
448                    
449                    /** The entry point of the task. */
450                    public void
451                    run() {
452                            try { CC.getClient().loadInstrument(filename, instrIndex, channel, true); }
453                            catch(Exception x) {
454                                    setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
455                                    CC.getLogger().log(Level.FINE, getErrorMessage(), x);
456                            }
457                    }
458            }
459            
460            /**
461           * This task assigns the specifed MIDI instrument map to the specified sampler channel.           * This task assigns the specifed MIDI instrument map to the specified sampler channel.
462           */           */
463          public static class SetMidiInstrumentMap extends EnhancedTask {          public static class SetMidiInstrumentMap extends EnhancedTask {
# Line 653  public class Channel { Line 813  public class Channel {
813                  run() {                  run() {
814                          try {                          try {
815                                  SamplerChannelModel scm;                                  SamplerChannelModel scm;
816                                  scm = CC.getSamplerModel().getChannelModel(channel);                                  scm = CC.getSamplerModel().getChannelById(channel);
817                                  Integer[] fxSendIDs = CC.getClient().getFxSendIDs(channel);                                  Integer[] fxSendIDs = CC.getClient().getFxSendIDs(channel);
818                                                    
819                                  boolean found = false;                                  boolean found = false;
# Line 714  public class Channel { Line 874  public class Channel {
874                  run() {                  run() {
875                          try {                          try {
876                                  SamplerChannelModel scm;                                  SamplerChannelModel scm;
877                                  scm = CC.getSamplerModel().getChannelModel(channel);                                  scm = CC.getSamplerModel().getChannelById(channel);
878                                  scm.updateFxSend(CC.getClient().getFxSendInfo(channel, fxSend));                                  scm.updateFxSend(CC.getClient().getFxSendInfo(channel, fxSend));
879                          } catch(Exception x) {                          } catch(Exception x) {
880                                  /*                                  /*

Legend:
Removed from v.1144  
changed lines
  Added in v.1313

  ViewVC Help
Powered by ViewVC