Chris@2
|
1 /* Performance Worm: Visualisation of Expressive Musical Performance
|
Chris@2
|
2 Copyright (C) 2001, 2006 by Simon Dixon
|
Chris@2
|
3
|
Chris@2
|
4 This program is free software; you can redistribute it and/or modify
|
Chris@2
|
5 it under the terms of the GNU General Public License as published by
|
Chris@2
|
6 the Free Software Foundation; either version 2 of the License, or
|
Chris@2
|
7 (at your option) any later version.
|
Chris@2
|
8
|
Chris@2
|
9 This program is distributed in the hope that it will be useful,
|
Chris@2
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@2
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@2
|
12 GNU General Public License for more details.
|
Chris@2
|
13
|
Chris@2
|
14 You should have received a copy of the GNU General Public License along
|
Chris@2
|
15 with this program (the file gpl.txt); if not, download it from
|
Chris@2
|
16 http://www.gnu.org/licenses/gpl.txt or write to the
|
Chris@2
|
17 Free Software Foundation, Inc.,
|
Chris@2
|
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
Chris@2
|
19 */
|
Chris@2
|
20
|
Chris@2
|
21 package at.ofai.music.worm;
|
Chris@2
|
22
|
Chris@2
|
23 import java.io.PrintStream;
|
Chris@2
|
24 import java.io.BufferedReader;
|
Chris@2
|
25 import java.io.IOException;
|
Chris@2
|
26 import at.ofai.music.util.Parameters;
|
Chris@2
|
27
|
Chris@2
|
28 public class WormParameters extends Parameters {
|
Chris@2
|
29
|
Chris@2
|
30 static final long serialVersionUID = 0;
|
Chris@2
|
31 public static final String VERSION = "WORM Version";
|
Chris@2
|
32 public static final String FRAMEPERIOD = "FrameLength";
|
Chris@2
|
33 public static final String COMPOSER = "Composer";
|
Chris@2
|
34 public static final String PIECE = "Piece";
|
Chris@2
|
35 public static final String PERFORMER = "Performer";
|
Chris@2
|
36 public static final String KEY = "Key";
|
Chris@2
|
37 public static final String YEAR = "YearOfRecording";
|
Chris@2
|
38 public static final String INDICATION = "Indication";
|
Chris@2
|
39 public static final String BEATLEVEL = "BeatLevel";
|
Chris@2
|
40 public static final String TRACKLEVEL = "TrackLevel";
|
Chris@2
|
41 public static final String STARTBAR = "StartBarNumber";
|
Chris@2
|
42 public static final String UPBEAT = "Upbeat";
|
Chris@2
|
43 public static final String BEATSPERBAR = "BeatsPerBar";
|
Chris@2
|
44 public static final String LENGTH = "Length";
|
Chris@2
|
45 public static final String AUDIOPATH = "AudioPath";
|
Chris@2
|
46 public static final String AUDIOFILE = "AudioFile";
|
Chris@2
|
47 public static final String SMOOTHING = "Smoothing";
|
Chris@2
|
48 public static final String AXIS = "Axis";
|
Chris@2
|
49 public static final String RESOLUTION = "Time Resolution";
|
Chris@2
|
50 public static final String UNITS = "LoudnessUnits";
|
Chris@2
|
51 public static final String TEMPOLATE = "TempoLate";
|
Chris@2
|
52 public static final String TITLE = "Edit Worm Parameters";
|
Chris@2
|
53 public static final String SEP = ":\t";
|
Chris@2
|
54 public static final char SEPCHAR = ':';
|
Chris@2
|
55
|
Chris@2
|
56 protected double framePeriod;
|
Chris@2
|
57 protected String trackLevel, loudnessUnits, version, composer, piece,
|
Chris@2
|
58 performer, key, year, indication, audioFile, audioPath,
|
Chris@2
|
59 smoothing, axis, beatLevel, upbeat, startBar, tempoLate;
|
Chris@2
|
60 protected int beatsPerBar, length;
|
Chris@2
|
61
|
Chris@2
|
62 public WormParameters(java.awt.Frame f) {
|
Chris@2
|
63 super(f, TITLE);
|
Chris@2
|
64 composer = "Unknown composer";
|
Chris@2
|
65 piece = "unknown piece";
|
Chris@2
|
66 performer = "unknown performer";
|
Chris@2
|
67 key = "";
|
Chris@2
|
68 year = "";
|
Chris@2
|
69 indication = "";
|
Chris@2
|
70 beatLevel = "1/4";
|
Chris@2
|
71 trackLevel = "1.0";
|
Chris@2
|
72 upbeat = "0";
|
Chris@2
|
73 startBar = "1";
|
Chris@2
|
74 beatsPerBar = 4;
|
Chris@2
|
75 length = 0;
|
Chris@2
|
76 audioFile = "";
|
Chris@2
|
77 audioPath = "";
|
Chris@2
|
78 smoothing = "";
|
Chris@2
|
79 axis = "";
|
Chris@2
|
80 version = "1.0";
|
Chris@2
|
81 loudnessUnits = "dB";
|
Chris@2
|
82 tempoLate = "";
|
Chris@2
|
83 framePeriod = WormFile.defaultFramePeriod;
|
Chris@2
|
84 } // constructor
|
Chris@2
|
85
|
Chris@2
|
86 public void editParameters() {
|
Chris@2
|
87 editParameters(true);
|
Chris@2
|
88 } // editParameters()
|
Chris@2
|
89
|
Chris@2
|
90 public void editParameters(boolean doEdit) {
|
Chris@2
|
91 setString(COMPOSER, composer);
|
Chris@2
|
92 setString(PIECE, piece);
|
Chris@2
|
93 setString(PERFORMER, performer);
|
Chris@2
|
94 setString(KEY, key);
|
Chris@2
|
95 setString(YEAR, year);
|
Chris@2
|
96 setString(INDICATION, indication);
|
Chris@2
|
97 setString(BEATLEVEL, beatLevel); // e.g. 3/8
|
Chris@2
|
98 setString(TRACKLEVEL, trackLevel);
|
Chris@2
|
99 setString(UPBEAT, upbeat);
|
Chris@2
|
100 setString(STARTBAR, startBar);
|
Chris@2
|
101 setInt(BEATSPERBAR, beatsPerBar);
|
Chris@2
|
102 setInt(LENGTH, length);
|
Chris@2
|
103 setString(AUDIOPATH, audioPath);
|
Chris@2
|
104 setString(AUDIOFILE, audioFile);
|
Chris@2
|
105 setString(SMOOTHING, smoothing);
|
Chris@2
|
106 setString(AXIS, axis);
|
Chris@2
|
107 setString(VERSION, version);
|
Chris@2
|
108 setDouble(RESOLUTION, framePeriod);
|
Chris@2
|
109 setString(UNITS, loudnessUnits);
|
Chris@2
|
110 setString(TEMPOLATE, tempoLate);
|
Chris@2
|
111 setVisible(doEdit);
|
Chris@2
|
112 composer = getString(COMPOSER);
|
Chris@2
|
113 piece = getString(PIECE);
|
Chris@2
|
114 performer = getString(PERFORMER);
|
Chris@2
|
115 key = getString(KEY);
|
Chris@2
|
116 year = getString(YEAR);
|
Chris@2
|
117 indication = getString(INDICATION);
|
Chris@2
|
118 beatLevel = getString(BEATLEVEL); // e.g. 3/8
|
Chris@2
|
119 trackLevel = getString(TRACKLEVEL);
|
Chris@2
|
120 upbeat = getString(UPBEAT);
|
Chris@2
|
121 startBar = getString(STARTBAR);
|
Chris@2
|
122 beatsPerBar = getInt(BEATSPERBAR);
|
Chris@2
|
123 length = getInt(LENGTH);
|
Chris@2
|
124 audioPath = getString(AUDIOPATH);
|
Chris@2
|
125 audioFile = getString(AUDIOFILE);
|
Chris@2
|
126 smoothing = getString(SMOOTHING);
|
Chris@2
|
127 axis = getString(AXIS);
|
Chris@2
|
128 version = getString(VERSION);
|
Chris@2
|
129 framePeriod = getDouble(RESOLUTION);
|
Chris@2
|
130 loudnessUnits = getString(UNITS);
|
Chris@2
|
131 tempoLate = getString(TEMPOLATE);
|
Chris@2
|
132 } // editParameters()
|
Chris@2
|
133
|
Chris@2
|
134 public void write(PrintStream out, int length, double outFramePeriod) {
|
Chris@2
|
135 out.println(VERSION + SEP + version);
|
Chris@2
|
136 out.println(FRAMEPERIOD + SEP + outFramePeriod);
|
Chris@2
|
137 out.println(UNITS + SEP + loudnessUnits);
|
Chris@2
|
138 if ((audioPath.length() > 0) && !audioPath.endsWith("/"))
|
Chris@2
|
139 audioPath += "/";
|
Chris@2
|
140 out.println(AUDIOFILE + SEP + audioPath + audioFile);
|
Chris@2
|
141 out.println(SMOOTHING + SEP + smoothing);
|
Chris@2
|
142 out.println(COMPOSER + SEP + composer);
|
Chris@2
|
143 out.println(PIECE + SEP + piece);
|
Chris@2
|
144 out.println(PERFORMER + SEP + performer);
|
Chris@2
|
145 out.println(BEATLEVEL + SEP + beatLevel);
|
Chris@2
|
146 out.println(TRACKLEVEL + SEP + trackLevel);
|
Chris@2
|
147 out.println(UPBEAT + SEP + upbeat);
|
Chris@2
|
148 out.println(STARTBAR + SEP + startBar);
|
Chris@2
|
149 out.println(BEATSPERBAR + SEP + beatsPerBar);
|
Chris@2
|
150 out.println(AXIS + SEP + axis);
|
Chris@2
|
151 out.println(TEMPOLATE + SEP + tempoLate);
|
Chris@2
|
152 out.println(LENGTH + SEP + length);
|
Chris@2
|
153 } // write()
|
Chris@2
|
154
|
Chris@2
|
155 public String read(BufferedReader in) throws IOException {
|
Chris@2
|
156 String input = in.readLine();
|
Chris@2
|
157 if (input == null)
|
Chris@2
|
158 throw new RuntimeException("Empty input file");
|
Chris@2
|
159 if (!input.startsWith("WORM"))
|
Chris@2
|
160 throw new RuntimeException("Bad header format: not a WORM file");
|
Chris@2
|
161 int delimiter = input.indexOf(SEPCHAR);
|
Chris@2
|
162 while (delimiter >= 0) {
|
Chris@2
|
163 String attribute = input.substring(0,delimiter).trim();
|
Chris@2
|
164 String value = input.substring(delimiter+1).trim();
|
Chris@2
|
165 if (attribute.equalsIgnoreCase(VERSION))
|
Chris@2
|
166 version = value;
|
Chris@2
|
167 else if (attribute.equalsIgnoreCase(FRAMEPERIOD))
|
Chris@2
|
168 framePeriod = Double.parseDouble(value);
|
Chris@2
|
169 else if (attribute.equalsIgnoreCase(UNITS))
|
Chris@2
|
170 loudnessUnits = value;
|
Chris@2
|
171 else if (attribute.equalsIgnoreCase(LENGTH))
|
Chris@2
|
172 length = Integer.parseInt(value);
|
Chris@2
|
173 else if (attribute.equalsIgnoreCase(AUDIOFILE)) {
|
Chris@2
|
174 int index = value.lastIndexOf('/');
|
Chris@2
|
175 if (index >= 0)
|
Chris@2
|
176 audioPath = value.substring(0, index);
|
Chris@2
|
177 audioFile = value.substring(index + 1);
|
Chris@2
|
178 } else if (attribute.equalsIgnoreCase(SMOOTHING))
|
Chris@2
|
179 smoothing = value;
|
Chris@2
|
180 else if (attribute.equalsIgnoreCase(COMPOSER))
|
Chris@2
|
181 composer = value;
|
Chris@2
|
182 else if (attribute.equalsIgnoreCase(PIECE))
|
Chris@2
|
183 piece = value;
|
Chris@2
|
184 else if (attribute.equalsIgnoreCase(PERFORMER))
|
Chris@2
|
185 performer = value;
|
Chris@2
|
186 else if (attribute.equalsIgnoreCase(KEY))
|
Chris@2
|
187 key = value;
|
Chris@2
|
188 else if (attribute.equalsIgnoreCase(INDICATION))
|
Chris@2
|
189 indication = value;
|
Chris@2
|
190 else if (attribute.equalsIgnoreCase(YEAR))
|
Chris@2
|
191 year = value;
|
Chris@2
|
192 else if (attribute.equalsIgnoreCase(BEATLEVEL))
|
Chris@2
|
193 beatLevel = value;
|
Chris@2
|
194 else if (attribute.equalsIgnoreCase(TRACKLEVEL))
|
Chris@2
|
195 trackLevel = value;
|
Chris@2
|
196 else if (attribute.equalsIgnoreCase(STARTBAR))
|
Chris@2
|
197 startBar = value;
|
Chris@2
|
198 else if (attribute.equalsIgnoreCase(UPBEAT))
|
Chris@2
|
199 upbeat = value;
|
Chris@2
|
200 else if (attribute.equalsIgnoreCase(BEATSPERBAR))
|
Chris@2
|
201 beatsPerBar = Integer.parseInt(value);
|
Chris@2
|
202 else if (attribute.equalsIgnoreCase(AXIS))
|
Chris@2
|
203 axis = value;
|
Chris@2
|
204 else if (attribute.equalsIgnoreCase(TEMPOLATE))
|
Chris@2
|
205 tempoLate = value;
|
Chris@2
|
206 else
|
Chris@2
|
207 System.err.println("Warning: Unrecognised header data: " +
|
Chris@2
|
208 attribute + SEP + value);
|
Chris@2
|
209 input = in.readLine();
|
Chris@2
|
210 if (input != null)
|
Chris@2
|
211 delimiter = input.indexOf(SEPCHAR);
|
Chris@2
|
212 else
|
Chris@2
|
213 break;
|
Chris@2
|
214 }
|
Chris@2
|
215 return input;
|
Chris@2
|
216 } // read()
|
Chris@2
|
217
|
Chris@2
|
218 public double getTrackLevel() {
|
Chris@2
|
219 try {
|
Chris@2
|
220 int i = trackLevel.indexOf("/");
|
Chris@2
|
221 if (i >= 0)
|
Chris@2
|
222 return Double.parseDouble(trackLevel.substring(0,i)) /
|
Chris@2
|
223 Double.parseDouble(trackLevel.substring(i+1));
|
Chris@2
|
224 else
|
Chris@2
|
225 return Double.parseDouble(trackLevel);
|
Chris@2
|
226 } catch (Exception e) {
|
Chris@2
|
227 System.err.println("Error getting TrackLevel:\n" + e);
|
Chris@2
|
228 return 1;
|
Chris@2
|
229 }
|
Chris@2
|
230 } // getTrackLevel()
|
Chris@2
|
231
|
Chris@2
|
232 } // WormParameters
|