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 MeapaeMComposer extends Composer
00043 {
00044 public static String description = "MeapaeMComposer makes palindromes by writing " +
00045 "each chunk of audio forward and then backward.";
00046
00047 String outFileName = "meapaem.edl";
00048
00049 FeatFile featFile;
00050 boolean debug = false;
00051
00052 public MeapaeMComposer(String featFN, String outFN)
00053 {
00054 this(new FeatFile(featFN), new EDLFile(outFN));
00055 }
00056
00057 public MeapaeMComposer(FeatFile featFN, EDLFile outFN)
00058 {
00059 if (featFN == null || outFN == null)
00060 return;
00061
00062 featFile = featFN;
00063 outFile = outFN;
00064
00065 if(outFile == null)
00066 outFile = new EDLFile("");
00067 }
00068
00069 public void printUsageAndExit()
00070 {
00071 System.out.println("Usage: MeapeaMComposer [-options] features.feat \n\n" +
00072 " where options include:\n" +
00073 " -o output_file the file to write the output to (defaults to meapeam.edl)\n" +
00074 " -g debug mode (prints out chunk features on each line of output file)");
00075 System.out.println();
00076 System.exit(0);
00077 }
00078
00079 public MeapaeMComposer(String[] args)
00080 {
00081 if(args.length == 0)
00082 printUsageAndExit();
00083
00084 Vector features = new Vector();
00085
00086
00087 String argString = "o:g";
00088
00089 Getopt opt = new Getopt("MeapaeMComposer", args, argString);
00090 opt.setOpterr(false);
00091
00092 int c = -1;
00093 while ((c =opt.getopt()) != -1)
00094 {
00095 switch(c)
00096 {
00097 case 'o':
00098 outFileName = opt.getOptarg();
00099 break;
00100 case 'g':
00101 debug = true;
00102 break;
00103 case '?':
00104 printUsageAndExit();
00105 break;
00106 default:
00107 System.out.print("getopt() returned " + c + "\n");
00108 }
00109 }
00110
00111
00112 int ind = opt.getOptind();
00113 if(ind > args.length)
00114 printUsageAndExit();
00115
00116 featFile = new FeatFile(args[args.length-1]);
00117 outFile = new EDLFile(outFileName);
00118
00119 System.out.println("Composing " + outFileName +
00120 " from " + args[args.length-1] + ".");
00121 }
00122
00123 public void setup() throws IOException, ParserException
00124 {
00125 super.setup();
00126
00127 if(!featFile.haveReadFile)
00128 featFile.readFile();
00129
00130 if(featFile.chunks.size() == 0)
00131 throw new ParserException(featFile.filename, "No chunks found");
00132
00133 progress.setMaximum(featFile.chunks.size());
00134 }
00135
00136
00137
00138 public EDLFile compose()
00139 {
00140 Iterator c = featFile.chunks.iterator();
00141 double currTime = 0;
00142
00143
00144 while(c.hasNext())
00145 {
00146
00147 FeatChunk ch = (FeatChunk)c.next();
00148
00149
00150 EDLChunk original = new EDLChunk(ch, currTime);
00151
00152 EDLChunk backwards = new EDLChunk(ch, currTime+ch.length);
00153
00154
00155
00156
00157 backwards.commands.add("reverse");
00158
00159
00160 outFile.chunks.add(original);
00161 outFile.chunks.add(backwards);
00162
00163
00164
00165 currTime += (ch.length * 2);
00166
00167 progress.setValue(progress.getValue()+1);
00168 }
00169
00170
00171 outFile.haveReadFile = true;
00172
00173 return outFile;
00174 }
00175
00176 public static void main(String[] args)
00177 {
00178 MeapaeMComposer m = new MeapaeMComposer(args);
00179 long startTime = System.currentTimeMillis();
00180 m.run();
00181 System.out.println("Done. Took " +
00182 ((System.currentTimeMillis() - startTime)/1000.0)
00183 + "s");
00184 System.exit(0);
00185 }
00186 }