1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 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 java.util.logging.Level; |
26 |
|
27 |
import org.jsampler.CC; |
28 |
import org.jsampler.HF; |
29 |
|
30 |
import org.linuxsampler.lscp.ServerInfo; |
31 |
|
32 |
import static org.jsampler.JSI18n.i18n; |
33 |
|
34 |
|
35 |
/** |
36 |
* Provides tasks for managing the global settings of the sampler. |
37 |
* @author Grigor Iliev |
38 |
*/ |
39 |
public class Global { |
40 |
|
41 |
/** Forbits the instantiation of this class. */ |
42 |
private Global() { } |
43 |
|
44 |
/** |
45 |
* This task retrieves information about the LinuxSampler instance. |
46 |
* @author Grigor Iliev |
47 |
*/ |
48 |
public static class GetServerInfo extends EnhancedTask<ServerInfo> { |
49 |
/** Creates a new instance of <code>GetServerInfo</code>. */ |
50 |
public |
51 |
GetServerInfo() { |
52 |
setTitle("Global.GetServerInfo_task"); |
53 |
setDescription(i18n.getMessage("Global.GetServerInfo.desc")); |
54 |
} |
55 |
|
56 |
/** The entry point of the task. */ |
57 |
public void |
58 |
run() { |
59 |
try { setResult(CC.getClient().getServerInfo()); } |
60 |
catch(Exception x) { |
61 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
62 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
63 |
} |
64 |
} |
65 |
} |
66 |
|
67 |
/** |
68 |
* This task resets the whole sampler. |
69 |
* @author Grigor Iliev |
70 |
*/ |
71 |
public static class ResetSampler extends EnhancedTask { |
72 |
/** Creates a new instance of <code>ResetSampler</code>. */ |
73 |
public |
74 |
ResetSampler() { |
75 |
setTitle("Global.ResetSampler_task"); |
76 |
setDescription(i18n.getMessage("Global.ResetSampler.desc")); |
77 |
} |
78 |
|
79 |
/** The entry point of the task. */ |
80 |
public void |
81 |
run() { |
82 |
try { CC.getClient().resetSampler(); } |
83 |
catch(Exception x) { |
84 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
85 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
86 |
} |
87 |
} |
88 |
} |
89 |
|
90 |
/** |
91 |
* This task gets the global volume of the sampler. |
92 |
*/ |
93 |
public static class GetVolume extends EnhancedTask<Float> { |
94 |
/** Creates a new instance of <code>Get</code>. */ |
95 |
public |
96 |
GetVolume() { |
97 |
setTitle("Global.GetVolume_task"); |
98 |
setDescription(i18n.getMessage("Global.GetVolume.desc")); |
99 |
} |
100 |
|
101 |
/** The entry point of the task. */ |
102 |
public void |
103 |
run() { |
104 |
try { setResult(CC.getClient().getVolume()); } |
105 |
catch(Exception x) { |
106 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
107 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
108 |
} |
109 |
} |
110 |
} |
111 |
|
112 |
|
113 |
/** |
114 |
* This task sets the global volume of the sampler. |
115 |
*/ |
116 |
public static class SetVolume extends EnhancedTask { |
117 |
private float volume; |
118 |
|
119 |
/** |
120 |
* Creates new instance of <code>SetVolume</code>. |
121 |
* @param volume The new volume value. |
122 |
*/ |
123 |
public |
124 |
SetVolume(float volume) { |
125 |
setTitle("Global.SetVolume_task"); |
126 |
setDescription(i18n.getMessage("Global.SetVolume.desc")); |
127 |
this.volume = volume; |
128 |
} |
129 |
|
130 |
/** The entry point of the task. */ |
131 |
public void |
132 |
run() { |
133 |
try { |
134 |
CC.getClient().setVolume(volume); |
135 |
} catch(Exception x) { |
136 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
137 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
138 |
} |
139 |
} |
140 |
} |
141 |
} |