Chris@2: /* Performance Worm: Visualisation of Expressive Musical Performance Chris@2: Copyright (C) 2001, 2006 by Simon Dixon Chris@2: Chris@2: This program is free software; you can redistribute it and/or modify Chris@2: it under the terms of the GNU General Public License as published by Chris@2: the Free Software Foundation; either version 2 of the License, or Chris@2: (at your option) any later version. Chris@2: Chris@2: This program is distributed in the hope that it will be useful, Chris@2: but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@2: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@2: GNU General Public License for more details. Chris@2: Chris@2: You should have received a copy of the GNU General Public License along Chris@2: with this program (the file gpl.txt); if not, download it from Chris@2: http://www.gnu.org/licenses/gpl.txt or write to the Chris@2: Free Software Foundation, Inc., Chris@2: 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Chris@2: */ Chris@2: Chris@2: package at.ofai.music.worm; Chris@2: Chris@2: import java.io.PrintStream; Chris@2: import java.io.BufferedReader; Chris@2: import java.io.IOException; Chris@2: import at.ofai.music.util.Parameters; Chris@2: Chris@2: public class WormParameters extends Parameters { Chris@2: Chris@2: static final long serialVersionUID = 0; Chris@2: public static final String VERSION = "WORM Version"; Chris@2: public static final String FRAMEPERIOD = "FrameLength"; Chris@2: public static final String COMPOSER = "Composer"; Chris@2: public static final String PIECE = "Piece"; Chris@2: public static final String PERFORMER = "Performer"; Chris@2: public static final String KEY = "Key"; Chris@2: public static final String YEAR = "YearOfRecording"; Chris@2: public static final String INDICATION = "Indication"; Chris@2: public static final String BEATLEVEL = "BeatLevel"; Chris@2: public static final String TRACKLEVEL = "TrackLevel"; Chris@2: public static final String STARTBAR = "StartBarNumber"; Chris@2: public static final String UPBEAT = "Upbeat"; Chris@2: public static final String BEATSPERBAR = "BeatsPerBar"; Chris@2: public static final String LENGTH = "Length"; Chris@2: public static final String AUDIOPATH = "AudioPath"; Chris@2: public static final String AUDIOFILE = "AudioFile"; Chris@2: public static final String SMOOTHING = "Smoothing"; Chris@2: public static final String AXIS = "Axis"; Chris@2: public static final String RESOLUTION = "Time Resolution"; Chris@2: public static final String UNITS = "LoudnessUnits"; Chris@2: public static final String TEMPOLATE = "TempoLate"; Chris@2: public static final String TITLE = "Edit Worm Parameters"; Chris@2: public static final String SEP = ":\t"; Chris@2: public static final char SEPCHAR = ':'; Chris@2: Chris@2: protected double framePeriod; Chris@2: protected String trackLevel, loudnessUnits, version, composer, piece, Chris@2: performer, key, year, indication, audioFile, audioPath, Chris@2: smoothing, axis, beatLevel, upbeat, startBar, tempoLate; Chris@2: protected int beatsPerBar, length; Chris@2: Chris@2: public WormParameters(java.awt.Frame f) { Chris@2: super(f, TITLE); Chris@2: composer = "Unknown composer"; Chris@2: piece = "unknown piece"; Chris@2: performer = "unknown performer"; Chris@2: key = ""; Chris@2: year = ""; Chris@2: indication = ""; Chris@2: beatLevel = "1/4"; Chris@2: trackLevel = "1.0"; Chris@2: upbeat = "0"; Chris@2: startBar = "1"; Chris@2: beatsPerBar = 4; Chris@2: length = 0; Chris@2: audioFile = ""; Chris@2: audioPath = ""; Chris@2: smoothing = ""; Chris@2: axis = ""; Chris@2: version = "1.0"; Chris@2: loudnessUnits = "dB"; Chris@2: tempoLate = ""; Chris@2: framePeriod = WormFile.defaultFramePeriod; Chris@2: } // constructor Chris@2: Chris@2: public void editParameters() { Chris@2: editParameters(true); Chris@2: } // editParameters() Chris@2: Chris@2: public void editParameters(boolean doEdit) { Chris@2: setString(COMPOSER, composer); Chris@2: setString(PIECE, piece); Chris@2: setString(PERFORMER, performer); Chris@2: setString(KEY, key); Chris@2: setString(YEAR, year); Chris@2: setString(INDICATION, indication); Chris@2: setString(BEATLEVEL, beatLevel); // e.g. 3/8 Chris@2: setString(TRACKLEVEL, trackLevel); Chris@2: setString(UPBEAT, upbeat); Chris@2: setString(STARTBAR, startBar); Chris@2: setInt(BEATSPERBAR, beatsPerBar); Chris@2: setInt(LENGTH, length); Chris@2: setString(AUDIOPATH, audioPath); Chris@2: setString(AUDIOFILE, audioFile); Chris@2: setString(SMOOTHING, smoothing); Chris@2: setString(AXIS, axis); Chris@2: setString(VERSION, version); Chris@2: setDouble(RESOLUTION, framePeriod); Chris@2: setString(UNITS, loudnessUnits); Chris@2: setString(TEMPOLATE, tempoLate); Chris@2: setVisible(doEdit); Chris@2: composer = getString(COMPOSER); Chris@2: piece = getString(PIECE); Chris@2: performer = getString(PERFORMER); Chris@2: key = getString(KEY); Chris@2: year = getString(YEAR); Chris@2: indication = getString(INDICATION); Chris@2: beatLevel = getString(BEATLEVEL); // e.g. 3/8 Chris@2: trackLevel = getString(TRACKLEVEL); Chris@2: upbeat = getString(UPBEAT); Chris@2: startBar = getString(STARTBAR); Chris@2: beatsPerBar = getInt(BEATSPERBAR); Chris@2: length = getInt(LENGTH); Chris@2: audioPath = getString(AUDIOPATH); Chris@2: audioFile = getString(AUDIOFILE); Chris@2: smoothing = getString(SMOOTHING); Chris@2: axis = getString(AXIS); Chris@2: version = getString(VERSION); Chris@2: framePeriod = getDouble(RESOLUTION); Chris@2: loudnessUnits = getString(UNITS); Chris@2: tempoLate = getString(TEMPOLATE); Chris@2: } // editParameters() Chris@2: Chris@2: public void write(PrintStream out, int length, double outFramePeriod) { Chris@2: out.println(VERSION + SEP + version); Chris@2: out.println(FRAMEPERIOD + SEP + outFramePeriod); Chris@2: out.println(UNITS + SEP + loudnessUnits); Chris@2: if ((audioPath.length() > 0) && !audioPath.endsWith("/")) Chris@2: audioPath += "/"; Chris@2: out.println(AUDIOFILE + SEP + audioPath + audioFile); Chris@2: out.println(SMOOTHING + SEP + smoothing); Chris@2: out.println(COMPOSER + SEP + composer); Chris@2: out.println(PIECE + SEP + piece); Chris@2: out.println(PERFORMER + SEP + performer); Chris@2: out.println(BEATLEVEL + SEP + beatLevel); Chris@2: out.println(TRACKLEVEL + SEP + trackLevel); Chris@2: out.println(UPBEAT + SEP + upbeat); Chris@2: out.println(STARTBAR + SEP + startBar); Chris@2: out.println(BEATSPERBAR + SEP + beatsPerBar); Chris@2: out.println(AXIS + SEP + axis); Chris@2: out.println(TEMPOLATE + SEP + tempoLate); Chris@2: out.println(LENGTH + SEP + length); Chris@2: } // write() Chris@2: Chris@2: public String read(BufferedReader in) throws IOException { Chris@2: String input = in.readLine(); Chris@2: if (input == null) Chris@2: throw new RuntimeException("Empty input file"); Chris@2: if (!input.startsWith("WORM")) Chris@2: throw new RuntimeException("Bad header format: not a WORM file"); Chris@2: int delimiter = input.indexOf(SEPCHAR); Chris@2: while (delimiter >= 0) { Chris@2: String attribute = input.substring(0,delimiter).trim(); Chris@2: String value = input.substring(delimiter+1).trim(); Chris@2: if (attribute.equalsIgnoreCase(VERSION)) Chris@2: version = value; Chris@2: else if (attribute.equalsIgnoreCase(FRAMEPERIOD)) Chris@2: framePeriod = Double.parseDouble(value); Chris@2: else if (attribute.equalsIgnoreCase(UNITS)) Chris@2: loudnessUnits = value; Chris@2: else if (attribute.equalsIgnoreCase(LENGTH)) Chris@2: length = Integer.parseInt(value); Chris@2: else if (attribute.equalsIgnoreCase(AUDIOFILE)) { Chris@2: int index = value.lastIndexOf('/'); Chris@2: if (index >= 0) Chris@2: audioPath = value.substring(0, index); Chris@2: audioFile = value.substring(index + 1); Chris@2: } else if (attribute.equalsIgnoreCase(SMOOTHING)) Chris@2: smoothing = value; Chris@2: else if (attribute.equalsIgnoreCase(COMPOSER)) Chris@2: composer = value; Chris@2: else if (attribute.equalsIgnoreCase(PIECE)) Chris@2: piece = value; Chris@2: else if (attribute.equalsIgnoreCase(PERFORMER)) Chris@2: performer = value; Chris@2: else if (attribute.equalsIgnoreCase(KEY)) Chris@2: key = value; Chris@2: else if (attribute.equalsIgnoreCase(INDICATION)) Chris@2: indication = value; Chris@2: else if (attribute.equalsIgnoreCase(YEAR)) Chris@2: year = value; Chris@2: else if (attribute.equalsIgnoreCase(BEATLEVEL)) Chris@2: beatLevel = value; Chris@2: else if (attribute.equalsIgnoreCase(TRACKLEVEL)) Chris@2: trackLevel = value; Chris@2: else if (attribute.equalsIgnoreCase(STARTBAR)) Chris@2: startBar = value; Chris@2: else if (attribute.equalsIgnoreCase(UPBEAT)) Chris@2: upbeat = value; Chris@2: else if (attribute.equalsIgnoreCase(BEATSPERBAR)) Chris@2: beatsPerBar = Integer.parseInt(value); Chris@2: else if (attribute.equalsIgnoreCase(AXIS)) Chris@2: axis = value; Chris@2: else if (attribute.equalsIgnoreCase(TEMPOLATE)) Chris@2: tempoLate = value; Chris@2: else Chris@2: System.err.println("Warning: Unrecognised header data: " + Chris@2: attribute + SEP + value); Chris@2: input = in.readLine(); Chris@2: if (input != null) Chris@2: delimiter = input.indexOf(SEPCHAR); Chris@2: else Chris@2: break; Chris@2: } Chris@2: return input; Chris@2: } // read() Chris@2: Chris@2: public double getTrackLevel() { Chris@2: try { Chris@2: int i = trackLevel.indexOf("/"); Chris@2: if (i >= 0) Chris@2: return Double.parseDouble(trackLevel.substring(0,i)) / Chris@2: Double.parseDouble(trackLevel.substring(i+1)); Chris@2: else Chris@2: return Double.parseDouble(trackLevel); Chris@2: } catch (Exception e) { Chris@2: System.err.println("Error getting TrackLevel:\n" + e); Chris@2: return 1; Chris@2: } Chris@2: } // getTrackLevel() Chris@2: Chris@2: } // WormParameters