00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package com.meapsoft;
00024
00025 import java.io.BufferedReader;
00026 import java.io.FileReader;
00027 import java.io.IOException;
00028 import java.io.Writer;
00029 import java.util.Iterator;
00030 import java.util.Vector;
00031 import java.util.regex.Matcher;
00032
00039 public class EDLFile extends FeatFile
00040 {
00041 public EDLFile(String fn)
00042 {
00043 filename = fn;
00044
00045
00046 chunks = new MaxHeap(100);
00047 }
00048
00052 public void readFile() throws IOException, ParserException
00053 {
00054 BufferedReader in = new BufferedReader(new FileReader(filename));
00055
00056 String audioFile="";
00057 double dstTime;
00058 double chunkLength;
00059 double srcTime;
00060
00061
00062
00063
00064
00065 long lineno = 0;
00066 String line;
00067 while((line = in.readLine()) != null)
00068 {
00069 lineno++;
00070
00071
00072 String comment = "";
00073 Matcher c = commentPattern.matcher(line+"\n");
00074 if(c.find())
00075 {
00076
00077 comment = c.group() + line.substring(c.end()) + "\n";
00078 line = line.substring(0, c.start());
00079 }
00080
00081 Matcher p = linePattern.matcher(line);
00082
00083 if(!p.find())
00084 continue;
00085 try { dstTime = Double.parseDouble(p.group(1)); }
00086 catch(NumberFormatException nfe) {
00087 throw new ParserException(filename, lineno,
00088 "Could not parse dest start time \""
00089 + p.group(1) + "\"."); }
00090
00091 if(!p.find())
00092 throw new ParserException(filename, lineno,
00093 "Could not find source filename.");
00094 audioFile = p.group(1);
00095
00096 audioFile = audioFile.replaceAll("%20", " ");
00097
00098 if(!p.find())
00099 throw new ParserException(filename, lineno,
00100 "Could not find source start time.");
00101 try { srcTime = Double.parseDouble(p.group(1)); }
00102 catch(NumberFormatException nfe) {
00103 throw new ParserException(filename, lineno,
00104 "Could not parse source start time \""
00105 + p.group(1) + "\"."); }
00106
00107 if(!p.find())
00108 throw new ParserException(filename, lineno,
00109 "Could not find chunk length.");
00110 try { chunkLength = Double.parseDouble(p.group(1)); }
00111 catch(NumberFormatException nfe) {
00112 throw new ParserException(filename, lineno,
00113 "Could not parse chunk length \""
00114 + p.group(1) + "\"."); }
00115
00116 EDLChunk ch = new EDLChunk(audioFile, srcTime, chunkLength, dstTime);
00117 ch.comment = comment;
00118
00119
00120 while(p.find())
00121 ch.commands.add(p.group(1));
00122
00123 chunks.add(ch);
00124 }
00125
00126 in.close();
00127 haveReadFile = true;
00128 }
00129
00134 public double[][] getFeatures()
00135 {
00136 return getFeatures(null);
00137 }
00138
00143 public double[][] getFeatures(int[] featdim)
00144 {
00145
00146 ((MaxHeap)chunks).sort();
00147
00148 double[][] f = super.getFeatures(featdim);
00149
00150
00151
00152 if(!((Heap)chunks).isHeap())
00153 ((MaxHeap)chunks).rebuildHeap();
00154
00155 return f;
00156 }
00157
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00185 protected void write(Writer w) throws IOException
00186 {
00187
00188 w.write("# dst_time src_filename src_onset_time src_chunk_length [commands]\n");
00189
00190
00191 ((MaxHeap)chunks).sort();
00192
00193 Iterator i = chunks.iterator();
00194 while(i.hasNext())
00195 w.write(i.next().toString());
00196
00197
00198 ((MaxHeap)chunks).rebuildHeap();
00199 }
00200 }
00201