/[svn]/jsampler/trunk/src/org/jsampler/EffectChain.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/EffectChain.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: 3650 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;
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import javax.swing.SwingUtilities;
27 import org.jsampler.event.EffectChainEvent;
28 import org.jsampler.event.EffectChainListener;
29 import org.linuxsampler.lscp.EffectChainInfo;
30 import org.linuxsampler.lscp.EffectInstanceInfo;
31
32
33 /**
34 *
35 * @author Grigor Iliev
36 */
37 public class EffectChain {
38 private int chainId = -1;
39 private final ArrayList<EffectInstance> effectInstances = new ArrayList<EffectInstance>();
40
41 private final ArrayList<EffectChainListener> listeners = new ArrayList<EffectChainListener>();
42
43 public
44 EffectChain(EffectChainInfo chain) {
45 setChainId(chain.getChainId());
46
47 setEffectInstances(chain);
48 }
49
50 /**
51 * Registers the specified listener to be notified when
52 * the settings of the effect chain are changed.
53 * @param l The <code>EffectChainListener</code> to register.
54 */
55 public void
56 addEffectChainListener(EffectChainListener l) { listeners.add(l); }
57
58 /**
59 * Removes the specified listener.
60 * @param l The <code>EffectChainListener</code> to remove.
61 */
62 public void
63 removeEffectChainListener(EffectChainListener l) { listeners.remove(l); }
64
65 /**
66 * Gets the numerical ID of the chain.
67 * @return The numerical ID of the chain or -1 if the ID is not set.
68 */
69 public int
70 getChainId() { return chainId; }
71
72 /** Sets the numerical ID of the chain. */
73 public void
74 setChainId(int id) { chainId = id; }
75
76 public EffectInstance[]
77 getEffectInstances() {
78 return effectInstances.toArray(new EffectInstance[0]);
79 }
80
81 public void
82 setEffectInstances(EffectChainInfo chain) {
83 effectInstances.clear();
84 for(int i = 0; i < chain.getEffectInstanceCount(); i++) {
85 effectInstances.add(new EffectInstance(chain.getEffectInstance(i)));
86 }
87 fireEffectInstanceListChanged();
88
89 }
90
91 public int
92 getEffectInstanceCount() { return effectInstances.size(); }
93
94 public EffectInstance
95 getEffectInstance(int idx) { return effectInstances.get(idx); }
96
97 public int
98 getIndex(int instanceId) {
99 for(int i = 0; i < effectInstances.size(); i++) {
100 if(effectInstances.get(i).getInstanceId() == instanceId) {
101 return i;
102 }
103 }
104 return -1;
105 }
106
107 public EffectInstance
108 getEffectInstanceById(int instanceId) {
109 int idx = getIndex(instanceId);
110 if(idx == -1) return null;
111
112 return effectInstances.get(idx);
113 }
114
115 private void
116 fireEffectInstanceListChanged() {
117 final EffectChainEvent e = new EffectChainEvent(this, this);
118 SwingUtilities.invokeLater(new Runnable() {
119 public void
120 run() { fireEffectInstanceListChanged(e); }
121 });
122 }
123
124 /**
125 * This method should be invoked from the event-dispatching thread.
126 */
127 private void
128 fireEffectInstanceListChanged(EffectChainEvent e) {
129 CC.getSamplerModel().setModified(true);
130 for(EffectChainListener l : listeners) l.effectInstanceListChanged(e);
131 }
132 }

  ViewVC Help
Powered by ViewVC