00001 package com.meapsoft.composers;
00002
00003 import gnu.getopt.Getopt;
00004
00005 import java.io.IOException;
00006 import java.util.Iterator;
00007 import java.util.Vector;
00008
00009 import com.meapsoft.EDLChunk;
00010 import com.meapsoft.EDLFile;
00011 import com.meapsoft.FeatChunk;
00012 import com.meapsoft.FeatFile;
00013 import com.meapsoft.ParserException;
00014
00020 public class BlipComposer extends Composer
00021 {
00022 public static String description = "Inserts a blip at the beginning of each chunk in the input " +
00023 "features file. Especially useful for understanding the output of the " +
00024 "segmenter.";
00025
00026 String outFileName = "blipped.edl";
00027
00028 FeatFile featFile;
00029 boolean debug = false;
00030
00031 public BlipComposer(String featFN, String outFN)
00032 {
00033 this(new FeatFile(featFN), new EDLFile(outFN));
00034 }
00035
00036 public BlipComposer(FeatFile featFN, EDLFile outFN)
00037 {
00038 if (featFN == null || outFN == null)
00039 return;
00040
00041 featFile = featFN;
00042 outFile = outFN;
00043
00044 if(outFile == null)
00045 outFile = new EDLFile("");
00046 }
00047
00048 public void printUsageAndExit()
00049 {
00050 System.out.println("Usage: BlipComposer [-options] features.feat \n\n" +
00051 " where options include:\n" +
00052 " -o output_file the file to write the output to (defaults to blipped.edl)\n" +
00053 " -g debug mode (prints out chunk features on each line of output file)");
00054 printCommandLineOptions('c');
00055 System.out.println();
00056 System.exit(0);
00057 }
00058
00059 public BlipComposer(String[] args)
00060 {
00061 if(args.length == 0)
00062 printUsageAndExit();
00063
00064 Vector features = new Vector();
00065
00066
00067 String argString = "o:c:g";
00068 parseCommands(args, argString);
00069
00070 Getopt opt = new Getopt("BlipComposer", args, argString);
00071 opt.setOpterr(false);
00072
00073 int c = -1;
00074 while ((c =opt.getopt()) != -1)
00075 {
00076 switch(c)
00077 {
00078 case 'o':
00079 outFileName = opt.getOptarg();
00080 break;
00081 case 'g':
00082 debug = true;
00083 break;
00084 case 'c':
00085 break;
00086 case '?':
00087 printUsageAndExit();
00088 break;
00089 default:
00090 System.out.print("getopt() returned " + c + "\n");
00091 }
00092 }
00093
00094
00095 int ind = opt.getOptind();
00096 if(ind > args.length)
00097 printUsageAndExit();
00098
00099 featFile = new FeatFile(args[args.length-1]);
00100 outFile = new EDLFile(outFileName);
00101
00102 System.out.println("Composing " + outFileName +
00103 " from " + args[args.length-1] + ".");
00104 }
00105
00106 public void setup() throws IOException, ParserException
00107 {
00108 super.setup();
00109
00110 if(!featFile.haveReadFile)
00111 featFile.readFile();
00112
00113 if(featFile.chunks.size() == 0)
00114 throw new ParserException(featFile.filename, "No chunks found");
00115 }
00116
00117 public EDLFile compose()
00118 {
00119 Iterator c = featFile.chunks.iterator();
00120 double currTime = 0;
00121
00122 while(c.hasNext())
00123 {
00124 FeatChunk ch = (FeatChunk)c.next();
00125
00126 EDLChunk nc = new EDLChunk(ch, currTime);
00127
00128 EDLChunk blip = new EDLChunk("data" +
00129 System.getProperty("file.separator") + "blip.wav",
00130 0, 0.1, currTime);
00131
00132 outFile.chunks.add(blip);
00133 outFile.chunks.add(nc);
00134
00135 currTime += ch.length;
00136 }
00137
00138
00139 outFile.haveReadFile = true;
00140
00141 return outFile;
00142 }
00143
00144 public String description()
00145 {
00146 return description;
00147 }
00148
00149 public static void main(String[] args)
00150 {
00151 BlipComposer m = new BlipComposer(args);
00152 long startTime = System.currentTimeMillis();
00153 m.go();
00154 System.out.println("Done. Took " +
00155 ((System.currentTimeMillis() - startTime)/1000.0)
00156 + "s");
00157 System.exit(0);
00158 }
00159 }