1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
24 |
|
|
25 |
import java.util.Vector; |
import java.util.Vector; |
26 |
|
|
27 |
import javax.swing.event.ChangeEvent; |
import net.sf.juife.event.GenericEvent; |
28 |
import javax.swing.event.ChangeListener; |
import net.sf.juife.event.GenericListener; |
29 |
|
|
30 |
import org.jsampler.event.OrchestraAdapter; |
import org.jsampler.event.OrchestraAdapter; |
31 |
import org.jsampler.event.OrchestraEvent; |
import org.jsampler.event.OrchestraEvent; |
60 |
* Registers the specified listener for receiving event messages. |
* Registers the specified listener for receiving event messages. |
61 |
* @param l The <code>OrchestraListener</code> to register. |
* @param l The <code>OrchestraListener</code> to register. |
62 |
*/ |
*/ |
63 |
|
@Override |
64 |
public void |
public void |
65 |
addOrchestraListener(OrchestraListener l) { listeners.add(l); } |
addOrchestraListener(OrchestraListener l) { listeners.add(l); } |
66 |
|
|
68 |
* Removes the specified listener. |
* Removes the specified listener. |
69 |
* @param l The <code>OrchestraListener</code> to remove. |
* @param l The <code>OrchestraListener</code> to remove. |
70 |
*/ |
*/ |
71 |
|
@Override |
72 |
public void |
public void |
73 |
removeOrchestraListener(OrchestraListener l) { listeners.remove(l); } |
removeOrchestraListener(OrchestraListener l) { listeners.remove(l); } |
74 |
|
|
76 |
* Gets the name of this orchestra. |
* Gets the name of this orchestra. |
77 |
* @return The name of this orchestra. |
* @return The name of this orchestra. |
78 |
*/ |
*/ |
79 |
|
@Override |
80 |
public String |
public String |
81 |
getName() { return name; } |
getName() { return name; } |
82 |
|
|
84 |
* Sets the name of this orchestra. |
* Sets the name of this orchestra. |
85 |
* @param name The new name of this orchestra. |
* @param name The new name of this orchestra. |
86 |
*/ |
*/ |
87 |
|
@Override |
88 |
public void |
public void |
89 |
setName(String name) { |
setName(String name) { |
90 |
this.name = name; |
this.name = name; |
95 |
* Returns the name of this orchestra. |
* Returns the name of this orchestra. |
96 |
* @return The name of this orchestra. |
* @return The name of this orchestra. |
97 |
*/ |
*/ |
98 |
|
@Override |
99 |
public String |
public String |
100 |
toString() { return getName(); } |
toString() { return getName(); } |
101 |
|
|
103 |
* Gets a brief description about this orchestra. |
* Gets a brief description about this orchestra. |
104 |
* @return A brief description about this orchestra. |
* @return A brief description about this orchestra. |
105 |
*/ |
*/ |
106 |
|
@Override |
107 |
public String |
public String |
108 |
getDescription() { return description; } |
getDescription() { return description; } |
109 |
|
|
111 |
* Sets a description about this orchestra. |
* Sets a description about this orchestra. |
112 |
* @param desc A brief description about this orchestra. |
* @param desc A brief description about this orchestra. |
113 |
*/ |
*/ |
114 |
|
@Override |
115 |
public void |
public void |
116 |
setDescription(String desc) { |
setDescription(String desc) { |
117 |
description = desc; |
description = desc; |
122 |
* Gets the current number of instruments in this orchestra. |
* Gets the current number of instruments in this orchestra. |
123 |
* @return The current number of instruments in this orchestra. |
* @return The current number of instruments in this orchestra. |
124 |
*/ |
*/ |
125 |
|
@Override |
126 |
public int |
public int |
127 |
getInstrumentCount() { return instruments.size(); } |
getInstrumentCount() { return instruments.size(); } |
128 |
|
|
131 |
* @param idx The index of the instrument to be returned. |
* @param idx The index of the instrument to be returned. |
132 |
* @return The instrument at the specified position. |
* @return The instrument at the specified position. |
133 |
*/ |
*/ |
134 |
|
@Override |
135 |
public OrchestraInstrument |
public OrchestraInstrument |
136 |
getInstrument(int idx) { return instruments.get(idx); } |
getInstrument(int idx) { return instruments.get(idx); } |
137 |
|
|
140 |
* @param instr The instrument to be added. |
* @param instr The instrument to be added. |
141 |
* @throws IllegalArgumentException If <code>instr</code> is <code>null</code>. |
* @throws IllegalArgumentException If <code>instr</code> is <code>null</code>. |
142 |
*/ |
*/ |
143 |
|
@Override |
144 |
public void |
public void |
145 |
addInstrument(OrchestraInstrument instr) { |
addInstrument(OrchestraInstrument instr) { |
146 |
insertInstrument(instr, getInstrumentCount()); |
insertInstrument(instr, getInstrumentCount()); |
153 |
* @throws IllegalArgumentException If <code>instr</code> is <code>null</code>. |
* @throws IllegalArgumentException If <code>instr</code> is <code>null</code>. |
154 |
* @throws ArrayIndexOutOfBoundsException If the specified index is invalid. |
* @throws ArrayIndexOutOfBoundsException If the specified index is invalid. |
155 |
*/ |
*/ |
156 |
|
@Override |
157 |
public void |
public void |
158 |
insertInstrument(OrchestraInstrument instr, int idx) { |
insertInstrument(OrchestraInstrument instr, int idx) { |
159 |
if(instr == null) throw new IllegalArgumentException("instr should be non-null!"); |
if(instr == null) throw new IllegalArgumentException("instr should be non-null!"); |
165 |
* Removes the specified instrument from this orchestra. |
* Removes the specified instrument from this orchestra. |
166 |
* @param idx The index of the instrument to remove. |
* @param idx The index of the instrument to remove. |
167 |
*/ |
*/ |
168 |
|
@Override |
169 |
public void |
public void |
170 |
removeInstrument(int idx) { |
removeInstrument(int idx) { |
171 |
OrchestraInstrument instr = instruments.get(idx); |
OrchestraInstrument instr = instruments.get(idx); |
179 |
* @return <code>true</code> if the specified instrument was in this orchestra, |
* @return <code>true</code> if the specified instrument was in this orchestra, |
180 |
* <code>false</code> otherwise. |
* <code>false</code> otherwise. |
181 |
*/ |
*/ |
182 |
|
@Override |
183 |
public boolean |
public boolean |
184 |
removeInstrument(OrchestraInstrument instr) { |
removeInstrument(OrchestraInstrument instr) { |
185 |
boolean b = instruments.removeElement(instr); |
boolean b = instruments.removeElement(instr); |
194 |
* and -1 if <code>instr</code> is <code>null</code> or |
* and -1 if <code>instr</code> is <code>null</code> or |
195 |
* the orchestra does not contain the specified instrument. |
* the orchestra does not contain the specified instrument. |
196 |
*/ |
*/ |
197 |
|
@Override |
198 |
public int |
public int |
199 |
getInstrumentIndex(OrchestraInstrument instr) { |
getInstrumentIndex(OrchestraInstrument instr) { |
200 |
if(instr == null) return -1; |
if(instr == null) return -1; |
213 |
* or if the instrument is already on the top. |
* or if the instrument is already on the top. |
214 |
* @param instr The instrument to move on top. |
* @param instr The instrument to move on top. |
215 |
*/ |
*/ |
216 |
|
@Override |
217 |
public void |
public void |
218 |
moveInstrumentOnTop(OrchestraInstrument instr) { |
moveInstrumentOnTop(OrchestraInstrument instr) { |
219 |
if(instr == null) return; |
if(instr == null) return; |
232 |
* or if the instrument is already on the top. |
* or if the instrument is already on the top. |
233 |
* @param instr The instrument to move up. |
* @param instr The instrument to move up. |
234 |
*/ |
*/ |
235 |
|
@Override |
236 |
public void |
public void |
237 |
moveInstrumentUp(OrchestraInstrument instr) { |
moveInstrumentUp(OrchestraInstrument instr) { |
238 |
if(instr == null) return; |
if(instr == null) return; |
252 |
* or if the instrument is already at the bottom. |
* or if the instrument is already at the bottom. |
253 |
* @param instr The instrument to move down. |
* @param instr The instrument to move down. |
254 |
*/ |
*/ |
255 |
|
@Override |
256 |
public void |
public void |
257 |
moveInstrumentDown(OrchestraInstrument instr) { |
moveInstrumentDown(OrchestraInstrument instr) { |
258 |
if(instr == null) return; |
if(instr == null) return; |
270 |
* or if the instrument is already at the bottom. |
* or if the instrument is already at the bottom. |
271 |
* @param instr The instrument to move at bottom. |
* @param instr The instrument to move at bottom. |
272 |
*/ |
*/ |
273 |
|
@Override |
274 |
public void |
public void |
275 |
moveInstrumentAtBottom(OrchestraInstrument instr) { |
moveInstrumentAtBottom(OrchestraInstrument instr) { |
276 |
if(instr == null) return; |
if(instr == null) return; |
288 |
* @throws IllegalArgumentException If an error occurs while |
* @throws IllegalArgumentException If an error occurs while |
289 |
* reading the content of this orchestra. |
* reading the content of this orchestra. |
290 |
*/ |
*/ |
291 |
|
@Override |
292 |
public void |
public void |
293 |
readObject(Node node) { |
readObject(Node node) { |
294 |
if( |
if( |
337 |
* @param node Specifies the node where the content of this orchestra |
* @param node Specifies the node where the content of this orchestra |
338 |
* should be written. |
* should be written. |
339 |
*/ |
*/ |
340 |
|
@Override |
341 |
public void |
public void |
342 |
writeObject(Document doc, Node node) { |
writeObject(Document doc, Node node) { |
343 |
Element el = doc.createElement("orchestra"); |
Element el = doc.createElement("orchestra"); |
398 |
private Handler |
private Handler |
399 |
getHandler() { return eventHandler; } |
getHandler() { return eventHandler; } |
400 |
|
|
401 |
private class Handler extends OrchestraAdapter implements ChangeListener { |
private class Handler extends OrchestraAdapter implements GenericListener { |
402 |
/** Invoked when the settings of an instrument are changed. */ |
/** Invoked when the settings of an instrument are changed. */ |
403 |
public void |
public void |
404 |
stateChanged(ChangeEvent e) { |
jobDone(GenericEvent e) { |
405 |
fireInstrumentChanged((OrchestraInstrument)e.getSource()); |
fireInstrumentChanged((OrchestraInstrument)e.getSource()); |
406 |
} |
} |
407 |
|
|