Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

Composer.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.MEAPUtil;
00034 import com.meapsoft.ParserException;
00035 
00042 public abstract class Composer extends MEAPUtil
00043 {
00044     // Short description of this composer
00045         public static String description = "I am a generic Composer.";
00046 
00047     // The EDL file that this composer generates
00048     EDLFile outFile;
00049 
00050     // Commands to be applied to all
00051     Vector commands = null;
00052 
00059     public void setup() throws IOException, ParserException
00060     {
00061         // clear old EDL
00062         outFile.clearChunks(); 
00063 
00064         // keep track of our progress in composing:
00065         progress.setMinimum(0);
00066         progress.setValue(0);
00067     }
00068 
00072     public abstract EDLFile compose();
00073 
00074     /*
00075      * Setup, compose, and write output file.  Handles exceptions.
00076      */
00077     public void run()
00078     {
00079         try
00080         {
00081             doComposer();
00082         }
00083         catch(Exception e)
00084         {
00085             exceptionHandler.handleException(e);
00086         }
00087     }
00088 
00093     public void doComposer() throws IOException, ParserException
00094     {
00095         //System.out.println("Composer: doing setup...");
00096         setup();
00097                 //System.out.println("Composer: doing compose...");
00098         compose();
00099                 //System.out.println("Composer: adding commands...");
00100         addCommandsToAllEDLChunks();
00101                 //System.out.println("Composer: writing file...");
00102         if(writeMEAPFile)
00103         {
00104             outFile.writeFile();
00105                         //System.out.println("filename: " + outFile.filename);
00106         }
00107                 //System.out.println("Composer: finished!");
00108     }
00109 
00113     public void addCommandToAllEDLChunks(String cmd)
00114     {
00115         if(outFile != null)
00116         {
00117             Iterator i = outFile.chunks.iterator();
00118             while(i.hasNext())
00119             {
00120                 EDLChunk chunk = (EDLChunk)i.next();
00121 
00122                 if(chunk.commands != null)
00123                     chunk.commands.add(cmd);
00124             }
00125         }
00126     }
00127 
00131     public void addCommandsToAllEDLChunks(Vector cmds)
00132     {
00133         Iterator i = cmds.iterator();
00134         while(i.hasNext())
00135             addCommandToAllEDLChunks((String)i.next());
00136     }
00137 
00138     public void addCommandsToAllEDLChunks()
00139     {
00140         if(commands != null)
00141             addCommandsToAllEDLChunks(commands);
00142     }
00143 
00147     public void addCommand(String cmd)
00148     {
00149         if(commands == null)
00150             commands = new Vector();
00151 
00152         commands.add(cmd);
00153     }
00154 
00158     public static void printCommandLineOptions(char arg)
00159     {
00160         if(arg == 'c')
00161         {
00162             System.out.println(
00163                 "    -c command      apply command to all chunks in the EDL output file\n" +
00164                 "                    Supported commands include: reverse, crossfade(time), overlap(time) (time in seconds), gain(x)." +
00165                 "");
00166         }
00167         else
00168             MEAPUtil.printCommandLineOptions(arg);
00169     }
00170 
00174     public void parseCommands(String[] args, String argString)
00175     {
00176         Getopt opt = new Getopt("Composer", args, argString);
00177         opt.setOpterr(false);
00178         
00179         int c = -1;
00180         while ((c = opt.getopt()) != -1) 
00181         {
00182             if(c == 'c') 
00183             {
00184                 if(commands == null)
00185                     commands = new Vector();
00186                 
00187                 commands.add(opt.getOptarg());
00188             }
00189         }
00190     }
00191 
00192         public String description()
00193         {
00194                 return description;
00195         }
00196 }

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