1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
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 org.jsampler.CC; |
26 |
|
27 |
import org.jsampler.view.JSChannel; |
28 |
|
29 |
import org.linuxsampler.lscp.Client; |
30 |
import org.linuxsampler.lscp.SamplerChannel; |
31 |
|
32 |
import static org.jsampler.JSI18n.i18n; |
33 |
|
34 |
|
35 |
/** |
36 |
* This task duplicates the specified sampler channels. |
37 |
* @author Grigor Iliev |
38 |
*/ |
39 |
public class DuplicateChannels extends EnhancedTask { |
40 |
SamplerChannel[] chnS; |
41 |
|
42 |
/** |
43 |
* Creates a new instance of <code>DuplicateChannels</code>. |
44 |
* @param channel The channel to duplicate. |
45 |
*/ |
46 |
public |
47 |
DuplicateChannels(SamplerChannel channel) { |
48 |
initTask(); |
49 |
|
50 |
chnS = new SamplerChannel[1]; |
51 |
chnS[0] = channel; |
52 |
} |
53 |
|
54 |
/** |
55 |
* Creates a new instance of <code>DuplicateChannels</code>. |
56 |
* @param channels The channels to duplicate. |
57 |
*/ |
58 |
public |
59 |
DuplicateChannels(JSChannel[] channels) { |
60 |
initTask(); |
61 |
|
62 |
chnS = new SamplerChannel[channels.length]; |
63 |
|
64 |
for(int i = 0; i < channels.length; i++) chnS[i] = channels[i].getChannelInfo(); |
65 |
} |
66 |
|
67 |
private void |
68 |
initTask() { |
69 |
setTitle("DuplicateChannels_task"); |
70 |
setDescription(i18n.getMessage("DuplicateChannels.description")); |
71 |
} |
72 |
|
73 |
/** The entry point of the task. */ |
74 |
@Override |
75 |
public void |
76 |
exec() throws Exception { |
77 |
for(SamplerChannel c : chnS) { |
78 |
duplicateSettings(c, CC.getClient().addSamplerChannel()); |
79 |
} |
80 |
} |
81 |
|
82 |
private void |
83 |
duplicateSettings(SamplerChannel sc, int c) throws Exception { |
84 |
Client client = CC.getClient(); |
85 |
|
86 |
if(sc.getMidiInputDevice() >= 0) { |
87 |
client.setChannelMidiInputDevice(c, sc.getMidiInputDevice()); |
88 |
client.setChannelMidiInputPort(c, sc.getMidiInputPort()); |
89 |
client.setChannelMidiInputChannel(c, sc.getMidiInputChannel()); |
90 |
} |
91 |
|
92 |
if(sc.getAudioOutputDevice() >= 0) { |
93 |
client.setChannelAudioOutputDevice(c, sc.getAudioOutputDevice()); |
94 |
} |
95 |
|
96 |
if(sc.getEngine() != null) { |
97 |
client.loadSamplerEngine(sc.getEngine().getName(), c); |
98 |
|
99 |
client.setChannelVolume(c, sc.getVolume()); |
100 |
|
101 |
if(sc.isSoloChannel()) client.setChannelSolo(c, true); |
102 |
|
103 |
if(sc.isMuted() && !sc.isMutedBySolo()) |
104 |
client.setChannelMute(c, true); |
105 |
|
106 |
if(sc.getInstrumentFile() != null) client.loadInstrument ( |
107 |
sc.getInstrumentFile(), sc.getInstrumentIndex(), c, true |
108 |
); |
109 |
} |
110 |
} |
111 |
} |