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

Annotation of /jsampler/trunk/src/org/jsampler/view/std/JSSamplerTree.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2192 - (hide annotations) (download)
Fri Jun 24 21:34:51 2011 UTC (12 years, 10 months ago) by iliev
File size: 6178 byte(s)
* Initial implementation of Sampler Browser
  (choose Window/Sampler Browser) - another way to view/edit
  the sampler configuration (work in progress - for now only
  support for viewing/editing send effects)

1 iliev 2192 /*
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     import javax.swing.tree.TreeSelectionModel;
32    
33     import org.jsampler.CC;
34     import org.jsampler.view.AbstractSamplerTree;
35     import org.jsampler.view.SamplerTreeModel;
36    
37     import static org.jsampler.view.SamplerTreeModel.*;
38     import static org.jsampler.view.std.StdI18n.i18n;
39    
40     /**
41     *
42     * @author Grigor Iliev
43     */
44     public class JSSamplerTree extends AbstractSamplerTree {
45     /**
46     * Creates a new instance of <code>JSSamplerTree</code>.
47     */
48     public
49     JSSamplerTree(SamplerTreeModel model) {
50     super(model);
51     getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
52    
53     addMouseListener(new MouseAdapter() {
54     public void
55     mousePressed(MouseEvent e) {
56     if(e.getButton() != e.BUTTON3) return;
57     setSelectionPath(getClosestPathForLocation(e.getX(), e.getY()));
58     }
59     });
60    
61     ContextMenu contextMenu = new ContextMenu();
62     addMouseListener(contextMenu);
63     }
64    
65     class ContextMenu extends MouseAdapter {
66     private final JPopupMenu aodMenu = new JPopupMenu();
67     private final JPopupMenu secMenu = new JPopupMenu();
68     private final JPopupMenu eiMenu = new JPopupMenu();
69    
70    
71     ContextMenu() {
72     String s = i18n.getMenuLabel("JSSamplerTree.cm.aodMenu.addChain");
73     JMenuItem mi = new JMenuItem(s);
74     aodMenu.add(mi);
75     mi.addActionListener(new ActionListener() {
76     public void
77     actionPerformed(ActionEvent e) {
78     AudioDeviceTreeNode node = getAudioDeviceTreeNode();
79     if(node == null) return;
80     node.getAudioDevice().addBackendSendEffectChain();
81     }
82     });
83    
84     // Send Effect Chain menu
85    
86     s = i18n.getMenuLabel("JSSamplerTree.cm.secMenu.remove");
87     mi = new JMenuItem(s);
88     secMenu.add(mi);
89     mi.addActionListener(new ActionListener() {
90     public void
91     actionPerformed(ActionEvent e) {
92     SendEffectChainTreeNode node = getSendEffectChainTreeNode();
93     if(node == null) return;
94     node.getAudioDevice().removeBackendSendEffectChain(node.getChainId());
95     }
96     });
97    
98     s = i18n.getMenuLabel("JSSamplerTree.cm.secMenu.appendEffectInstance");
99     mi = new JMenuItem(s);
100     secMenu.add(mi);
101     mi.addActionListener(new ActionListener() {
102     public void
103     actionPerformed(ActionEvent e) {
104     SendEffectChainTreeNode node = getSendEffectChainTreeNode();
105     if(node == null) return;
106    
107     JSAddEffectInstancesDlg dlg = new JSAddEffectInstancesDlg();
108     dlg.setVisible(true);
109     if(dlg.isCancelled()) return;
110    
111     node.getAudioDevice().addBackendEffectInstances (
112     dlg.getSelectedEffects(), node.getChainId(), -1
113     );
114     }
115     });
116    
117     // Effect Instance menu
118     s = i18n.getMenuLabel("JSSamplerTree.cm.eiMenu.remove");
119     mi = new JMenuItem(s);
120     eiMenu.add(mi);
121     mi.addActionListener(new ActionListener() {
122     public void
123     actionPerformed(ActionEvent e) {
124     EffectInstanceTreeNode node = getEffectInstanceTreeNode();
125     if(node == null) return;
126    
127     node.getParent().getAudioDevice().removeBackendEffectInstance (
128     node.getParent().getChainId(), node.getInstanceId()
129     );
130     }
131     });
132    
133     s = i18n.getMenuLabel("JSSamplerTree.cm.eiMenu.insertInstances");
134     mi = new JMenuItem(s);
135     eiMenu.add(mi);
136     mi.addActionListener(new ActionListener() {
137     public void
138     actionPerformed(ActionEvent e) {
139     EffectInstanceTreeNode node = getEffectInstanceTreeNode();
140     if(node == null) return;
141    
142     JSAddEffectInstancesDlg dlg = new JSAddEffectInstancesDlg();
143     dlg.setVisible(true);
144     if(dlg.isCancelled()) return;
145    
146     SendEffectChainTreeNode parent = node.getParent();
147     int idx = parent.getEffectChain().getIndex(node.getInstanceId());
148    
149     parent.getAudioDevice().addBackendEffectInstances (
150     dlg.getSelectedEffects(), parent.getChainId(), idx
151     );
152     }
153     });
154     }
155    
156     public void
157     mousePressed(MouseEvent e) {
158     if(e.isPopupTrigger()) show(e);
159     }
160    
161     public void
162     mouseReleased(MouseEvent e) {
163     if(e.isPopupTrigger()) show(e);
164     }
165    
166     void
167     show(MouseEvent e) {
168     Object o = getSelectionModel().getSelectionPath().getLastPathComponent();
169     if(o == null) return;
170     if(o instanceof AudioDeviceTreeNode) {
171     aodMenu.show(e.getComponent(), e.getX(), e.getY());
172     } else if(o instanceof SendEffectChainTreeNode) {
173     secMenu.show(e.getComponent(), e.getX(), e.getY());
174     } else if(o instanceof EffectInstanceTreeNode) {
175     eiMenu.show(e.getComponent(), e.getX(), e.getY());
176     }
177    
178     }
179    
180     private AudioDeviceTreeNode
181     getAudioDeviceTreeNode() {
182     Object o = getSelectionModel().getSelectionPath().getLastPathComponent();
183     if(o == null || !(o instanceof AudioDeviceTreeNode)) return null;
184     return (AudioDeviceTreeNode)o;
185     }
186    
187     private SendEffectChainTreeNode
188     getSendEffectChainTreeNode() {
189     Object o = getSelectionModel().getSelectionPath().getLastPathComponent();
190     if(o == null || !(o instanceof SendEffectChainTreeNode)) return null;
191     return (SendEffectChainTreeNode)o;
192     }
193    
194     private EffectInstanceTreeNode
195     getEffectInstanceTreeNode() {
196     Object o = getSelectionModel().getSelectionPath().getLastPathComponent();
197     if(o == null || !(o instanceof EffectInstanceTreeNode)) return null;
198     return (EffectInstanceTreeNode)o;
199     }
200     }
201     }

  ViewVC Help
Powered by ViewVC