Main Page   Class Hierarchy   Compound List   File List   Compound Members  

Composer.java

00001 /*
00002  *  Copyright 2006 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         public static String description = "I am a generic Composer.";
00045     // The EDL file that this composer generates
00046     EDLFile outFile;
00047     // Commands to be applied to all
00048     Vector commands = null;
00049 
00056     public void setup() throws IOException, ParserException
00057     {
00058         // clear old EDL
00059         outFile.clearChunks(); 
00060     }
00061 
00065     public abstract EDLFile compose();
00066 
00067     /*
00068      * Setup, compose, and write output file
00069      */
00070     public void go()
00071     {
00072         try
00073         {
00074             setup();
00075             compose();
00076             addCommandsToAllEDLChunks();
00077             outFile.writeFile();
00078         }
00079         catch(Exception e)
00080         {
00081             e.printStackTrace();
00082             System.exit(1);
00083         }
00084     }
00085 
00086 
00090     public void addCommandToAllEDLChunks(String cmd)
00091     {
00092         if(outFile != null)
00093         {
00094             Iterator i = outFile.chunks.iterator();
00095             while(i.hasNext())
00096             {
00097                 EDLChunk chunk = (EDLChunk)i.next();
00098 
00099                 if(chunk.commands != null)
00100                     chunk.commands.add(cmd);
00101             }
00102         }
00103     }
00104 
00108     public void addCommandsToAllEDLChunks(Vector cmds)
00109     {
00110         Iterator i = cmds.iterator();
00111         while(i.hasNext())
00112             addCommandToAllEDLChunks((String)i.next());
00113     }
00114 
00115     public void addCommandsToAllEDLChunks()
00116     {
00117         if(commands != null)
00118             addCommandsToAllEDLChunks(commands);
00119     }
00120 
00124     public void addCommand(String cmd)
00125     {
00126         if(commands == null)
00127             commands = new Vector();
00128 
00129         commands.add(cmd);
00130     }
00131 
00132     public static void printCommandLineOptions(char arg)
00133     {
00134         if(arg == 'c')
00135         {
00136             System.out.println(
00137                 "    -c command      apply command to all chunks in the EDL output file\n" +
00138                 "                    Supported commands include: reverse, crossfade(time), overlap(time) (time in seconds)" +
00139                 "");
00140         }
00141         else
00142             MEAPUtil.printCommandLineOptions(arg);
00143     }
00144 
00148     public void parseCommands(String[] args, String argString)
00149     {
00150         Getopt opt = new Getopt("Composer", args, argString);
00151         opt.setOpterr(false);
00152         
00153         int c = -1;
00154         while ((c = opt.getopt()) != -1) 
00155         {
00156             if(c == 'c') 
00157             {
00158                 if(commands == null)
00159                     commands = new Vector();
00160                 
00161                 commands.add(opt.getOptarg());
00162             }
00163         }
00164     }
00165 }

Generated on Thu May 11 15:04:10 2006 for MEAPsoft by doxygen1.2.18