/[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 1334 by iliev, Sun Sep 9 17:43:30 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                                    int chnId = getResult();
68                                    
69                                    JSPrefs p = CC.getViewConfig().preferences();
70                                    if(!p.getBoolProperty(USE_CHANNEL_DEFAULTS)) return;
71                                    
72                                    String s = p.getStringProperty(DEFAULT_ENGINE);
73                                    if(s != null && s.length() > 0) {
74                                            CC.getClient().loadSamplerEngine(s, chnId);
75                                    }
76                                    
77                                    s = p.getStringProperty(DEFAULT_MIDI_INPUT);
78                                    if(s != null && s.equals("firstDevice")) {
79                                            assignFirstMidiDevice();
80                                    } else if(s != null && s.equals("firstDeviceNextChannel")) {
81                                            assignFirstMidiDeviceNextChannel();
82                                    }
83                                    
84                                    s = p.getStringProperty(DEFAULT_AUDIO_OUTPUT);
85                                    if(s != null && s.equals("firstDevice")) {
86                                            assignFirstAudioDevice();
87                                    }
88                                    
89                                    s = p.getStringProperty(DEFAULT_MIDI_INSTRUMENT_MAP);
90                                    if(s != null && s.equals("midiInstrumentMap.none")) {
91                                            CC.getClient().setChannelMidiInstrumentMap(chnId, -1);
92                                    } else if(s != null && s.equals("midiInstrumentMap.default")) {
93                                            CC.getClient().setChannelMidiInstrumentMap(chnId, -2);
94                                    }
95                                    
96                                    float volume = p.getIntProperty(DEFAULT_CHANNEL_VOLUME);
97                                    volume /= 100;
98                                    CC.getClient().setChannelVolume(chnId, volume);
99                            } catch(Exception x) {
100                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
101                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);
102                          }                          }
103                  }                  }
104                    
105                    private void
106                    assignFirstMidiDevice() throws Exception {
107                            if(CC.getSamplerModel().getMidiDeviceCount() < 1) return;
108                            int id = CC.getSamplerModel().getMidiDevices()[0].getDeviceId();
109                            CC.getClient().setChannelMidiInputDevice(getResult(), id);
110                    }
111                    
112                    private void
113                    assignFirstMidiDeviceNextChannel() throws Exception {
114                            int channelId = getResult();
115                            if(CC.getSamplerModel().getMidiDeviceCount() < 1) return;
116                            int id = CC.getSamplerModel().getMidiDevices()[0].getDeviceId();
117                            CC.getClient().setChannelMidiInputDevice(channelId, id);
118                            
119                            boolean[] usedChannels = new boolean[16];
120                            for(int i = 0; i < usedChannels.length; i++) usedChannels[i] = false;
121                            
122                            for(SamplerChannelModel m : CC.getSamplerModel().getChannels()) {
123                                    if(m.getChannelId() == channelId) continue;
124                                    if(m.getChannelInfo().getMidiInputDevice() != id) continue;
125                                    if(m.getChannelInfo().getMidiInputPort() != 0) continue;
126                                    int chn = m.getChannelInfo().getMidiInputChannel();
127                                    if(chn >= 0 && chn < 16) usedChannels[chn] = true;
128                            }
129                            
130                            int lastUsed = -1;
131                            for(int i = 0; i < usedChannels.length; i++) {
132                                    if(usedChannels[i]) lastUsed = i;
133                            }
134                            
135                            if(lastUsed == -1) {
136                                    CC.getClient().setChannelMidiInputChannel(channelId, 0);
137                                    return;
138                            }
139                            
140                            if(lastUsed < 15) {
141                                    CC.getClient().setChannelMidiInputChannel(channelId, lastUsed + 1);
142                                    return;
143                            }
144                            
145                            int firstUnused = -1;
146                            for(int i = 0; i < usedChannels.length; i++) {
147                                    if(!usedChannels[i]) {
148                                            firstUnused = i;
149                                            break;
150                                    }
151                            }
152                            
153                            if(firstUnused == -1) {
154                                    CC.getClient().setChannelMidiInputChannel(channelId, 0);
155                                    return;
156                            }
157                            
158                            CC.getClient().setChannelMidiInputChannel(channelId, firstUnused);
159                    }
160                    
161                    private void
162                    assignFirstAudioDevice() throws Exception {
163                            if(CC.getSamplerModel().getAudioDeviceCount() < 1) return;
164                            int id = CC.getSamplerModel().getAudioDevices()[0].getDeviceId();
165                            CC.getClient().setChannelAudioOutputDevice(getResult(), id);
166                    }
167          }          }
168    
169          /**          /**
# Line 298  public class Channel { Line 396  public class Channel {
396          }          }
397                    
398          /**          /**
399             * This task loads a sampler engine in a specific sampler channel.
400             * @author Grigor Iliev
401             */
402            public static class LoadEngine extends EnhancedTask {
403                    private String engine;
404                    private int channel;
405                    
406                    /**
407                     * Creates new instance of <code>LoadEngine</code>.
408                     * @param engine The name of the engine to load.
409                     * @param channel The number of the sampler channel
410                     * the deployed engine should be assigned to.
411                     */
412                    public
413                    LoadEngine(String engine, int channel) {
414                            this.engine = engine;
415                            this.channel = channel;
416                            
417                            setTitle("Channel.LoadEngine_task");
418                            
419                            Object[] objs = { engine, new Integer(channel) };
420                            setDescription(i18n.getMessage("Channel.LoadEngine.desc", objs));
421                    }
422                    
423                    /** The entry point of the task. */
424                    public void
425                    run() {
426                            try { CC.getClient().loadSamplerEngine(engine, channel); }
427                            catch(Exception x) {
428                                    setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
429                                    CC.getLogger().log(Level.FINE, getErrorMessage(), x);
430                            }
431                    }
432            }
433            
434            /**
435             * This task loads and assigns an instrument to a sampler channel.
436             * @author Grigor Iliev
437             */
438            public static class LoadInstrument extends EnhancedTask {
439                    private String filename;
440                    private int instrIndex;
441                    private int channel;
442                    
443                    /**
444                     * Creates new instance of <code>LoadInstrument</code>.
445                     * @param filename The name of the instrument file
446                     * on the LinuxSampler instance's host system.
447                     * @param instrIndex The index of the instrument in the instrument file.
448                     * @param channel The number of the sampler channel the
449                     * instrument should be assigned to.
450                     */
451                    public
452                    LoadInstrument(String filename, int instrIndex, int channel) {
453                            this.filename = filename;
454                            this.instrIndex = instrIndex;
455                            this.channel = channel;
456                            
457                            setTitle("Channel.LoadInstrument_task");
458                            setDescription(i18n.getMessage("Channel.LoadInstrument.desc"));
459                    }
460                    
461                    /** The entry point of the task. */
462                    public void
463                    run() {
464                            try { CC.getClient().loadInstrument(filename, instrIndex, channel, true); }
465                            catch(Exception x) {
466                                    setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
467                                    CC.getLogger().log(Level.FINE, getErrorMessage(), x);
468                            }
469                    }
470            }
471            
472            /**
473           * 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.
474           */           */
475          public static class SetMidiInstrumentMap extends EnhancedTask {          public static class SetMidiInstrumentMap extends EnhancedTask {
# Line 653  public class Channel { Line 825  public class Channel {
825                  run() {                  run() {
826                          try {                          try {
827                                  SamplerChannelModel scm;                                  SamplerChannelModel scm;
828                                  scm = CC.getSamplerModel().getChannelModel(channel);                                  scm = CC.getSamplerModel().getChannelById(channel);
829                                  Integer[] fxSendIDs = CC.getClient().getFxSendIDs(channel);                                  Integer[] fxSendIDs = CC.getClient().getFxSendIDs(channel);
830                                                    
831                                  boolean found = false;                                  boolean found = false;
# Line 714  public class Channel { Line 886  public class Channel {
886                  run() {                  run() {
887                          try {                          try {
888                                  SamplerChannelModel scm;                                  SamplerChannelModel scm;
889                                  scm = CC.getSamplerModel().getChannelModel(channel);                                  scm = CC.getSamplerModel().getChannelById(channel);
890                                  scm.updateFxSend(CC.getClient().getFxSendInfo(channel, fxSend));                                  scm.updateFxSend(CC.getClient().getFxSendInfo(channel, fxSend));
891                          } catch(Exception x) {                          } catch(Exception x) {
892                                  /*                                  /*

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

  ViewVC Help
Powered by ViewVC