1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005 Grigor Kirilov Iliev |
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 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 |
* |
40 |
* @author Grigor Iliev |
41 |
*/ |
42 |
public class DuplicateChannels extends EnhancedTask { |
43 |
JSChannel[] channels; |
44 |
|
45 |
public |
46 |
DuplicateChannels(JSChannel[] channels) { |
47 |
this.channels = channels; |
48 |
|
49 |
setTitle("DuplicateChannels_task"); |
50 |
setDescription(i18n.getMessage("DuplicateChannels.description")); |
51 |
} |
52 |
|
53 |
public void |
54 |
run() { |
55 |
try { |
56 |
for(JSChannel c : channels) { |
57 |
int i = CC.getClient().addSamplerChannel(); |
58 |
duplicateSettings(c.getChannelInfo(), i); |
59 |
} |
60 |
} |
61 |
catch(Exception x) { |
62 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
63 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
64 |
} |
65 |
} |
66 |
|
67 |
private void |
68 |
duplicateSettings(SamplerChannel sc, int c) throws Exception { |
69 |
Client client = CC.getClient(); |
70 |
|
71 |
if(sc.getMidiInputDevice() >= 0) { |
72 |
client.setChannelMidiInputDevice(c, sc.getMidiInputDevice()); |
73 |
client.setChannelMidiInputPort(c, sc.getMidiInputPort()); |
74 |
client.setChannelMidiInputChannel(c, sc.getMidiInputChannel()); |
75 |
} |
76 |
|
77 |
if(sc.getAudioOutputDevice() >= 0) { |
78 |
client.setChannelAudioOutputDevice(c, sc.getAudioOutputDevice()); |
79 |
} |
80 |
|
81 |
if(sc.getEngine() != null) { |
82 |
client.loadSamplerEngine(sc.getEngine().getName(), c); |
83 |
|
84 |
client.setChannelVolume(c, sc.getVolume()); |
85 |
|
86 |
if(sc.isSoloChannel()) client.setChannelSolo(c, true); |
87 |
|
88 |
if(sc.isMuted() && !sc.isMutedBySolo()) |
89 |
client.setChannelMute(c, true); |
90 |
|
91 |
if(sc.getInstrumentFile() != null) client.loadInstrument ( |
92 |
sc.getInstrumentFile(), sc.getInstrumentIndex(), c, true |
93 |
); |
94 |
} |
95 |
} |
96 |
} |