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.composers;
00024
00025 import gnu.getopt.Getopt;
00026
00027 import java.io.IOException;
00028 import java.text.NumberFormat;
00029 import java.util.Vector;
00030
00031 import com.meapsoft.ChunkDist;
00032 import com.meapsoft.EDLChunk;
00033 import com.meapsoft.EDLFile;
00034 import com.meapsoft.ParserException;
00035
00044 public class EDLComposer extends Composer
00045 {
00046 public static String description = "EDLComposer applies " +
00047 "composer options (gain, crossfade, etc.) to an existing " +
00048 ".edl file. It is meant to be used to generate output " +
00049 "from the visualizers.";
00050
00051 String outFileName = "visualized.edl";
00052
00053 EDLFile inEDLFile;
00054
00055
00056 boolean reverseSort = false;
00057 boolean debug = false;
00058 boolean normalizeFeatures = true;
00059
00060 public EDLComposer(String inEDLFN, String outEDLFN)
00061 {
00062 this(new EDLFile(inEDLFN), new EDLFile(outEDLFN));
00063 }
00064
00065 public EDLComposer(EDLFile inEDL, EDLFile outEDL)
00066 {
00067 this.inEDLFile = inEDL;
00068 outFile = outEDL;
00069
00070 if(outFile == null)
00071 outFile = new EDLFile(outFileName);
00072
00073
00074 writeMEAPFile = true;
00075 }
00076
00077 public void printUsageAndExit()
00078 {
00079 System.out.println("Usage: EDLComposer [-options] EDLFile.edl \n\n" +
00080 " where options include:\n" +
00081 " -o output_file the file to write the output to (defaults to sorted.edl)\n" +
00082 " -g debug mode (prints out chunk features on each line of output file)\n" +
00083 " -r sort in reverse order");
00084 printCommandLineOptions('i');
00085 printCommandLineOptions('d');
00086 printCommandLineOptions('c');
00087 System.out.println();
00088 System.exit(0);
00089 }
00090
00094 public EDLComposer(String[] args)
00095 {
00096 if(args.length == 0)
00097 printUsageAndExit();
00098
00099 Vector features = new Vector();
00100
00101
00102 String argString = "d:i:o:c:r:g";
00103
00104
00105 parseCommands(args, argString);
00106
00107 Getopt opt = new Getopt("EDLComposer", args, argString);
00108 opt.setOpterr(false);
00109
00110 int c = -1;
00111 while ((c =opt.getopt()) != -1)
00112 {
00113 switch(c)
00114 {
00115 case 'o':
00116 outFileName = opt.getOptarg();
00117 break;
00118 case 'r':
00119 reverseSort = true;
00120 break;
00121 case 'g':
00122 debug = true;
00123 break;
00124 case 'd':
00125 break;
00126 case 'i':
00127 break;
00128 case 'c':
00129 break;
00130 case '?':
00131 printUsageAndExit();
00132 break;
00133 default:
00134 System.out.print("getopt() returned " + c + "\n");
00135 }
00136 }
00137
00138
00139 int ind = opt.getOptind();
00140 if(ind > args.length)
00141 printUsageAndExit();
00142
00143 inEDLFile = new EDLFile(args[args.length-1]);
00144 outFile = new EDLFile(outFileName);
00145
00146 System.out.println("Composing " + outFileName +
00147 " from " + args[args.length-1] + ".");
00148 }
00149
00150 public void setReverseSort(boolean b)
00151 {
00152 reverseSort = b;
00153 }
00154
00155 public void setNormalizeFeatures(boolean b)
00156 {
00157 normalizeFeatures = b;
00158 }
00159
00160 public void setup() throws IOException, ParserException
00161 {
00162 super.setup();
00163
00164 if(!inEDLFile.haveReadFile)
00165 inEDLFile.readFile();
00166
00167 if(inEDLFile.chunks.size() == 0)
00168 throw new ParserException(inEDLFile.filename, "No chunks found");
00169
00170 if(normalizeFeatures)
00171 {
00172
00173 inEDLFile.normalizeFeatures();
00174 inEDLFile.applyFeatureWeights();
00175 }
00176
00177 progress.setMaximum(inEDLFile.chunks.size());
00178 }
00179
00180
00181 public EDLFile compose()
00182 {
00183 outFile.chunks = inEDLFile.chunks;
00184
00185
00186 outFile.haveReadFile = true;
00187
00188 return outFile;
00189 }
00190
00191 public static void main(String[] args)
00192 {
00193 EDLComposer m = new EDLComposer(args);
00194 long startTime = System.currentTimeMillis();
00195 m.run();
00196 System.out.println("Done. Took " +
00197 ((System.currentTimeMillis() - startTime)/1000.0)
00198 + "s");
00199 System.exit(0);
00200 }
00201 }