1 | package org.apollo.gui;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.Dimension;
|
---|
5 | import java.awt.Event;
|
---|
6 | import java.awt.Font;
|
---|
7 | import java.awt.Graphics2D;
|
---|
8 | import java.awt.GridBagConstraints;
|
---|
9 | import java.awt.GridBagLayout;
|
---|
10 | import java.awt.Insets;
|
---|
11 | import java.awt.Point;
|
---|
12 | import java.awt.event.ActionEvent;
|
---|
13 | import java.awt.event.ActionListener;
|
---|
14 |
|
---|
15 | import javax.sound.sampled.LineUnavailableException;
|
---|
16 | import javax.swing.JButton;
|
---|
17 | import javax.swing.JPanel;
|
---|
18 | import javax.swing.JSlider;
|
---|
19 | import javax.swing.JSplitPane;
|
---|
20 | import javax.swing.JToggleButton;
|
---|
21 | import javax.swing.event.ChangeEvent;
|
---|
22 | import javax.swing.event.ChangeListener;
|
---|
23 |
|
---|
24 | import org.apollo.audio.ApolloPlaybackMixer;
|
---|
25 | import org.apollo.audio.ApolloSubjectChangedEvent;
|
---|
26 | import org.apollo.audio.SampledTrackModel;
|
---|
27 | import org.apollo.audio.TrackSequence;
|
---|
28 | import org.apollo.audio.structure.AudioStructureModel;
|
---|
29 | import org.apollo.audio.util.SoundDesk;
|
---|
30 | import org.apollo.audio.util.TrackMixSubject;
|
---|
31 | import org.apollo.io.IconRepository;
|
---|
32 | import org.apollo.items.EmulatedTextItem;
|
---|
33 | import org.apollo.items.EmulatedTextItem.TextChangeListener;
|
---|
34 | import org.apollo.mvc.Observer;
|
---|
35 | import org.apollo.mvc.Subject;
|
---|
36 | import org.apollo.mvc.SubjectChangedEvent;
|
---|
37 | import org.apollo.util.AudioMath;
|
---|
38 | import org.apollo.widgets.TrackWidgetCommons;
|
---|
39 | import org.expeditee.core.Colour;
|
---|
40 | import org.expeditee.core.Image;
|
---|
41 | import org.expeditee.core.bounds.AxisAlignedBoxBounds;
|
---|
42 | import org.expeditee.gio.EcosystemManager;
|
---|
43 | import org.expeditee.gio.input.InputEvent;
|
---|
44 | import org.expeditee.gio.input.InputEventListener;
|
---|
45 | import org.expeditee.gio.swing.SwingConversions;
|
---|
46 | import org.expeditee.gio.swing.SwingMiscManager;
|
---|
47 | import org.expeditee.gui.Browser;
|
---|
48 | import org.expeditee.gui.DisplayController;
|
---|
49 | import org.expeditee.gui.Popup;
|
---|
50 | import org.expeditee.gui.PopupManager.ExpandShrinkAnimator;
|
---|
51 |
|
---|
52 | public class ExpandedTrackPopup extends Popup implements ActionListener, Observer
|
---|
53 | {
|
---|
54 | /** The observed subject. Can never be null */
|
---|
55 | private SampledTrackModel trackModel; // immutable
|
---|
56 |
|
---|
57 | private String trackSourceFrameName; // immutable
|
---|
58 |
|
---|
59 | private TrackMixSubject trackMix; // immutable
|
---|
60 |
|
---|
61 | private JPanel panel;
|
---|
62 | private JButton playPauseButton;
|
---|
63 | private JButton stopButton;
|
---|
64 | private JButton rewindButton;
|
---|
65 | private JButton closeButton;
|
---|
66 | private JToggleButton soloButton;
|
---|
67 | private JToggleButton muteButton;
|
---|
68 | private JSlider volumeSlider;
|
---|
69 | JPanel nameLabelParent;
|
---|
70 |
|
---|
71 | private EmulatedTextItem nameLabel;
|
---|
72 |
|
---|
73 | private JSplitPane splitPane;
|
---|
74 | private SampledTrackGraphViewPort zoomController;
|
---|
75 | private EditableSampledTrackGraphView zoomedTrackView;
|
---|
76 | private TimeAxisPanel timeAxis;
|
---|
77 |
|
---|
78 | private boolean isUpdatingGUI = false;
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Hidden constuctor: only ExpandedTrackManager can create these.
|
---|
82 | *
|
---|
83 | * @see {@link ExpandedTrackManager}
|
---|
84 | *
|
---|
85 | * @param trackModel
|
---|
86 | *
|
---|
87 | * @param trackMix
|
---|
88 | *
|
---|
89 | * @param trackSourceFrameName
|
---|
90 | * Where the expanded tracks track source was expanded from.
|
---|
91 | * Must not be null
|
---|
92 | *
|
---|
93 | * @param frameStart
|
---|
94 | * the initial zoom
|
---|
95 | *
|
---|
96 | * @param frameLength
|
---|
97 | * the initial zoom
|
---|
98 | *
|
---|
99 | * @throws NullPointerException
|
---|
100 | * If trackModel or trackMix is null.
|
---|
101 | */
|
---|
102 | private ExpandedTrackPopup(
|
---|
103 | SampledTrackModel trackModel,
|
---|
104 | TrackMixSubject trackMix,
|
---|
105 | String trackSourceFrameName,
|
---|
106 | int frameStart,
|
---|
107 | int frameLength)
|
---|
108 | {
|
---|
109 | super(new ExpandShrinkAnimator());
|
---|
110 | super.setConsumeBackClick(true);
|
---|
111 |
|
---|
112 | panel = new JPanel(new BorderLayout());
|
---|
113 |
|
---|
114 | if (trackModel == null) throw new NullPointerException("trackModel");
|
---|
115 | if (trackMix == null) throw new NullPointerException("trackMix");
|
---|
116 | if (trackSourceFrameName == null) throw new NullPointerException("trackSourceFrameName");
|
---|
117 |
|
---|
118 | this.trackModel = trackModel;
|
---|
119 | this.trackMix = trackMix;
|
---|
120 |
|
---|
121 | final int BUTTON_SIZE = 40;
|
---|
122 |
|
---|
123 | playPauseButton = new JButton();
|
---|
124 | playPauseButton.addActionListener(this);
|
---|
125 | SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png"));
|
---|
126 | playPauseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
|
---|
127 | playPauseButton.setToolTipText("Play selection / Pause");
|
---|
128 |
|
---|
129 | stopButton = new JButton();
|
---|
130 | stopButton.setEnabled(false);
|
---|
131 | stopButton.addActionListener(this);
|
---|
132 | SwingMiscManager.setJButtonIcon(stopButton, IconRepository.getIcon("stop.png"));
|
---|
133 | stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
|
---|
134 | stopButton.setToolTipText("Stop playback");
|
---|
135 |
|
---|
136 | rewindButton = new JButton();
|
---|
137 | rewindButton.addActionListener(this);
|
---|
138 | SwingMiscManager.setJButtonIcon(rewindButton, IconRepository.getIcon("rewind.png"));
|
---|
139 | rewindButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
|
---|
140 | rewindButton.setToolTipText("Rewind to start");
|
---|
141 |
|
---|
142 | // Icon changes
|
---|
143 | muteButton = new JToggleButton();
|
---|
144 | SwingMiscManager.setJButtonIcon(muteButton, IconRepository.getIcon("volmute.png"));
|
---|
145 | muteButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
|
---|
146 | muteButton.setToolTipText("Toggle mute");
|
---|
147 | muteButton.addChangeListener(new ChangeListener() {
|
---|
148 | public void stateChanged(ChangeEvent e) {
|
---|
149 | if (!ExpandedTrackPopup.this.isUpdatingGUI) {
|
---|
150 | ExpandedTrackPopup.this.trackMix.setMuted(muteButton.isSelected());
|
---|
151 |
|
---|
152 | }
|
---|
153 | }
|
---|
154 | });
|
---|
155 |
|
---|
156 | soloButton = new JToggleButton();
|
---|
157 | SwingMiscManager.setJButtonIcon(soloButton, IconRepository.getIcon("solo.png"));
|
---|
158 | SwingMiscManager.setJButtonSelectedIcon(soloButton, IconRepository.getIcon("soloon.png"));
|
---|
159 | soloButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
|
---|
160 | soloButton.setToolTipText("Toggle solo");
|
---|
161 | soloButton.addChangeListener(new ChangeListener() {
|
---|
162 | public void stateChanged(ChangeEvent e) {
|
---|
163 | if (!ExpandedTrackPopup.this.isUpdatingGUI) {
|
---|
164 | SoundDesk.getInstance().setSoloIDPrefix(soloButton.isSelected() ?
|
---|
165 | ExpandedTrackPopup.this.trackMix.getChannelID() : null
|
---|
166 | );
|
---|
167 |
|
---|
168 | }
|
---|
169 | }
|
---|
170 | });
|
---|
171 |
|
---|
172 | closeButton = new JButton();
|
---|
173 | closeButton.addActionListener(this);
|
---|
174 | SwingMiscManager.setJButtonIcon(closeButton, IconRepository.getIcon("close.png"));
|
---|
175 | closeButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
|
---|
176 | closeButton.setToolTipText("Close");
|
---|
177 |
|
---|
178 | final int VOLUME_SPACING = 6;
|
---|
179 | volumeSlider = new JSlider(JSlider.HORIZONTAL);
|
---|
180 | volumeSlider.setMinimum(0);
|
---|
181 | volumeSlider.setMaximum(100);
|
---|
182 | volumeSlider.addChangeListener(new ChangeListener() {
|
---|
183 | public void stateChanged(ChangeEvent e) {
|
---|
184 | if (!ExpandedTrackPopup.this.isUpdatingGUI) {
|
---|
185 | ExpandedTrackPopup.this.trackMix.setVolume(((float)volumeSlider.getValue()) / 100.0f);
|
---|
186 | }
|
---|
187 | // Update the icons
|
---|
188 | updateButtonGUI();
|
---|
189 | }
|
---|
190 | });
|
---|
191 | volumeSlider.setPreferredSize(new Dimension(100 - (2 * VOLUME_SPACING), BUTTON_SIZE));
|
---|
192 |
|
---|
193 | zoomedTrackView = new EditableSampledTrackGraphView();
|
---|
194 | zoomedTrackView.setSelectAllOnDoubleClick(true);
|
---|
195 |
|
---|
196 | zoomController = new SampledTrackGraphViewPort();
|
---|
197 |
|
---|
198 | // Keep timescale in zoomedTrackView consistance with zoom controller
|
---|
199 | zoomController.addZoomChangeListener(new ZoomChangeListener() {
|
---|
200 |
|
---|
201 | public void zoomChanged(Event e) {
|
---|
202 |
|
---|
203 | int minFrame = Math.min(
|
---|
204 | zoomController.getZoomStartFrame(), zoomController.getZoomEndFrame());
|
---|
205 |
|
---|
206 | int maxFrame = Math.max(
|
---|
207 | zoomController.getZoomStartFrame(), zoomController.getZoomEndFrame());
|
---|
208 |
|
---|
209 |
|
---|
210 | zoomedTrackView.setTimeScale(minFrame, maxFrame - minFrame);
|
---|
211 | }
|
---|
212 |
|
---|
213 | });
|
---|
214 |
|
---|
215 | timeAxis = new TimeAxisPanel(zoomedTrackView);
|
---|
216 | timeAxis.setPreferredSize(new Dimension(100, 40));
|
---|
217 |
|
---|
218 | nameLabelParent = new JPanel();
|
---|
219 |
|
---|
220 | nameLabel = new EmulatedTextItem(trackModel.getName(), SwingConversions.fromSwingPoint(new Point(10, 25)));
|
---|
221 | nameLabel.setFontStyle(SwingConversions.fromSwingFontStyle(Font.BOLD));
|
---|
222 | nameLabel.setFontSize(16);
|
---|
223 | nameLabel.setBackgroundColor(Colour.WHITE);
|
---|
224 | nameLabel.gainFocus();
|
---|
225 |
|
---|
226 | nameLabel.addTextChangeListener(new TextChangeListener() { // a little bit loopy!
|
---|
227 |
|
---|
228 | public void onTextChanged(Object source, String newLabel) {
|
---|
229 | if (ExpandedTrackPopup.this.trackModel != null && !nameLabel.getText().equals(ExpandedTrackPopup.this.trackModel.getName())) {
|
---|
230 | ExpandedTrackPopup.this.trackModel.setName(nameLabel.getText());
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | });
|
---|
235 |
|
---|
236 | JPanel workArea = new JPanel(new BorderLayout());
|
---|
237 |
|
---|
238 | workArea.add(zoomedTrackView, BorderLayout.CENTER);
|
---|
239 | workArea.add(timeAxis, BorderLayout.SOUTH);
|
---|
240 |
|
---|
241 | splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
---|
242 | splitPane.setTopComponent(workArea);
|
---|
243 | splitPane.setBottomComponent(zoomController);
|
---|
244 | splitPane.setOneTouchExpandable(true);
|
---|
245 | splitPane.setResizeWeight(1.0);
|
---|
246 |
|
---|
247 | // Create the toolbar
|
---|
248 | JPanel toolBarPanel = new JPanel(new GridBagLayout());
|
---|
249 |
|
---|
250 | GridBagConstraints c = new GridBagConstraints();
|
---|
251 | c.gridx = 0;
|
---|
252 | c.gridy = 0;
|
---|
253 | c.fill = GridBagConstraints.BOTH;
|
---|
254 | toolBarPanel.add(playPauseButton, c);
|
---|
255 |
|
---|
256 | c = new GridBagConstraints();
|
---|
257 | c.gridx = 1;
|
---|
258 | c.gridy = 0;
|
---|
259 | c.fill = GridBagConstraints.BOTH;
|
---|
260 | toolBarPanel.add(stopButton, c);
|
---|
261 |
|
---|
262 | c = new GridBagConstraints();
|
---|
263 | c.gridx = 2;
|
---|
264 | c.gridy = 0;
|
---|
265 | c.fill = GridBagConstraints.BOTH;
|
---|
266 | toolBarPanel.add(rewindButton, c);
|
---|
267 |
|
---|
268 | c = new GridBagConstraints();
|
---|
269 | c.gridx = 3;
|
---|
270 | c.gridy = 0;
|
---|
271 | c.fill = GridBagConstraints.BOTH;
|
---|
272 | toolBarPanel.add(soloButton, c);
|
---|
273 |
|
---|
274 | c = new GridBagConstraints();
|
---|
275 | c.gridx = 4;
|
---|
276 | c.gridy = 0;
|
---|
277 | c.fill = GridBagConstraints.BOTH;
|
---|
278 | toolBarPanel.add(muteButton, c);
|
---|
279 |
|
---|
280 | c = new GridBagConstraints();
|
---|
281 | c.gridx = 5;
|
---|
282 | c.gridy = 0;
|
---|
283 | c.fill = GridBagConstraints.BOTH;
|
---|
284 | c.insets = new Insets(0,VOLUME_SPACING,0,VOLUME_SPACING);
|
---|
285 | toolBarPanel.add(volumeSlider, c);
|
---|
286 |
|
---|
287 | c = new GridBagConstraints();
|
---|
288 | c.gridx = 6;
|
---|
289 | c.gridy = 0;
|
---|
290 | c.fill = GridBagConstraints.BOTH;
|
---|
291 | c.weightx = 1.0f;
|
---|
292 | toolBarPanel.add(nameLabelParent, c);
|
---|
293 |
|
---|
294 | c = new GridBagConstraints();
|
---|
295 | c.gridx = 7;
|
---|
296 | c.gridy = 0;
|
---|
297 | c.fill = GridBagConstraints.BOTH;
|
---|
298 | toolBarPanel.add(closeButton, c);
|
---|
299 |
|
---|
300 | panel.add(toolBarPanel, BorderLayout.NORTH);
|
---|
301 | panel.add(splitPane, BorderLayout.CENTER);
|
---|
302 |
|
---|
303 | // Observe track model
|
---|
304 | trackModel.addObserver(zoomedTrackView);
|
---|
305 | trackModel.addObserver(zoomController);
|
---|
306 | trackModel.addObserver(this);
|
---|
307 |
|
---|
308 | // Setup mix to use
|
---|
309 | zoomedTrackView.setMix(trackMix);
|
---|
310 |
|
---|
311 | // Setup the initial zoom
|
---|
312 | zoomController.setZoom(frameStart, frameStart + frameLength);
|
---|
313 |
|
---|
314 | updateBorderColor();
|
---|
315 | }
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Giver/receiver design pattern for only allowing the ExpandedTrackManager singleton
|
---|
319 | * to create expanded views.
|
---|
320 | *
|
---|
321 | * @param trackModel
|
---|
322 | * The track model to observe.
|
---|
323 | *
|
---|
324 | * @param trackMix
|
---|
325 | * The mix to use.
|
---|
326 | *
|
---|
327 | * @param trackSourceFrameName
|
---|
328 | * Where the expanded tracks track source was expanded from.
|
---|
329 | * Must not be null
|
---|
330 | *
|
---|
331 | * @param frameStart
|
---|
332 | * the initial zoom - clamped
|
---|
333 | *
|
---|
334 | * @param frameLength
|
---|
335 | * the initial zoom - clamped
|
---|
336 | *
|
---|
337 | * @throws NullPointerException
|
---|
338 | * If trackModel or trackMix or trackSourceFrameName or localFilename is null.
|
---|
339 | *
|
---|
340 | */
|
---|
341 | static void giveToExpandedTrackManager(
|
---|
342 | SampledTrackModel trackModel,
|
---|
343 | TrackMixSubject trackMix,
|
---|
344 | String trackSourceFrameName,
|
---|
345 | int frameStart,
|
---|
346 | int frameLength) {
|
---|
347 |
|
---|
348 | ExpandedTrackPopup xtp = new ExpandedTrackPopup(
|
---|
349 | trackModel,
|
---|
350 | trackMix,
|
---|
351 | trackSourceFrameName,
|
---|
352 | frameStart,
|
---|
353 | frameLength);
|
---|
354 |
|
---|
355 | ExpandedTrackManager.getInstance().receiveExpandedTrackPopup(xtp);
|
---|
356 | }
|
---|
357 |
|
---|
358 | @Override
|
---|
359 | public void onShow()
|
---|
360 | {
|
---|
361 | if (splitPane.getHeight() < 140) {
|
---|
362 | splitPane.setDividerLocation(splitPane.getHeight() - 30);
|
---|
363 | } else {
|
---|
364 | splitPane.setDividerLocation(splitPane.getHeight() - 60);
|
---|
365 | }
|
---|
366 |
|
---|
367 | if (zoomedTrackView.getMix() != null) {
|
---|
368 | updateVolume((int)(100 * zoomedTrackView.getMix().getVolume()));
|
---|
369 | updateMute(zoomedTrackView.getMix().isMuted());
|
---|
370 | updateSolo(SoundDesk.getInstance().isSolo(zoomedTrackView.getMix().getChannelID()));
|
---|
371 | }
|
---|
372 |
|
---|
373 | SoundDesk.getInstance().addObserver(this);
|
---|
374 | trackMix.addObserver(this);
|
---|
375 |
|
---|
376 | // Invalidate full frame for shading
|
---|
377 | if (Browser._theBrowser != null) {
|
---|
378 | DisplayController.requestRefresh(false);
|
---|
379 | }
|
---|
380 | }
|
---|
381 |
|
---|
382 | @Override
|
---|
383 | public void onHide()
|
---|
384 | {
|
---|
385 | ExpandedTrackManager.getInstance().expandedTrackPopupHidden(this);
|
---|
386 | releaseMemory(); // get rid of buffer etc..
|
---|
387 |
|
---|
388 | SoundDesk.getInstance().removeObserver(this);
|
---|
389 | trackMix.removeObserver(this);
|
---|
390 |
|
---|
391 | // Invalidate full frame for shading
|
---|
392 | if (Browser._theBrowser != null) {
|
---|
393 | DisplayController.requestRefresh(false);
|
---|
394 | }
|
---|
395 | }
|
---|
396 |
|
---|
397 | @Override
|
---|
398 | public void paintInternal()
|
---|
399 | {
|
---|
400 | Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface();
|
---|
401 |
|
---|
402 | panel.paint(g);
|
---|
403 |
|
---|
404 | g.translate(-getFullBounds().getMinX(), -getFullBounds().getMinY());
|
---|
405 | nameLabel.paint();
|
---|
406 | g.translate(getFullBounds().getMinX(), getFullBounds().getMinY());
|
---|
407 | }
|
---|
408 |
|
---|
409 | public void actionPerformed(ActionEvent e)
|
---|
410 | {
|
---|
411 | if (trackModel == null) return;
|
---|
412 |
|
---|
413 | if (trackMix == null) return;
|
---|
414 |
|
---|
415 | if (e.getSource() == playPauseButton) {
|
---|
416 |
|
---|
417 | try {
|
---|
418 |
|
---|
419 | if (!SoundDesk.getInstance().isPlaying(trackMix.getChannelID())) { // play / resume
|
---|
420 |
|
---|
421 | int startFrame = -1, endFrame = -1;
|
---|
422 |
|
---|
423 | // Resume playback?
|
---|
424 | if (SoundDesk.getInstance().isPaused(trackMix.getChannelID())) {
|
---|
425 | startFrame = SoundDesk.getInstance().getLastPlayedFramePosition(trackMix.getChannelID());
|
---|
426 | if (startFrame >= 0 && startFrame < trackModel.getFrameCount()) {
|
---|
427 |
|
---|
428 | // The user may have edited the audio track and reselected it
|
---|
429 | // since the last pause. Thus select an appropriate end frame
|
---|
430 | endFrame = (trackModel.getSelectionLength() > 1) ?
|
---|
431 | trackModel.getSelectionStart() + trackModel.getSelectionLength():
|
---|
432 | trackModel.getFrameCount() - 1;
|
---|
433 |
|
---|
434 | // Changed selection? it play range invalid?
|
---|
435 | if (endFrame <= startFrame || startFrame < trackModel.getSelectionStart()) {
|
---|
436 | startFrame = -1; // Play new selection (see below)
|
---|
437 |
|
---|
438 | } else if (endFrame >= trackModel.getFrameCount()) {
|
---|
439 | endFrame = trackModel.getFrameCount() - 1;
|
---|
440 | }
|
---|
441 |
|
---|
442 | }
|
---|
443 | }
|
---|
444 |
|
---|
445 | // Play from beginning of selection to end of selection
|
---|
446 | if (startFrame < 0) {
|
---|
447 | startFrame = trackModel.getSelectionStart();
|
---|
448 | endFrame = (trackModel.getSelectionLength() > 1) ?
|
---|
449 | startFrame + trackModel.getSelectionLength():
|
---|
450 | trackModel.getFrameCount() - 1;
|
---|
451 | }
|
---|
452 |
|
---|
453 | // Safety clamp:
|
---|
454 | if (endFrame >= trackModel.getFrameCount()) {
|
---|
455 | endFrame = trackModel.getFrameCount() - 1;
|
---|
456 | }
|
---|
457 |
|
---|
458 | if (startFrame < endFrame) {
|
---|
459 | SoundDesk.getInstance().playSampledTrackModel(
|
---|
460 | trackModel,
|
---|
461 | trackMix.getChannelID(),
|
---|
462 | startFrame,
|
---|
463 | endFrame,
|
---|
464 | 0);
|
---|
465 | }
|
---|
466 |
|
---|
467 | } else { // pause
|
---|
468 |
|
---|
469 | TrackSequence ts = SoundDesk.getInstance().getTrackSequence(trackMix.getChannelID());
|
---|
470 |
|
---|
471 | if (ts != null &&
|
---|
472 | ts.isPlaying()) {
|
---|
473 |
|
---|
474 | // Mark channel as paused.
|
---|
475 | SoundDesk.getInstance().setPaused(trackMix.getChannelID(), true);
|
---|
476 |
|
---|
477 | // Stop playback for this channel
|
---|
478 | ApolloPlaybackMixer.getInstance().stop(ts);
|
---|
479 |
|
---|
480 | }
|
---|
481 |
|
---|
482 | }
|
---|
483 |
|
---|
484 | } catch (LineUnavailableException e1) {
|
---|
485 | e1.printStackTrace();
|
---|
486 | }
|
---|
487 |
|
---|
488 | } else if (e.getSource() == stopButton) {
|
---|
489 |
|
---|
490 | TrackSequence ts = SoundDesk.getInstance().getTrackSequence(trackMix.getChannelID());
|
---|
491 |
|
---|
492 | // reset any paused mark
|
---|
493 | SoundDesk.getInstance().setPaused(trackMix.getChannelID(), false);
|
---|
494 |
|
---|
495 | if (ts != null &&
|
---|
496 | ts.isPlaying()) {
|
---|
497 | // Stop playback
|
---|
498 | ApolloPlaybackMixer.getInstance().stop(ts);
|
---|
499 | }
|
---|
500 |
|
---|
501 | } else if (e.getSource() == rewindButton) {
|
---|
502 |
|
---|
503 | trackModel.setSelection(0, 0);
|
---|
504 | SoundDesk.getInstance().setPaused(trackMix.getChannelID(), false);
|
---|
505 |
|
---|
506 | } else if (e.getSource() == closeButton) {
|
---|
507 |
|
---|
508 | // If there are more expanded tracks showing then the ExpandedTrackManager
|
---|
509 | // will automatically re-layout the remaing views.
|
---|
510 | hide();
|
---|
511 |
|
---|
512 | }
|
---|
513 |
|
---|
514 | }
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * Gets rid of image buffers and threads... Frees this instance from
|
---|
518 | * being referenced from the track model - very very important.
|
---|
519 | */
|
---|
520 | void releaseMemory() {
|
---|
521 |
|
---|
522 |
|
---|
523 | trackModel.removeObserver(zoomedTrackView);
|
---|
524 | trackModel.removeObserver(zoomController);
|
---|
525 | trackModel.removeObserver(this);
|
---|
526 |
|
---|
527 | assert (zoomedTrackView.getObservedSubject() == null);
|
---|
528 | assert (zoomController.getObservedSubject() == null);
|
---|
529 |
|
---|
530 | zoomedTrackView.releaseBuffer();
|
---|
531 | zoomController.releaseBuffer();
|
---|
532 |
|
---|
533 | SoundDesk.getInstance().removeObserver(this);
|
---|
534 | trackMix.removeObserver(this);
|
---|
535 |
|
---|
536 | }
|
---|
537 |
|
---|
538 | /**
|
---|
539 | * @return The observed track model. Never null
|
---|
540 | */
|
---|
541 | public Subject getObservedSubject() {
|
---|
542 | return trackModel;
|
---|
543 | }
|
---|
544 |
|
---|
545 | /**
|
---|
546 | * @return The observed track model.
|
---|
547 | */
|
---|
548 | SampledTrackModel getObservedTrackModel() {
|
---|
549 | return trackModel;
|
---|
550 | }
|
---|
551 |
|
---|
552 |
|
---|
553 | public void setObservedSubject(Subject parent) {
|
---|
554 | }
|
---|
555 |
|
---|
556 | public void modelChanged(Subject source, SubjectChangedEvent event) {
|
---|
557 |
|
---|
558 |
|
---|
559 | // Synch GUI with track state
|
---|
560 | switch (event.getID()) {
|
---|
561 |
|
---|
562 | case ApolloSubjectChangedEvent.TRACK_SEQUENCE_CREATED: // from sound desk
|
---|
563 |
|
---|
564 | if (event.getState().equals(trackMix.getChannelID())) {
|
---|
565 | // The channel being played is the same as this one ...
|
---|
566 | // even if the track model is unloaded must enter into a playing state
|
---|
567 | // if the created track sequence will play
|
---|
568 | TrackSequence ts = SoundDesk.getInstance().getTrackSequence(trackMix.getChannelID());
|
---|
569 | assert(ts != null);
|
---|
570 | assert(!ts.hasFinished());
|
---|
571 | assert(!ts.isPlaying());
|
---|
572 | ts.addObserver(this);
|
---|
573 | }
|
---|
574 |
|
---|
575 | break;
|
---|
576 |
|
---|
577 | case ApolloSubjectChangedEvent.PLAYBACK_STARTED: // From observed track sequence
|
---|
578 | stopButton.setEnabled(true);
|
---|
579 | rewindButton.setEnabled(false);
|
---|
580 | SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("pause.png"));
|
---|
581 |
|
---|
582 | setBorderThickness(TrackWidgetCommons.PLAYING_TRACK_EDGE_THICKNESS);
|
---|
583 |
|
---|
584 | break;
|
---|
585 |
|
---|
586 | case ApolloSubjectChangedEvent.PLAYBACK_STOPPED: // From observed track sequence
|
---|
587 |
|
---|
588 | rewindButton.setEnabled(true);
|
---|
589 | stopButton.setEnabled(false);
|
---|
590 | SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png"));
|
---|
591 |
|
---|
592 | // Note:
|
---|
593 | // No need to remove self from observing the dead track since the track references this
|
---|
594 | // and will get garbage collected
|
---|
595 |
|
---|
596 | setBorderThickness(TrackWidgetCommons.STOPPED_TRACK_EDGE_THICKNESS);
|
---|
597 |
|
---|
598 |
|
---|
599 | break;
|
---|
600 |
|
---|
601 | case ApolloSubjectChangedEvent.PAUSE_MARK_CHANGED: // When stopped or paused
|
---|
602 | /*
|
---|
603 | if (ae.getState().equals(trackMix.getChannelID())) {
|
---|
604 |
|
---|
605 | if (MixDesk.getInstance().isPaused(trackMix.getChannelID())) {
|
---|
606 | // Do nothing .. the paused mark is set prior to a stop
|
---|
607 | } else {
|
---|
608 | // Esnure that the GUI represents a stopped state
|
---|
609 | stopButton.setEnabled(false);
|
---|
610 | playPauseButton.setIcon(IconRepository.getIcon("play.png"));
|
---|
611 | }
|
---|
612 |
|
---|
613 | }*/
|
---|
614 |
|
---|
615 | break;
|
---|
616 |
|
---|
617 | case ApolloSubjectChangedEvent.VOLUME: // From obseved track mix
|
---|
618 | updateVolume((int)(100 * trackMix.getVolume()));
|
---|
619 | break;
|
---|
620 |
|
---|
621 | case ApolloSubjectChangedEvent.MUTE: // From obseved track mix
|
---|
622 | updateMute(trackMix.isMuted());
|
---|
623 | updateBorderColor();
|
---|
624 | break;
|
---|
625 |
|
---|
626 | case ApolloSubjectChangedEvent.SOLO_PREFIX_CHANGED: // From mix desk
|
---|
627 | updateSolo(SoundDesk.getInstance().isSolo(trackMix.getChannelID()));
|
---|
628 | updateBorderColor();
|
---|
629 | break;
|
---|
630 |
|
---|
631 | case ApolloSubjectChangedEvent.NAME_CHANGED:
|
---|
632 | if (!nameLabel.getText().equals(trackModel.getName())) {
|
---|
633 | nameLabel.setText(trackModel.getName());
|
---|
634 | }
|
---|
635 |
|
---|
636 | // Keep graph model consistant
|
---|
637 | AudioStructureModel.getInstance().onTrackWidgetNameChanged(
|
---|
638 | trackModel.getLocalFilename(), // may not be in model ... but does not matter in such a case
|
---|
639 | null,
|
---|
640 | trackModel.getName());
|
---|
641 |
|
---|
642 | break;
|
---|
643 |
|
---|
644 | case ApolloSubjectChangedEvent.AUDIO_INSERTED: // from track model
|
---|
645 | case ApolloSubjectChangedEvent.AUDIO_REMOVED:
|
---|
646 |
|
---|
647 | long newRunningTime = AudioMath.framesToMilliseconds(
|
---|
648 | trackModel.getFrameCount(), trackModel.getFormat());
|
---|
649 | assert(newRunningTime > 0);
|
---|
650 |
|
---|
651 | if (trackModel != null) {
|
---|
652 |
|
---|
653 | // Keep TrackGraphModel consistant
|
---|
654 | AudioStructureModel.getInstance().onTrackWidgetAudioEdited(
|
---|
655 | trackModel.getLocalFilename(),
|
---|
656 | null,
|
---|
657 | newRunningTime);
|
---|
658 | }
|
---|
659 |
|
---|
660 | break;
|
---|
661 | }
|
---|
662 |
|
---|
663 | }
|
---|
664 |
|
---|
665 |
|
---|
666 |
|
---|
667 | /**
|
---|
668 | * Updates the volume GUI.
|
---|
669 | * {@link #volumeChanged()} is not raised as a result of this call.
|
---|
670 | *
|
---|
671 | * @param vol
|
---|
672 | * The volume ranging from 0 - 100. Clamped.
|
---|
673 | */
|
---|
674 | protected void updateVolume(int vol) {
|
---|
675 |
|
---|
676 | if (volumeSlider.getValue() == vol) return;
|
---|
677 |
|
---|
678 | // Clamp
|
---|
679 | if(vol < 0) vol = 0;
|
---|
680 | else if (vol > 100) vol = 100;
|
---|
681 |
|
---|
682 | isUpdatingGUI = true;
|
---|
683 |
|
---|
684 | volumeSlider.setValue(vol);
|
---|
685 |
|
---|
686 | isUpdatingGUI = false;
|
---|
687 | }
|
---|
688 |
|
---|
689 |
|
---|
690 | /**
|
---|
691 | * Updates the mute button GUI.
|
---|
692 | * {@link #muteChanged()} is not raised as a result of this call.
|
---|
693 | *
|
---|
694 | * @param isMuted
|
---|
695 | * True if set gui to muted.
|
---|
696 | */
|
---|
697 | protected void updateMute(boolean isMuted) {
|
---|
698 |
|
---|
699 | if (muteButton.isSelected() == isMuted) return;
|
---|
700 |
|
---|
701 | isUpdatingGUI = true;
|
---|
702 |
|
---|
703 | muteButton.setSelected(isMuted);
|
---|
704 |
|
---|
705 | isUpdatingGUI = false;
|
---|
706 | }
|
---|
707 |
|
---|
708 |
|
---|
709 | /**
|
---|
710 | * Updates the solo button GUI.
|
---|
711 | * {@link #muteChanged()} is not raised as a result of this call.
|
---|
712 | *
|
---|
713 | * @param isSolo
|
---|
714 | * True if set gui to solo on.
|
---|
715 | */
|
---|
716 | protected void updateSolo(boolean isSolo) {
|
---|
717 |
|
---|
718 | if (soloButton.isSelected() == isSolo) return;
|
---|
719 |
|
---|
720 | isUpdatingGUI = true;
|
---|
721 |
|
---|
722 | soloButton.setSelected(isSolo);
|
---|
723 |
|
---|
724 | isUpdatingGUI = false;
|
---|
725 | }
|
---|
726 |
|
---|
727 | private void updateBorderColor() {
|
---|
728 |
|
---|
729 | // Get border color currently used
|
---|
730 | Colour oldC = getBorderColor();
|
---|
731 |
|
---|
732 | Colour newC = TrackWidgetCommons.getBorderColor(
|
---|
733 | SoundDesk.getInstance().isSolo(trackMix.getChannelID()),
|
---|
734 | trackMix.isMuted());
|
---|
735 |
|
---|
736 | // Update the color
|
---|
737 | if (!newC.equals(oldC)) {
|
---|
738 | setBorderColor(newC);
|
---|
739 | }
|
---|
740 | }
|
---|
741 |
|
---|
742 | /**
|
---|
743 | * Sets the mute icon to represent the current volume value in the slider.
|
---|
744 | * Note: this is not the icon if mute is on.
|
---|
745 | */
|
---|
746 | private void updateButtonGUI() {
|
---|
747 |
|
---|
748 | Image newIcon = null;
|
---|
749 | if (volumeSlider.getValue() <= 25)
|
---|
750 | newIcon = IconRepository.getIcon("vol25.png");
|
---|
751 | else if (volumeSlider.getValue() <= 50)
|
---|
752 | newIcon = IconRepository.getIcon("vol50.png");
|
---|
753 | else if (volumeSlider.getValue() <= 75)
|
---|
754 | newIcon = IconRepository.getIcon("vol75.png");
|
---|
755 | else // maxing
|
---|
756 | newIcon = IconRepository.getIcon("vol100.png");
|
---|
757 |
|
---|
758 | SwingMiscManager.setJButtonIcon(muteButton, newIcon);
|
---|
759 | }
|
---|
760 |
|
---|
761 | /**
|
---|
762 | * @return
|
---|
763 | * The frame at where this expanded view came from.
|
---|
764 | * Never null.
|
---|
765 | */
|
---|
766 | public String getTrackSourceFrameName()
|
---|
767 | {
|
---|
768 | return trackSourceFrameName;
|
---|
769 | }
|
---|
770 |
|
---|
771 | public void setBounds(int x, int y, int width, int height)
|
---|
772 | {
|
---|
773 | panel.setBounds(x, y, width, height);
|
---|
774 | }
|
---|
775 |
|
---|
776 | @Override
|
---|
777 | public AxisAlignedBoxBounds getFullBounds()
|
---|
778 | {
|
---|
779 | return SwingConversions.fromSwingRectangle(panel.getBounds());
|
---|
780 | }
|
---|
781 |
|
---|
782 |
|
---|
783 | } |
---|