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