1 |
iliev |
787 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1143 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
787 |
* |
6 |
|
|
* This file is part of JSampler. |
7 |
|
|
* |
8 |
|
|
* JSampler is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License version 2 |
10 |
|
|
* as published by the Free Software Foundation. |
11 |
|
|
* |
12 |
|
|
* JSampler is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with JSampler; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
|
|
* MA 02111-1307 USA |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
package org.jsampler.task; |
24 |
|
|
|
25 |
|
|
import java.util.logging.Level; |
26 |
|
|
|
27 |
|
|
import org.jsampler.CC; |
28 |
|
|
import org.jsampler.HF; |
29 |
|
|
|
30 |
|
|
import org.jsampler.view.JSChannel; |
31 |
|
|
|
32 |
|
|
import org.linuxsampler.lscp.Client; |
33 |
|
|
import org.linuxsampler.lscp.SamplerChannel; |
34 |
|
|
|
35 |
|
|
import static org.jsampler.JSI18n.i18n; |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
/** |
39 |
iliev |
911 |
* This task duplicates the specified sampler channels. |
40 |
iliev |
787 |
* @author Grigor Iliev |
41 |
|
|
*/ |
42 |
iliev |
842 |
public class DuplicateChannels extends EnhancedTask { |
43 |
iliev |
911 |
SamplerChannel[] chnS; |
44 |
iliev |
787 |
|
45 |
iliev |
911 |
/** |
46 |
|
|
* Creates a new instance of <code>DuplicateChannels</code>. |
47 |
|
|
* @param channel The channel to duplicate. |
48 |
|
|
*/ |
49 |
iliev |
787 |
public |
50 |
iliev |
911 |
DuplicateChannels(SamplerChannel channel) { |
51 |
|
|
initTask(); |
52 |
|
|
|
53 |
|
|
chnS = new SamplerChannel[1]; |
54 |
|
|
chnS[0] = channel; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* Creates a new instance of <code>DuplicateChannels</code>. |
59 |
|
|
* @param channels The channels to duplicate. |
60 |
|
|
*/ |
61 |
|
|
public |
62 |
iliev |
787 |
DuplicateChannels(JSChannel[] channels) { |
63 |
iliev |
911 |
initTask(); |
64 |
iliev |
787 |
|
65 |
iliev |
911 |
chnS = new SamplerChannel[channels.length]; |
66 |
|
|
|
67 |
|
|
for(int i = 0; i < channels.length; i++) chnS[i] = channels[i].getChannelInfo(); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
private void |
71 |
|
|
initTask() { |
72 |
iliev |
787 |
setTitle("DuplicateChannels_task"); |
73 |
|
|
setDescription(i18n.getMessage("DuplicateChannels.description")); |
74 |
|
|
} |
75 |
|
|
|
76 |
iliev |
911 |
/** The entry point of the task. */ |
77 |
iliev |
787 |
public void |
78 |
|
|
run() { |
79 |
|
|
try { |
80 |
iliev |
911 |
for(SamplerChannel c : chnS) { |
81 |
|
|
duplicateSettings(c, CC.getClient().addSamplerChannel()); |
82 |
iliev |
787 |
} |
83 |
|
|
} |
84 |
|
|
catch(Exception x) { |
85 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
86 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
87 |
|
|
} |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
private void |
91 |
|
|
duplicateSettings(SamplerChannel sc, int c) throws Exception { |
92 |
|
|
Client client = CC.getClient(); |
93 |
|
|
|
94 |
|
|
if(sc.getMidiInputDevice() >= 0) { |
95 |
|
|
client.setChannelMidiInputDevice(c, sc.getMidiInputDevice()); |
96 |
|
|
client.setChannelMidiInputPort(c, sc.getMidiInputPort()); |
97 |
|
|
client.setChannelMidiInputChannel(c, sc.getMidiInputChannel()); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
if(sc.getAudioOutputDevice() >= 0) { |
101 |
|
|
client.setChannelAudioOutputDevice(c, sc.getAudioOutputDevice()); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
if(sc.getEngine() != null) { |
105 |
|
|
client.loadSamplerEngine(sc.getEngine().getName(), c); |
106 |
|
|
|
107 |
|
|
client.setChannelVolume(c, sc.getVolume()); |
108 |
|
|
|
109 |
|
|
if(sc.isSoloChannel()) client.setChannelSolo(c, true); |
110 |
|
|
|
111 |
|
|
if(sc.isMuted() && !sc.isMutedBySolo()) |
112 |
|
|
client.setChannelMute(c, true); |
113 |
|
|
|
114 |
|
|
if(sc.getInstrumentFile() != null) client.loadInstrument ( |
115 |
|
|
sc.getInstrumentFile(), sc.getInstrumentIndex(), c, true |
116 |
|
|
); |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
} |