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.gui;
|
f@0
|
20
|
f@0
|
21 import java.awt.Color;
|
f@0
|
22 import java.awt.Component;
|
f@0
|
23 import java.awt.Dimension;
|
f@0
|
24 import java.awt.Font;
|
f@0
|
25 import java.awt.Insets;
|
f@0
|
26 import java.awt.event.ItemEvent;
|
f@0
|
27 import java.awt.event.ItemListener;
|
f@0
|
28
|
f@0
|
29 import javax.swing.DefaultComboBoxModel;
|
f@0
|
30 import javax.swing.JButton;
|
f@0
|
31 import javax.swing.JComboBox;
|
f@0
|
32 import javax.swing.JLabel;
|
f@0
|
33 import javax.swing.JList;
|
f@0
|
34 import javax.swing.JPanel;
|
f@0
|
35 import javax.swing.JSlider;
|
f@0
|
36 import javax.swing.JToggleButton;
|
f@0
|
37 import javax.swing.ListCellRenderer;
|
f@0
|
38 import javax.swing.border.MatteBorder;
|
f@0
|
39 import javax.swing.event.ChangeEvent;
|
f@0
|
40 import javax.swing.event.ChangeListener;
|
f@0
|
41
|
f@0
|
42 import uk.ac.qmul.eecs.depic.daw.Automation;
|
f@0
|
43 import uk.ac.qmul.eecs.depic.daw.Parameter;
|
f@0
|
44 import uk.ac.qmul.eecs.depic.daw.Parameter.Type;
|
f@0
|
45 import uk.ac.qmul.eecs.depic.daw.ParametersControl;
|
f@0
|
46 import uk.ac.qmul.eecs.depic.patterns.SequenceEvent;
|
f@0
|
47 import uk.ac.qmul.eecs.depic.patterns.SequenceListener;
|
f@0
|
48
|
f@2
|
49 /**
|
f@2
|
50 *
|
f@2
|
51 * The small panel with parameters like volume and pan that sits at the left of each audio track
|
f@2
|
52 *
|
f@2
|
53 */
|
f@0
|
54 public class AudioTrackParameters extends JPanel {
|
f@0
|
55 private static final long serialVersionUID = 1L;
|
f@0
|
56 private final static int SLIDER_SCALE = 100;
|
f@0
|
57
|
f@0
|
58 private AudioTrack track;
|
f@0
|
59 public final JLabel nameLabel;
|
f@0
|
60 public final JLabel gainLabel;
|
f@0
|
61 public final JToggleButton muteButton;
|
f@0
|
62 public final JToggleButton soloButton;
|
f@0
|
63 public final JButton fxButton;
|
f@0
|
64 public final JComboBox<Parameter.Type> automationComboBox;
|
f@0
|
65 public final JSlider gainSlider;
|
f@0
|
66 public final JLabel panLabel;
|
f@0
|
67 public final JSlider panSlider;
|
f@0
|
68
|
f@0
|
69 /**
|
f@0
|
70 * Create the panel.
|
f@0
|
71 */
|
f@0
|
72 public AudioTrackParameters(AudioTrack track, int index) {
|
f@0
|
73 this.track = track;
|
f@0
|
74
|
f@0
|
75 this.setPreferredSize(new Dimension(247, 130)); //FIXME const values
|
f@0
|
76 this.setMaximumSize(new Dimension(247, 130));
|
f@0
|
77
|
f@0
|
78
|
f@0
|
79 nameLabel = new JLabel("New Track "+index);
|
f@0
|
80 nameLabel.setBounds(6, 8, 233, 17);
|
f@0
|
81 nameLabel.setBorder(new MatteBorder(0, 0, 1, 0, (Color) new Color(0, 0, 0)));
|
f@0
|
82
|
f@0
|
83 soloButton = new JToggleButton("S");
|
f@0
|
84 soloButton.setBounds(205, 84, 36, 20);
|
f@0
|
85 soloButton.getAccessibleContext().setAccessibleName("Solo");
|
f@0
|
86 soloButton.setMargin(new Insets(0, 0, 0, 0));
|
f@0
|
87 soloButton.setMinimumSize(new Dimension(20, 20));
|
f@0
|
88 soloButton.setMaximumSize(new Dimension(20, 20));
|
f@0
|
89 soloButton.setPreferredSize(new Dimension(20, 20));
|
f@0
|
90
|
f@0
|
91 muteButton = new JToggleButton("M");
|
f@0
|
92 muteButton.setBounds(166, 84, 38, 20);
|
f@0
|
93 muteButton.getAccessibleContext().setAccessibleName("Mute");
|
f@0
|
94 muteButton.setMargin(new Insets(0, 0, 0, 0));
|
f@0
|
95 muteButton.setFont(new Font("Tahoma", Font.PLAIN, 11));
|
f@0
|
96 muteButton.setPreferredSize(new Dimension(20, 20));
|
f@0
|
97 muteButton.setMinimumSize(new Dimension(20, 20));
|
f@0
|
98 muteButton.setMaximumSize(new Dimension(20, 20));
|
f@0
|
99
|
f@0
|
100 fxButton = new JButton("Fx");
|
f@0
|
101 fxButton.setBounds(12, 30, 40, 20);
|
f@0
|
102 fxButton.setPreferredSize(new Dimension(20, 20));
|
f@0
|
103 fxButton.setMinimumSize(new Dimension(20, 20));
|
f@0
|
104 fxButton.setMaximumSize(new Dimension(20, 20));
|
f@0
|
105 fxButton.setMargin(new Insets(0, 0, 0, 0));
|
f@0
|
106 fxButton.setFont(new Font("Tahoma", Font.PLAIN, 11));
|
f@0
|
107
|
f@0
|
108 automationComboBox = new JComboBox<>();
|
f@0
|
109 automationComboBox.setBounds(166, 29, 73, 18);
|
f@0
|
110
|
f@0
|
111 JLabel lblAutomation = new JLabel("Automation:");
|
f@0
|
112 lblAutomation.setBounds(95, 30, 65, 16);
|
f@0
|
113 lblAutomation.setLabelFor(automationComboBox);
|
f@0
|
114
|
f@0
|
115 gainLabel = new JLabel("");
|
f@0
|
116 gainLabel.setBounds(6, 106, 87, 16);
|
f@0
|
117 setLayout(null);
|
f@0
|
118 add(nameLabel);
|
f@0
|
119 add(fxButton);
|
f@0
|
120 add(gainLabel);
|
f@0
|
121 add(lblAutomation);
|
f@0
|
122 add(automationComboBox);
|
f@0
|
123 add(muteButton);
|
f@0
|
124 add(soloButton);
|
f@0
|
125
|
f@0
|
126 gainSlider = new JSlider();
|
f@0
|
127 gainSlider.setBounds(103, 103, 136, 21);
|
f@0
|
128 add(gainSlider);
|
f@0
|
129
|
f@0
|
130 panLabel = new JLabel("Pan: 0.0 ");
|
f@0
|
131 panLabel.setBounds(6, 84, 61, 16);
|
f@0
|
132 add(panLabel);
|
f@0
|
133
|
f@0
|
134 panSlider = new JSlider();
|
f@0
|
135 panSlider.setBounds(68, 84, 78, 21);
|
f@0
|
136 add(panSlider);
|
f@0
|
137
|
f@0
|
138 initComponentsValues();
|
f@0
|
139 addListeners();
|
f@0
|
140 }
|
f@0
|
141
|
f@0
|
142 private void addListeners(){
|
f@0
|
143 gainSlider.addChangeListener(new GainListener());
|
f@0
|
144 panSlider.addChangeListener(new PanListener());
|
f@0
|
145 automationComboBox.addItemListener(new AutomationComboBoxListener());
|
f@0
|
146
|
f@0
|
147 }
|
f@0
|
148
|
f@0
|
149 private void initComponentsValues(){
|
f@0
|
150 ParametersControl parametersControl = track.getSoundWave().getParametersControl();
|
f@0
|
151
|
f@0
|
152 /* gain slider */
|
f@0
|
153 Parameter volume = parametersControl.getGainParameter();
|
f@0
|
154 gainSlider.setMinimum((int)(volume.getRange().getStart()*SLIDER_SCALE));
|
f@0
|
155 gainSlider.setMaximum((int)(volume.getRange().getEnd()*SLIDER_SCALE));
|
f@0
|
156 gainSlider.setValue((int)volume.getValue()*SLIDER_SCALE);
|
f@0
|
157
|
f@0
|
158 gainLabel.setText(volume.getType().getLabel()+(volume.getInitialValue()+" "+volume.getType().getUnitofMeasurment()));
|
f@0
|
159 gainLabel.setLabelFor(gainSlider);
|
f@0
|
160
|
f@0
|
161 Parameter pan = parametersControl.getPanParameter();
|
f@0
|
162 panSlider.setMinimum((int)(pan.getRange().getStart()*SLIDER_SCALE));
|
f@0
|
163 panSlider.setMaximum((int)(pan.getRange().getEnd()*SLIDER_SCALE));
|
f@0
|
164 panSlider.setValue((int)pan.getValue()*SLIDER_SCALE);
|
f@0
|
165
|
f@0
|
166
|
f@0
|
167 float panValue = panSlider.getValue();
|
f@0
|
168 panLabel.setText(pan.getType().getLabel()+(panValue/SLIDER_SCALE));
|
f@0
|
169 panLabel.setLabelFor(panSlider);
|
f@0
|
170 /* automation combo box */
|
f@0
|
171
|
f@0
|
172 class ParameterTypeRenderer extends JLabel implements ListCellRenderer<Parameter.Type> {
|
f@0
|
173 private static final long serialVersionUID = 1L;
|
f@0
|
174
|
f@0
|
175 @Override
|
f@0
|
176 public Component getListCellRendererComponent(
|
f@0
|
177 JList<? extends Type> list, Type value, int index,
|
f@0
|
178 boolean isSelected, boolean cellHasFocus) {
|
f@0
|
179 if (isSelected) {
|
f@0
|
180 setBackground(list.getSelectionBackground());
|
f@0
|
181 setForeground(list.getSelectionForeground());
|
f@0
|
182 } else {
|
f@0
|
183 setBackground(list.getBackground());
|
f@0
|
184 setForeground(list.getForeground());
|
f@0
|
185 }
|
f@0
|
186
|
f@0
|
187 setText(" "+value.getLabel());
|
f@0
|
188
|
f@0
|
189 return this;
|
f@0
|
190 }
|
f@0
|
191
|
f@0
|
192 }
|
f@0
|
193
|
f@0
|
194 automationComboBox.setModel(new DefaultComboBoxModel<Parameter.Type>(
|
f@0
|
195 new Parameter.Type[] {Parameter.NONE_PARAMETER.getType(), Parameter.GAIN_TYPE, Parameter.PAN_TYPE}));
|
f@0
|
196
|
f@0
|
197 automationComboBox.setRenderer(new ParameterTypeRenderer());
|
f@0
|
198 }
|
f@0
|
199
|
f@0
|
200 public void setLabel(String label){
|
f@0
|
201 nameLabel.setText(label);
|
f@0
|
202
|
f@0
|
203 track.getAccessibleContext().setAccessibleName(label);
|
f@0
|
204 }
|
f@0
|
205
|
f@0
|
206 /**
|
f@0
|
207 * Returns the text of this component label
|
f@0
|
208 *
|
f@0
|
209 * @see #setLabel(String)
|
f@0
|
210 * @return the text of this component label
|
f@0
|
211 */
|
f@0
|
212 @Override
|
f@0
|
213 public String toString(){
|
f@0
|
214 return nameLabel.getText();
|
f@0
|
215 }
|
f@0
|
216
|
f@0
|
217 private class GainListener implements ChangeListener {
|
f@0
|
218 @Override
|
f@0
|
219 public void stateChanged(ChangeEvent evt) {
|
f@0
|
220 JSlider gain = (JSlider)evt.getSource();
|
f@0
|
221
|
f@0
|
222 float newValue = (float)gain.getValue()/SLIDER_SCALE;
|
f@0
|
223 Parameter gainParam = track.getSoundWave().getParametersControl().getGainParameter();
|
f@0
|
224 gainLabel.setText(gainParam.getType().getLabel()+(newValue)+" "+gainParam.getType().getUnitofMeasurment());
|
f@0
|
225 gainParam.setValue(newValue);
|
f@0
|
226 }
|
f@0
|
227 }
|
f@0
|
228
|
f@0
|
229 private class PanListener implements ChangeListener {
|
f@0
|
230 @Override
|
f@0
|
231 public void stateChanged(ChangeEvent evt) {
|
f@0
|
232 JSlider pan = (JSlider)evt.getSource();
|
f@0
|
233
|
f@0
|
234 float newValue = (float)pan.getValue()/SLIDER_SCALE;
|
f@0
|
235 Parameter panParam = track.getSoundWave().getParametersControl().getPanParameter();
|
f@0
|
236 panParam.setValue(newValue);
|
f@0
|
237 panLabel.setText(panParam.getType().getLabel()+(newValue));
|
f@0
|
238 }
|
f@0
|
239 }
|
f@0
|
240
|
f@0
|
241 private class AutomationComboBoxListener implements ItemListener {
|
f@0
|
242 @Override
|
f@0
|
243 public void itemStateChanged(ItemEvent evt) {
|
f@0
|
244 if(evt.getStateChange() == ItemEvent.SELECTED){
|
f@0
|
245 Parameter.Type type = (Parameter.Type)evt.getItem();
|
f@0
|
246 track.getSoundWave().getParametersControl().setCurrentAutomation(type);
|
f@0
|
247
|
f@0
|
248 if(Parameter.GAIN_TYPE.equals(type)){
|
f@0
|
249 /* get the now current autiomation */
|
f@0
|
250 Automation a = track.getSoundWave().getParametersControl().getCurrentAutomation();
|
f@0
|
251 a.addSequenceListener(new SequenceListener(){
|
f@0
|
252
|
f@0
|
253 @Override
|
f@0
|
254 public <T extends SequenceEvent> void sequenceUpdated(T t) {
|
f@0
|
255 if(t.getSource().getValuesNum() != 0){
|
f@0
|
256 gainSlider.setEnabled(false);
|
f@0
|
257 }else {
|
f@0
|
258 gainSlider.setEnabled(true);
|
f@0
|
259 float newValue = t.getSource().getBegin() * SLIDER_SCALE;
|
f@0
|
260 gainSlider.setValue((int)newValue);
|
f@0
|
261 }
|
f@0
|
262 }
|
f@0
|
263
|
f@0
|
264 });
|
f@0
|
265 }else if(Parameter.PAN_TYPE.equals(type)) {
|
f@0
|
266 /* get the now current autiomation */
|
f@0
|
267 Automation a = track.getSoundWave().getParametersControl().getCurrentAutomation();
|
f@0
|
268 a.addSequenceListener(new SequenceListener(){
|
f@0
|
269
|
f@0
|
270 @Override
|
f@0
|
271 public <T extends SequenceEvent> void sequenceUpdated(T t) {
|
f@0
|
272 if(t.getSource().getValuesNum() != 0){
|
f@0
|
273 panSlider.setEnabled(false);
|
f@0
|
274 }else {
|
f@0
|
275 panSlider.setEnabled(true);
|
f@0
|
276 float newValue = (float)t.getSource().getBegin() * SLIDER_SCALE;
|
f@0
|
277 panSlider.setValue((int) newValue);
|
f@0
|
278 }
|
f@0
|
279 }
|
f@0
|
280
|
f@0
|
281 });
|
f@0
|
282 }
|
f@0
|
283 }
|
f@0
|
284 }
|
f@0
|
285 }
|
f@0
|
286 }
|