/[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 1204 by iliev, Thu May 24 21:43:45 2007 UTC revision 1445 by iliev, Mon Oct 15 20:55:33 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 956  public class Channel { Line 1054  public class Channel {
1054                          catch(Exception x) {                          catch(Exception x) {
1055                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
1056                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);
1057                            }
1058                    }
1059            }
1060    
1061            /**
1062             * This task starts an instrument editor for editing the loaded instrument
1063             * on the specified sampler channel.
1064             */
1065            public static class EditInstrument extends EnhancedTask {
1066                    private int chn;
1067                    
1068                    /**
1069                     * Creates new instance of <code>EditInstrument</code>.
1070                     * @param channel The sampler channel number.
1071                     */
1072                    public
1073                    EditInstrument(int channel) {
1074                            setTitle("Channel.EditInstrument_task");
1075                            String s = i18n.getMessage("Channel.EditInstrument.desc");
1076                            setDescription(s);
1077                            
1078                            this.chn = channel;
1079                    }
1080            
1081                    /** The entry point of the task. */
1082                    public void
1083                    run() {
1084                            try { CC.getClient().editChannelInstrument(chn); }
1085                            catch(Exception x) {
1086                                    setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
1087                                    CC.getLogger().log(Level.FINE, getErrorMessage(), x);
1088                          }                          }
1089                  }                  }
1090          }          }

Legend:
Removed from v.1204  
changed lines
  Added in v.1445

  ViewVC Help
Powered by ViewVC