24 |
|
|
25 |
import java.util.logging.Level; |
import java.util.logging.Level; |
26 |
|
|
27 |
|
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 |
|
|
33 |
|
|
34 |
|
|
35 |
/** |
/** |
36 |
* |
* This taks sets the volume of a specific sampler channel. |
37 |
* @author Grigor Iliev |
* @author Grigor Iliev |
38 |
*/ |
*/ |
39 |
public class SetChannelVolume extends EnhancedTask { |
public class SetChannelVolume extends EnhancedTask { |
40 |
private int channel; |
private int channel; |
41 |
private float volume; |
private float volume; |
42 |
|
|
43 |
|
/** |
44 |
|
* Creates new instance of <code>SetChannelVolume</code>. |
45 |
|
* @param channel The sampler channel number. |
46 |
|
* @param volume The new volume value. |
47 |
|
*/ |
48 |
public |
public |
49 |
SetChannelVolume(int channel, float volume) { |
SetChannelVolume(int channel, float volume) { |
50 |
setTitle("SetChannelVolume_task"); |
setTitle("SetChannelVolume_task"); |
54 |
this.volume = volume; |
this.volume = volume; |
55 |
} |
} |
56 |
|
|
57 |
|
/** The entry point of the task. */ |
58 |
public void |
public void |
59 |
run() { |
run() { |
60 |
|
/* |
61 |
|
* Because of the rapid flow of volume change tasks in some cases |
62 |
|
* we need to do some optimization to decrease the traffic. |
63 |
|
*/ |
64 |
|
boolean b = true; |
65 |
|
Task[] tS = CC.getTaskQueue().getPendingTasks(); |
66 |
|
|
67 |
|
for(int i = tS.length - 1; i >= 0; i--) { |
68 |
|
Task t = tS[i]; |
69 |
|
|
70 |
|
if(t instanceof SetChannelVolume) { |
71 |
|
SetChannelVolume scv = (SetChannelVolume)t; |
72 |
|
if(scv.getChannelID() == channel) { |
73 |
|
CC.getTaskQueue().removeTask(scv); |
74 |
|
} |
75 |
|
} |
76 |
|
} |
77 |
|
|
78 |
try { CC.getClient().setChannelVolume(channel, volume); } |
try { CC.getClient().setChannelVolume(channel, volume); } |
79 |
catch(Exception x) { |
catch(Exception x) { |
80 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
81 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
82 |
} |
} |
83 |
} |
} |
84 |
|
|
85 |
|
/** |
86 |
|
* Gets the ID of the channel whose volume should be changed. |
87 |
|
* @return The ID of the channel whose volume should be changed. |
88 |
|
*/ |
89 |
|
public int |
90 |
|
getChannelID() { return channel; } |
91 |
} |
} |