f@0
|
1 /*
|
f@0
|
2 Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation.
|
f@0
|
3
|
f@0
|
4 Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/)
|
f@0
|
5
|
f@0
|
6 This program is free software: you can redistribute it and/or modify
|
f@0
|
7 it under the terms of the GNU General Public License as published by
|
f@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
f@0
|
9 (at your option) any later version.
|
f@0
|
10
|
f@0
|
11 This program is distributed in the hope that it will be useful,
|
f@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@0
|
14 GNU General Public License for more details.
|
f@0
|
15
|
f@0
|
16 You should have received a copy of the GNU General Public License
|
f@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@0
|
18 */
|
f@0
|
19 package uk.ac.qmul.eecs.depic.daw.beads;
|
f@0
|
20
|
f@0
|
21 import java.awt.Color;
|
f@0
|
22 import java.util.HashMap;
|
f@0
|
23 import java.util.Map;
|
f@0
|
24
|
f@0
|
25 import uk.ac.qmul.eecs.depic.daw.Automation;
|
f@0
|
26 import uk.ac.qmul.eecs.depic.daw.Parameter;
|
f@0
|
27 import uk.ac.qmul.eecs.depic.daw.Parameter.Type;
|
f@0
|
28 import uk.ac.qmul.eecs.depic.daw.ParametersControl;
|
f@0
|
29 import uk.ac.qmul.eecs.depic.daw.SoundWaveEvent;
|
f@0
|
30
|
f@2
|
31 /**
|
f@2
|
32 *
|
f@2
|
33 * Beads implementation of the {@code ParametersControl} interface.
|
f@2
|
34 *
|
f@2
|
35 */
|
f@0
|
36 class BeadsParametersControl implements ParametersControl {
|
f@0
|
37 Parameter[] parameters;
|
f@0
|
38 GainParameter playersGain;
|
f@0
|
39 PanParameter playersPan;
|
f@0
|
40
|
f@0
|
41 Automation currentAutomation;
|
f@0
|
42 Parameter currentAutomationParameter;
|
f@0
|
43 Map<Parameter.Type,Automation> automations;
|
f@0
|
44 private BeadsSoundWave soundWave;
|
f@0
|
45
|
f@0
|
46 BeadsParametersControl(BeadsSoundWave soundWave){
|
f@0
|
47 this.soundWave = soundWave;
|
f@0
|
48 automations = new HashMap<>();
|
f@0
|
49 automations.put(Parameter.NONE_PARAMETER.getType(), Automation.NONE_AUTOMATION);
|
f@0
|
50 currentAutomation = Automation.NONE_AUTOMATION;
|
f@0
|
51 currentAutomationParameter = Parameter.NONE_PARAMETER;
|
f@0
|
52
|
f@0
|
53 parameters = new Parameter[2];
|
f@0
|
54 /* gain for soundWave */
|
f@0
|
55 parameters[0] = new GainParameter(soundWave.ac, 2);
|
f@0
|
56 /* pan for soundWave */
|
f@0
|
57 parameters[1] = new PanParameter(soundWave.ac);
|
f@0
|
58 }
|
f@0
|
59
|
f@0
|
60
|
f@0
|
61 @Override
|
f@0
|
62 public Automation getCurrentAutomation() {
|
f@0
|
63 return currentAutomation;
|
f@0
|
64 }
|
f@0
|
65
|
f@0
|
66 @Override
|
f@0
|
67 public Parameter getCurrentAutomationType() {
|
f@0
|
68 return currentAutomationParameter;
|
f@0
|
69 }
|
f@0
|
70
|
f@0
|
71
|
f@0
|
72 @Override
|
f@0
|
73 public void setCurrentAutomation(Parameter.Type type) {
|
f@0
|
74 currentAutomation = getAutomation(type);
|
f@0
|
75
|
f@0
|
76 currentAutomationParameter = Parameter.NONE_PARAMETER;
|
f@0
|
77 for(Parameter p : parameters){
|
f@0
|
78 if(p.getType().equals(type)){
|
f@0
|
79 currentAutomationParameter = p;
|
f@0
|
80 }
|
f@0
|
81 }
|
f@0
|
82 soundWave.fireSoundWaveListeners(SoundWaveEvent.AUTOMATION_CHANGED, currentAutomation);
|
f@0
|
83 }
|
f@0
|
84
|
f@0
|
85 @Override
|
f@0
|
86 public Automation getAutomation(Type type) {
|
f@0
|
87 if(type == null){
|
f@0
|
88 type = Parameter.NONE_PARAMETER.getType();
|
f@0
|
89 };
|
f@0
|
90
|
f@0
|
91 Automation automation = automations.get(type);
|
f@0
|
92
|
f@0
|
93 if(automation != null){
|
f@0
|
94 return automation;
|
f@0
|
95 }
|
f@0
|
96
|
f@0
|
97 if(Parameter.GAIN_TYPE.equals(type)) {
|
f@0
|
98 automation = new BeadsAutomation(soundWave,
|
f@0
|
99 parameters[0].getRange(),
|
f@0
|
100 Color.ORANGE,
|
f@0
|
101 parameters[0].getInitialValue());
|
f@0
|
102
|
f@0
|
103 automations.put(type, automation);
|
f@0
|
104 parameters[0].automate(automation);
|
f@0
|
105 return automation;
|
f@0
|
106 }else if (Parameter.PAN_TYPE.equals(type)) {
|
f@0
|
107 automation = new BeadsAutomation(soundWave,
|
f@0
|
108 parameters[1].getRange(),
|
f@0
|
109 Color.CYAN,
|
f@0
|
110 parameters[1].getInitialValue());
|
f@0
|
111
|
f@0
|
112 automations.put(type, automation);
|
f@0
|
113 parameters[1].automate(automation);
|
f@0
|
114 return automation;
|
f@0
|
115 }else {
|
f@0
|
116 throw new IllegalArgumentException("Parameter not recognized: "+type);
|
f@0
|
117 }
|
f@0
|
118
|
f@0
|
119 }
|
f@0
|
120
|
f@0
|
121 @Override
|
f@0
|
122 public Parameter getParameter(Parameter.Type type) {
|
f@0
|
123 for(Parameter p : parameters){
|
f@0
|
124 if(p.getType().equals(type)){
|
f@0
|
125 return p;
|
f@0
|
126 }
|
f@0
|
127 }
|
f@0
|
128
|
f@0
|
129 return Parameter.NONE_PARAMETER;
|
f@0
|
130 }
|
f@0
|
131
|
f@0
|
132
|
f@0
|
133 @Override
|
f@0
|
134 public Parameter getGainParameter() {
|
f@0
|
135 return parameters[0];
|
f@0
|
136 }
|
f@0
|
137
|
f@0
|
138
|
f@0
|
139 @Override
|
f@0
|
140 public Parameter getPanParameter() {
|
f@0
|
141 return parameters[1];
|
f@0
|
142 }
|
f@0
|
143
|
f@0
|
144 }
|