/[svn]/jsampler/trunk/src/org/jsampler/view/std/SamplerBrowser.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/std/SamplerBrowser.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2195 - (show annotations) (download)
Tue Jun 28 22:44:39 2011 UTC (12 years, 10 months ago) by iliev
File size: 9400 byte(s)
* Sampler Browser (work in progress): initial implementation of main pane

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2011 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 package org.jsampler.view.std;
23
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.awt.event.MouseAdapter;
27 import java.awt.event.MouseEvent;
28
29 import javax.swing.JMenuItem;
30 import javax.swing.JPopupMenu;
31
32 import org.jsampler.CC;
33 import org.jsampler.EffectInstance;
34 import org.jsampler.view.SamplerTreeModel.*;
35
36 import org.linuxsampler.lscp.EffectParameter;
37
38 import static org.jsampler.view.std.StdA4n.a4n;
39 import static org.jsampler.view.std.StdI18n.i18n;
40
41 /**
42 *
43 * @author Grigor Iliev
44 */
45 public class SamplerBrowser {
46
47
48 private static class SamplerMenu extends JPopupMenu {
49 public
50 SamplerMenu() {
51 JMenuItem mi = new JMenuItem(a4n.refresh);
52 add(mi);
53
54 mi = new JMenuItem(a4n.resetSampler);
55 add(mi);
56 }
57 }
58
59 private static class AudioDeviceMenu extends JPopupMenu {
60 public
61 AudioDeviceMenu() {
62 String s = i18n.getMenuLabel("SamplerBrowser.action.removeAudioDev");
63 JMenuItem mi = new JMenuItem(s);
64 add(mi);
65 mi.addActionListener(new ActionListener() {
66 public void
67 actionPerformed(ActionEvent e) {
68 AudioDeviceTreeNode node = getAudioDeviceTreeNode();
69 if(node == null) return;
70
71 int id = node.getAudioDevice().getDeviceId();
72 CC.getSamplerModel().removeBackendAudioDevice(id);
73 }
74 });
75 }
76
77 private AudioDeviceTreeNode
78 getAudioDeviceTreeNode() {
79 if(ContextMenu.getCurrentOwner() == null) return null;
80 Object o = ContextMenu.getCurrentOwner().getSelectedItem();
81 if(o == null || !(o instanceof AudioDeviceTreeNode)) return null;
82 return (AudioDeviceTreeNode)o;
83 }
84 }
85
86 private static class SendEffectChainDirMenu extends JPopupMenu {
87 public
88 SendEffectChainDirMenu() {
89 String s = i18n.getMenuLabel("SamplerBrowser.action.addChain");
90 JMenuItem mi = new JMenuItem(s);
91 add(mi);
92 mi.addActionListener(new ActionListener() {
93 public void
94 actionPerformed(ActionEvent e) {
95 SendEffectChainsTreeNode node = getSendEffectChainsTreeNode();
96 if(node == null) return;
97 node.getAudioDevice().addBackendSendEffectChain();
98 }
99 });
100 }
101
102 private SendEffectChainsTreeNode
103 getSendEffectChainsTreeNode() {
104 if(ContextMenu.getCurrentOwner() == null) return null;
105 Object o = ContextMenu.getCurrentOwner().getSelectedItem();
106 if(o == null || !(o instanceof SendEffectChainsTreeNode)) return null;
107 return (SendEffectChainsTreeNode)o;
108 }
109 }
110
111 private static class SendEffectChainMenu extends JPopupMenu {
112 public
113 SendEffectChainMenu() {
114 String s = i18n.getMenuLabel("SamplerBrowser.action.removeChain");
115 JMenuItem mi = new JMenuItem(s);
116 add(mi);
117 mi.addActionListener(new ActionListener() {
118 public void
119 actionPerformed(ActionEvent e) {
120 SendEffectChainTreeNode node = getSendEffectChainTreeNode();
121 if(node == null) return;
122
123 node.getAudioDevice().removeBackendSendEffectChain(node.getChainId());
124 }
125 });
126
127 s = i18n.getMenuLabel("SamplerBrowser.action.appendEffectInstance");
128 mi = new JMenuItem(s);
129 add(mi);
130 mi.addActionListener(new ActionListener() {
131 public void
132 actionPerformed(ActionEvent e) {
133 SendEffectChainTreeNode node = getSendEffectChainTreeNode();
134 if(node == null) return;
135
136 JSAddEffectInstancesDlg dlg = new JSAddEffectInstancesDlg();
137 dlg.setVisible(true);
138 if(dlg.isCancelled()) return;
139
140 node.getAudioDevice().addBackendEffectInstances (
141 dlg.getSelectedEffects(), node.getChainId(), -1
142 );
143 }
144 });
145 }
146
147 private SendEffectChainTreeNode
148 getSendEffectChainTreeNode() {
149 if(ContextMenu.getCurrentOwner() == null) return null;
150 Object o = ContextMenu.getCurrentOwner().getSelectedItem();
151 if(o == null || !(o instanceof SendEffectChainTreeNode)) return null;
152 return (SendEffectChainTreeNode)o;
153 }
154 }
155
156 private static class EffectInstanceMenu extends JPopupMenu {
157 public
158 EffectInstanceMenu() {
159 String s = i18n.getMenuLabel("SamplerBrowser.action.removeEffectInstance");
160 JMenuItem mi = new JMenuItem(s);
161 add(mi);
162 mi.addActionListener(new ActionListener() {
163 public void
164 actionPerformed(ActionEvent e) {
165 EffectInstanceTreeNode node = getEffectInstanceTreeNode();
166 if(node == null) return;
167
168 node.getParent().getAudioDevice().removeBackendEffectInstance (
169 node.getParent().getChainId(), node.getInstanceId()
170 );
171 }
172 });
173
174 s = i18n.getMenuLabel("SamplerBrowser.action.insertEffectInstance");
175 mi = new JMenuItem(s);
176 add(mi);
177 mi.addActionListener(new ActionListener() {
178 public void
179 actionPerformed(ActionEvent e) {
180 EffectInstanceTreeNode node = getEffectInstanceTreeNode();
181 if(node == null) return;
182
183 JSAddEffectInstancesDlg dlg = new JSAddEffectInstancesDlg();
184 dlg.setVisible(true);
185 if(dlg.isCancelled()) return;
186
187 SendEffectChainTreeNode parent = node.getParent();
188 int idx = parent.getEffectChain().getIndex(node.getInstanceId());
189
190 parent.getAudioDevice().addBackendEffectInstances (
191 dlg.getSelectedEffects(), parent.getChainId(), idx
192 );
193 }
194 });
195 }
196
197 private EffectInstanceTreeNode
198 getEffectInstanceTreeNode() {
199 if(ContextMenu.getCurrentOwner() == null) return null;
200 Object o = ContextMenu.getCurrentOwner().getSelectedItem();
201 if(o == null || !(o instanceof EffectInstanceTreeNode)) return null;
202 return (EffectInstanceTreeNode)o;
203 }
204 }
205
206 private static class EffectParameterMenu extends JPopupMenu {
207 public
208 EffectParameterMenu() {
209 String s = i18n.getMenuLabel("SamplerBrowser.action.editEffectPrm");
210 JMenuItem mi = new JMenuItem(s);
211 add(mi);
212 mi.addActionListener(new ActionListener() {
213 public void
214 actionPerformed(ActionEvent e) { editParameter(); }
215 });
216 }
217
218 private void
219 editParameter() {
220 EffectParameter prm = getEffectParameter();
221 if(prm == null) return;
222
223 JSSetParameterDlg dlg = new JSSetParameterDlg(prm);
224
225 dlg.setVisible(true);
226 if(dlg.isCancelled()) return;
227
228 EffectInstance ei;
229 ei = CC.getSamplerModel().getEffectInstanceById(prm.getEffectInstanceId());
230 if(ei == null) return;
231 ei.setBackendParameter(prm.getIndex(), dlg.getNewValue());
232 }
233
234 private EffectParameter
235 getEffectParameter() {
236 if(ContextMenu.getCurrentOwner() == null) return null;
237 Object o = ContextMenu.getCurrentOwner().getSelectedItem();
238 if(o == null || !(o instanceof EffectParameter)) return null;
239 return (EffectParameter)o;
240 }
241 }
242
243 public static class ContextMenu extends MouseAdapter {
244 private static ContextMenuOwner currentOwner;
245
246 private static SamplerMenu samplerMenu = null;
247 private static AudioDeviceMenu auDevMenu = null;
248 private static SendEffectChainDirMenu chainDirMenu = null;
249 private static SendEffectChainMenu chainMenu = null;
250 private static EffectInstanceMenu instanceMenu = null;
251 private static EffectParameterMenu effectPrmMenu = null;
252
253 private final ContextMenuOwner owner;
254
255 public
256 ContextMenu(ContextMenuOwner owner) {
257 this.owner = owner;
258 }
259
260 public static ContextMenuOwner
261 getCurrentOwner() { return currentOwner; }
262
263 @Override
264 public void
265 mousePressed(MouseEvent e) {
266 if(e.isPopupTrigger()) show(e);
267 }
268
269 @Override
270 public void
271 mouseReleased(MouseEvent e) {
272 if(e.isPopupTrigger()) show(e);
273 }
274
275 void
276 show(MouseEvent e) {
277 Object o = owner.getSelectedItem();
278 if(o == null) return;
279
280 currentOwner = owner;
281
282 if(o instanceof SamplerTreeNode) {
283 if(samplerMenu == null) samplerMenu = new SamplerMenu();
284 samplerMenu.show(e.getComponent(), e.getX(), e.getY());
285 } else if(o instanceof AudioDeviceTreeNode) {
286 if(auDevMenu == null) auDevMenu = new AudioDeviceMenu();
287 auDevMenu.show(e.getComponent(), e.getX(), e.getY());
288 } else if(o instanceof SendEffectChainsTreeNode) {
289 if(chainDirMenu == null) chainDirMenu = new SendEffectChainDirMenu();
290 chainDirMenu.show(e.getComponent(), e.getX(), e.getY());
291 } else if(o instanceof SendEffectChainTreeNode) {
292 if(chainMenu == null) chainMenu = new SendEffectChainMenu();
293 chainMenu.show(e.getComponent(), e.getX(), e.getY());
294 } else if(o instanceof EffectInstanceTreeNode) {
295 if(instanceMenu == null) instanceMenu = new EffectInstanceMenu();
296 instanceMenu.show(e.getComponent(), e.getX(), e.getY());
297 } else if(o instanceof EffectParameter) {
298 if(effectPrmMenu == null) effectPrmMenu = new EffectParameterMenu();
299 effectPrmMenu.show(e.getComponent(), e.getX(), e.getY());
300 }
301
302 }
303 }
304
305 public static interface ContextMenuOwner {
306 public Object getSelectedItem();
307 }
308 }

  ViewVC Help
Powered by ViewVC