f@0: /* f@0: Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation. f@0: f@0: Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/) f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@0: package uk.ac.qmul.eecs.depic.daw.gui; f@0: f@0: import java.beans.PropertyChangeEvent; f@0: import java.beans.PropertyChangeListener; f@0: f@0: import javax.swing.event.ChangeEvent; f@0: import javax.swing.event.ChangeListener; f@0: f@0: import uk.ac.qmul.eecs.depic.daw.Daw; f@0: import uk.ac.qmul.eecs.depic.daw.Selection; f@0: import uk.ac.qmul.eecs.depic.daw.Sonification; f@0: import uk.ac.qmul.eecs.depic.daw.SoundType; f@0: import uk.ac.qmul.eecs.depic.daw.SoundWave; f@0: f@2: /** f@2: * Plays sonification sounds of the audio track through the member variable of f@2: * type {@code Sonification} that is initialized with {@code Daw.getSoundEngineFactory().getSharedSonification()} f@2: * f@2: * Listen to property changes of AudioTrack objects ("cursorPos" and "mouseDragSelection" properties) f@2: * and to changes of sequence graphs (automation graphs) objects. f@2: * f@2: */ f@0: class AudioTrackSonification implements PropertyChangeListener, ChangeListener { f@0: private Sonification sonification = Daw.getSoundEngineFactory().getSharedSonification(); f@0: private AudioTrack track; f@0: f@0: AudioTrackSonification(AudioTrack track){ f@0: this.track = track; f@0: } f@0: f@0: @Override f@0: public void propertyChange(PropertyChangeEvent evt) { f@0: if("cursorPos".equals(evt.getPropertyName())){ f@0: AudioTrack track = (AudioTrack)evt.getSource(); f@0: SoundWave soundWave = track.getSoundWave(); f@0: int newPos = (Integer)evt.getNewValue(); f@0: f@0: if(soundWave.hasSequence()){ f@0: /* check if the cursor stumbled upon or left an automation point */ f@0: for(SequencePoint p : track.getAutomationGraph().getSequencePoints()){ f@0: if(p.isXCentredAt(newPos)){ f@0: sonification.getSequenceMapping(SoundType.AUTOMATION).renderValue(p.getSequenceValue()); //FIXME remove comments f@0: } f@0: } f@0: f@0: if(track.showAutomationSound){ f@0: sonification.getSequenceMapping(SoundType.AUTOMATION).renderCurveAt( f@0: soundWave.getSequence(), f@0: soundWave.getMillisecPerChunk() * newPos, f@0: Float.POSITIVE_INFINITY); f@0: } f@0: } f@0: f@0: if(soundWave.getDbWave().hasSequence()){ f@0: /* check if the cursor stumbled upon or left an automation point */ f@0: // for(SequencePoint p : track.getPeakLevelGraph().getSequencePoints()){ f@0: // if(p.isXCentredAt(newPos)){ f@0: // sonification.getSequenceMapping(GuiSoundType.PEAK_LEVEL).renderValue(p.getSequenceValue()); f@0: // } f@0: // } f@0: f@0: if(track.showPeakLevelSound){ f@0: sonification.getSequenceMapping(SoundType.PEAK_LEVEL).renderCurveAt( f@0: soundWave.getDbWave().getSequence(), f@0: soundWave.getMillisecPerChunk() * newPos, f@0: Float.POSITIVE_INFINITY); f@0: } f@0: } f@0: f@0: if(track.trackInteraction.getMouseSelection().isOpen()){ f@0: return; f@0: } f@0: f@0: /* play selection sound if within selection, stop it if without */ f@0: if(track.trackInteraction.getMouseSelection().contains(newPos)){ f@0: sonification.withinSelection(1.0f, 0.0f); f@0: }else { f@0: sonification.outsideSelection(); f@0: } f@0: f@0: if(track.trackInteraction.getMouseSelection().getStart() == newPos){ f@0: sonification.play(SoundType.SHIFT_START); f@0: }else if(track.trackInteraction.getMouseSelection().getEnd() == newPos){ f@0: sonification.play(SoundType.SHIFT_END); f@0: } f@0: }else if("mouseDragSelection".equals(evt.getPropertyName())){ f@0: if( ((Selection)evt.getNewValue()).isOpen() ){ f@0: sonification.outsideSelection(); f@0: } f@0: } f@0: } f@0: f@0: @Override f@0: public void stateChanged(ChangeEvent evt) { f@0: if(track.showAutomationSound){ f@0: SoundWave soundWave = track.getSoundWave(); f@0: sonification.getSequenceMapping(SoundType.AUTOMATION).renderCurveAt( f@0: soundWave.getSequence(), f@0: soundWave.getMillisecPerChunk() * soundWave.getCurrentChunkPosition(), f@0: Float.POSITIVE_INFINITY); f@0: } f@0: } f@0: f@0: }