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.util.Iterator;
00029 import java.util.Vector;
00030
00031 import com.meapsoft.EDLChunk;
00032 import com.meapsoft.EDLFile;
00033 import com.meapsoft.FeatChunk;
00034 import com.meapsoft.FeatFile;
00035 import com.meapsoft.ParserException;
00036
00042 public class IntraChunkShuffleComposer extends Composer
00043 {
00044 public static String description = "IntraChunkShuffleComposer chops each chunk up into small pieces " +
00045 "and rearranges them. This keeps the meta chunks intact but scrambles " +
00046 "them on a local level.";
00047
00048 String outFileName = "shuffle.edl";
00049
00050 FeatFile featFile;
00051 boolean debug = false;
00052
00053 int numSubChunks = 4;
00054
00055 public IntraChunkShuffleComposer(String featFN, String outFN, int chunks)
00056 {
00057 this(new FeatFile(featFN), new EDLFile(outFN), chunks);
00058 }
00059
00060 public IntraChunkShuffleComposer(FeatFile featFN, EDLFile outFN, int chunks)
00061 {
00062 if (featFN == null || outFN == null)
00063 return;
00064
00065 featFile = featFN;
00066 outFile = outFN;
00067 numSubChunks = chunks;
00068
00069 if (numSubChunks <= 1)
00070 numSubChunks = 2;
00071
00072 if(outFile == null)
00073 outFile = new EDLFile("");
00074 }
00075
00076 public void printUsageAndExit()
00077 {
00078 System.out.println("Usage: IntraChunkShuffleComposer [-options] features.feat \n\n" +
00079 " where options include:\n" +
00080 " -o output_file the file to write the output to (defaults to shuffle.edl)\n" +
00081 " -n num_chunks the number of subchunks to divide each chunk into\n" +
00082 " -g debug mode (prints out chunk features on each line of output file)");
00083 System.out.println();
00084 System.exit(0);
00085 }
00086
00087 public IntraChunkShuffleComposer(String[] args)
00088 {
00089 if(args.length == 0)
00090 printUsageAndExit();
00091
00092 Vector features = new Vector();
00093
00094
00095 String argString = "o:n:g";
00096
00097 Getopt opt = new Getopt("IntraChunkShuffleComposer", args, argString);
00098 opt.setOpterr(false);
00099
00100 int c = -1;
00101 while ((c =opt.getopt()) != -1)
00102 {
00103 switch(c)
00104 {
00105 case 'o':
00106 outFileName = opt.getOptarg();
00107 break;
00108 case 'n':
00109 numSubChunks = new Integer(opt.getOptarg()).intValue();
00110 if (numSubChunks <= 1)
00111 numSubChunks = 2;
00112 case 'g':
00113 debug = true;
00114 break;
00115 case '?':
00116 printUsageAndExit();
00117 break;
00118 default:
00119 System.out.print("getopt() returned " + c + "\n");
00120 }
00121 }
00122
00123
00124 int ind = opt.getOptind();
00125 if(ind > args.length)
00126 printUsageAndExit();
00127
00128 featFile = new FeatFile(args[args.length-1]);
00129 outFile = new EDLFile(outFileName);
00130
00131 System.out.println("Composing " + outFileName +
00132 " from " + args[args.length-1] + ".");
00133 }
00134
00135 public void setup() throws IOException, ParserException
00136 {
00137 super.setup();
00138
00139 if(!featFile.haveReadFile)
00140 featFile.readFile();
00141
00142 if(featFile.chunks.size() == 0)
00143 throw new ParserException(featFile.filename, "No chunks found");
00144
00145 progress.setMaximum(featFile.chunks.size());
00146 }
00147
00148
00149 public EDLFile compose()
00150 {
00151 Iterator c = featFile.chunks.iterator();
00152 double currTime = 0;
00153
00154
00155 while(c.hasNext())
00156 {
00157
00158 FeatChunk ch = (FeatChunk)c.next();
00159 double length = ch.length/numSubChunks;
00160 double localStartTime = ch.startTime;
00161
00162 for (int i = numSubChunks - 1; i >= 0; i--)
00163 {
00164
00165
00166
00167 EDLChunk chunk = new EDLChunk(ch.srcFile,
00168 localStartTime + (i * length), length, currTime);
00169
00170
00171
00172
00173
00174 outFile.chunks.add(chunk);
00175
00176
00177
00178 currTime += length;
00179 }
00180
00181 progress.setValue(progress.getValue()+1);
00182 }
00183
00184
00185 outFile.haveReadFile = true;
00186
00187 return outFile;
00188 }
00189
00190 public static void main(String[] args)
00191 {
00192 IntraChunkShuffleComposer m = new IntraChunkShuffleComposer(args);
00193 long startTime = System.currentTimeMillis();
00194 m.run();
00195 System.out.println("Done. Took " +
00196 ((System.currentTimeMillis() - startTime)/1000.0)
00197 + "s");
00198 System.exit(0);
00199 }
00200 }