Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

EDLComposer.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.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     //int[] featdim = null;
00055     //ChunkDist dist;
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         //make sure we write out the edl file    
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         // Parse arguments
00102         String argString = "d:i:o:c:r:g";
00103        // featdim = parseFeatDim(args, argString);
00104         //dist = parseChunkDist(args, argString, featdim);
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':  // already handled above
00125                 break;
00126             case 'i':  // already handled above
00127                 break;
00128             case 'c':  // already handled above
00129                 break;
00130             case '?':
00131                 printUsageAndExit();
00132                 break;
00133             default:
00134                 System.out.print("getopt() returned " + c + "\n");
00135             }
00136         }
00137         
00138         // parse arguments
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 //            inEDLFile = (EDLFile) inEDLFile.clone();
00173             inEDLFile.normalizeFeatures();
00174             inEDLFile.applyFeatureWeights();
00175         }
00176 
00177         progress.setMaximum(inEDLFile.chunks.size());
00178     }
00179 
00180         //super complicated compose() method!!!    
00181     public EDLFile compose()
00182     {
00183         outFile.chunks = inEDLFile.chunks;
00184 
00185         // outFile now contains some chunks.
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 }

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