Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

MeapaeMComposer.java

00001 /*
00002  *  Copyright 2006-2007 Columbia University.
00003  *
00004  *  This file is part of MEAPsoft.
00005  *
00006  *  MEAPsoft is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License version 2 as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  MEAPsoft is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with MEAPsoft; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  *  02110-1301 USA
00019  *
00020  *  See the file "COPYING" for the text of the license.
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                 // Parse arguments
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                 // parse arguments
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     //super simple demo composer() method
00137     //put your code in here!
00138         public EDLFile compose()
00139         {
00140                 Iterator c = featFile.chunks.iterator();
00141                 double currTime = 0;
00142 
00143                 //iterate through all the chunks that the segmenter found
00144                 while(c.hasNext())
00145                 {
00146                         //your current features chunk
00147                         FeatChunk ch = (FeatChunk)c.next();
00148 
00149                         //make a new EDL chunk from the current features chunk
00150                         EDLChunk original = new EDLChunk(ch, currTime);
00151                         //we're going to make one more chunk for the backwards part
00152                         EDLChunk backwards = new EDLChunk(ch, currTime+ch.length);
00153                         
00154                         //tell the 2nd chunk to add the reverse command so that
00155                         //when the synthsizer sees this chunk it will render the audio
00156                         //in reverse
00157                         backwards.commands.add("reverse");
00158 
00159                         //write both chunks out to the new EDL file                     
00160                         outFile.chunks.add(original);
00161                         outFile.chunks.add(backwards);
00162             
00163             //Increment currTime by twice the length of the chunk
00164             //since we've added two chunks. 
00165                         currTime += (ch.length * 2);
00166 
00167             progress.setValue(progress.getValue()+1);   
00168                 }
00169 
00170                 // outFile now contains some chunks.
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 }

Generated on Tue Feb 6 19:02:26 2007 for MEAPsoft by doxygen1.2.18