Mercurial > hg > cmdp
view src/uk/ac/qmul/eecs/depic/daw/beads/BeadsParametersControl.java @ 2:c0412c81d274
Added documentation
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Thu, 18 Feb 2016 18:35:26 +0000 |
parents | 3074a84ef81e |
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.beads; import java.awt.Color; import java.util.HashMap; import java.util.Map; import uk.ac.qmul.eecs.depic.daw.Automation; import uk.ac.qmul.eecs.depic.daw.Parameter; import uk.ac.qmul.eecs.depic.daw.Parameter.Type; import uk.ac.qmul.eecs.depic.daw.ParametersControl; import uk.ac.qmul.eecs.depic.daw.SoundWaveEvent; /** * * Beads implementation of the {@code ParametersControl} interface. * */ class BeadsParametersControl implements ParametersControl { Parameter[] parameters; GainParameter playersGain; PanParameter playersPan; Automation currentAutomation; Parameter currentAutomationParameter; Map<Parameter.Type,Automation> automations; private BeadsSoundWave soundWave; BeadsParametersControl(BeadsSoundWave soundWave){ this.soundWave = soundWave; automations = new HashMap<>(); automations.put(Parameter.NONE_PARAMETER.getType(), Automation.NONE_AUTOMATION); currentAutomation = Automation.NONE_AUTOMATION; currentAutomationParameter = Parameter.NONE_PARAMETER; parameters = new Parameter[2]; /* gain for soundWave */ parameters[0] = new GainParameter(soundWave.ac, 2); /* pan for soundWave */ parameters[1] = new PanParameter(soundWave.ac); } @Override public Automation getCurrentAutomation() { return currentAutomation; } @Override public Parameter getCurrentAutomationType() { return currentAutomationParameter; } @Override public void setCurrentAutomation(Parameter.Type type) { currentAutomation = getAutomation(type); currentAutomationParameter = Parameter.NONE_PARAMETER; for(Parameter p : parameters){ if(p.getType().equals(type)){ currentAutomationParameter = p; } } soundWave.fireSoundWaveListeners(SoundWaveEvent.AUTOMATION_CHANGED, currentAutomation); } @Override public Automation getAutomation(Type type) { if(type == null){ type = Parameter.NONE_PARAMETER.getType(); }; Automation automation = automations.get(type); if(automation != null){ return automation; } if(Parameter.GAIN_TYPE.equals(type)) { automation = new BeadsAutomation(soundWave, parameters[0].getRange(), Color.ORANGE, parameters[0].getInitialValue()); automations.put(type, automation); parameters[0].automate(automation); return automation; }else if (Parameter.PAN_TYPE.equals(type)) { automation = new BeadsAutomation(soundWave, parameters[1].getRange(), Color.CYAN, parameters[1].getInitialValue()); automations.put(type, automation); parameters[1].automate(automation); return automation; }else { throw new IllegalArgumentException("Parameter not recognized: "+type); } } @Override public Parameter getParameter(Parameter.Type type) { for(Parameter p : parameters){ if(p.getType().equals(type)){ return p; } } return Parameter.NONE_PARAMETER; } @Override public Parameter getGainParameter() { return parameters[0]; } @Override public Parameter getPanParameter() { return parameters[1]; } }