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