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