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.regex.Matcher;
00031
00038 public class EDLFile extends FeatFile
00039 {
00040 public EDLFile(String fn)
00041 {
00042 filename = fn;
00043
00044
00045 chunks = new MaxHeap(100);
00046 }
00047
00051 public void readFile() throws IOException, ParserException
00052 {
00053 BufferedReader in = new BufferedReader(new FileReader(filename));
00054
00055 String audioFile="";
00056 double dstTime;
00057 double chunkLength;
00058 double srcTime;
00059
00060
00061
00062
00063
00064 long lineno = 0;
00065 String line;
00066 while((line = in.readLine()) != null)
00067 {
00068 lineno++;
00069
00070
00071 String comment = "";
00072 Matcher c = commentPattern.matcher(line+"\n");
00073 if(c.find())
00074 {
00075
00076 comment = c.group() + line.substring(c.end()) + "\n";
00077 line = line.substring(0, c.start());
00078 }
00079
00080 Matcher p = linePattern.matcher(line);
00081
00082 if(!p.find())
00083 continue;
00084 try { dstTime = Double.parseDouble(p.group(1)); }
00085 catch(NumberFormatException nfe) {
00086 throw new ParserException(filename, lineno,
00087 "Could not parse dest start time \""
00088 + p.group(1) + "\"."); }
00089
00090 if(!p.find())
00091 throw new ParserException(filename, lineno,
00092 "Could not find source filename.");
00093 audioFile = p.group(1);
00094
00095 if(!p.find())
00096 throw new ParserException(filename, lineno,
00097 "Could not find source start time.");
00098 try { srcTime = Double.parseDouble(p.group(1)); }
00099 catch(NumberFormatException nfe) {
00100 throw new ParserException(filename, lineno,
00101 "Could not parse source start time \""
00102 + p.group(1) + "\"."); }
00103
00104 if(!p.find())
00105 throw new ParserException(filename, lineno,
00106 "Could not find chunk length.");
00107 try { chunkLength = Double.parseDouble(p.group(1)); }
00108 catch(NumberFormatException nfe) {
00109 throw new ParserException(filename, lineno,
00110 "Could not parse chunk length \""
00111 + p.group(1) + "\"."); }
00112
00113 EDLChunk ch = new EDLChunk(audioFile, srcTime, chunkLength, dstTime);
00114 ch.comment = comment;
00115
00116
00117 while(p.find())
00118 ch.commands.add(p.group(1));
00119
00120 chunks.add(ch);
00121 }
00122
00123 in.close();
00124 haveReadFile = true;
00125 }
00126
00127
00128 public double[][] getFeatures(int[] featdim)
00129 {
00130
00131 ((MaxHeap)chunks).sort();
00132
00133 double[][] f = super.getFeatures(featdim);
00134
00135
00136 ((MaxHeap)chunks).rebuildHeap();
00137
00138 return f;
00139 }
00140
00144 protected void write(Writer w) throws IOException
00145 {
00146
00147 w.write("# dst_time src_filename src_onset_time src_chunk_length [commands]\n");
00148
00149
00150 ((MaxHeap)chunks).sort();
00151
00152 Iterator i = chunks.iterator();
00153 while(i.hasNext())
00154 w.write(i.next().toString());
00155
00156
00157 ((MaxHeap)chunks).rebuildHeap();
00158 }
00159 }
00160