Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

ShoobyComposer.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 java.text.NumberFormat;
00026 import java.util.*;
00027 
00028 import com.meapsoft.ChunkDist;
00029 import com.meapsoft.EDLChunk;
00030 import com.meapsoft.EDLFile;
00031 import com.meapsoft.FeatChunk;
00032 import com.meapsoft.FeatFile;
00033 import com.meapsoft.MaxHeap;
00034 import com.meapsoft.MinHeap;
00035 
00044 public class ShoobyComposer extends SortComposer
00045 {
00046         public static String description = "ShoobyComposer starts at the first chunk and proceeds through the sound file " +
00047         "from each chunk to its nearest neighbor, according to the features in the input features file.  " +
00048         "It then makes a drunken walk through the sorted file in the style of scat singer Shooby Taylor.";
00049         
00050         int outFileLength = 500;
00051         int maxClumpWidth = 6;
00052         int shoobyDrunkenness = 100;
00053         
00054     public ShoobyComposer(String featFN, String outFN, int outFileLength, int maxClumpWidth, int shoobyDrunkenness)
00055     {
00056         super(featFN, outFN);
00057         this.outFileLength = outFileLength;
00058                 this.maxClumpWidth = maxClumpWidth;
00059                 this.shoobyDrunkenness = shoobyDrunkenness;
00060     }
00061 
00062     public ShoobyComposer(FeatFile featFN, EDLFile outFN, int outFileLength, int maxClumpWidth, int shoobyDrunkenness)
00063     {
00064         super(featFN, outFN);
00065         this.outFileLength = outFileLength;
00066                 this.maxClumpWidth = maxClumpWidth;
00067                 this.shoobyDrunkenness = shoobyDrunkenness;
00068     }
00069 
00070     public ShoobyComposer(FeatFile featFN, EDLFile outFN)
00071     {
00072         super(featFN, outFN);
00073     }
00074     
00075     public void printUsageAndExit() 
00076     {
00077         System.out.println("Usage: ShoobyComposer [-options] features.feat \n\n" + 
00078                        "  where options include:\n" + 
00079                        "    -o output_file  the file to write the output to (defaults to sorted.edl)\n" +
00080                "    -g              debug mode (prints out chunk features on each line of output file)");
00081         printCommandLineOptions('i');
00082         printCommandLineOptions('d');
00083         printCommandLineOptions('c');
00084         System.out.println();
00085         System.exit(0);
00086     }
00087 
00091     public ShoobyComposer(String[] args) 
00092     {
00093         super(args);
00094     }
00095 
00096     public EDLFile compose()
00097     {
00098         // initial chunk - pick it at random:
00099         //int randIdx = (int)Math.floor(featFile.chunks.size()*Math.random());
00100         // start with the first chunk
00101         FeatChunk currChunk = (FeatChunk)featFile.chunks.get(0);
00102         
00103         dist.setTarget(currChunk);
00104         
00105         // maintain a set of chunks sorted using dist from targetChunk
00106         MinHeap chunks = new MinHeap(dist);
00107         chunks.addAll(featFile.chunks);
00108         
00109         MaxHeap chunks2 = new MaxHeap(500);
00110         
00111         NumberFormat fmt = NumberFormat.getInstance();
00112         fmt.setMaximumFractionDigits(3);
00113         
00114         double currTime = 0;
00115         while(chunks.size() > 0)
00116         {
00117             dist.setTarget(currChunk);
00118             chunks.rebuildHeap();
00119             
00120             currChunk = (FeatChunk)chunks.deleteMin();
00121             
00122             // turn currChunk into an EDL chunk 
00123             EDLChunk nc = new EDLChunk(currChunk, currTime);
00124 
00125             chunks2.add(nc);
00126          
00127             currTime += currChunk.length;
00128 
00129             progress.setValue(progress.getValue()+1);   
00130         }
00131         
00132                 double currTime2 = 0;
00133                 Random rand = new Random();
00134                 int pointer;
00135                 int pointer2;
00136                 int clumpWidth;
00137                 int moveWidth;
00138                 
00139                 while(currTime2<=outFileLength)
00140                 {
00141                         pointer = rand.nextInt((int)chunks2.size());
00142                         clumpWidth = rand.nextInt(maxClumpWidth)+1;
00143                         moveWidth = rand.nextInt(13)+13;
00144                         int pointersSize = 2+rand.nextInt(3);
00145                         int pointers[] = new int[pointersSize];
00146                         pointers[0]=pointer;
00147                         for ( int pi = 1; pi<pointersSize; pi++) {
00148                                 pointers[pi] = pointers[0]+rand.nextInt(moveWidth);
00149                         };
00150                         for (int i = 0; i<rand.nextInt(maxClumpWidth)+1; i++) {
00151                                 pointer = pointers[rand.nextInt(pointersSize)];
00152                                 for (int i2 = 0; i2<rand.nextInt(maxClumpWidth)+1; i2++)
00153                                 {
00154                                         pointer2 = pointers[rand.nextInt(pointersSize)] + rand.nextInt(clumpWidth+1);
00155                                         if (pointer2>(chunks2.size()-1))
00156                                         {
00157                                                 pointer2 = chunks2.size()-1;
00158                                         }
00159                                         EDLChunk currChunk2 = (EDLChunk)chunks2.get(pointer2);
00160                                         EDLChunk nc = new EDLChunk(currChunk2.srcFile, currChunk2.startTime, currChunk2.length, currTime2);
00161                                         outFile.chunks.add(nc);
00162                                         currTime2 += nc.length;
00163                                 }
00164                         }
00165                 }
00166                 
00167         // outFile now contains some chunks.
00168         outFile.haveReadFile = true;
00169 
00170         return outFile;
00171     } 
00172     
00173     public static void main(String[] args) 
00174     {
00175         ShoobyComposer m = new ShoobyComposer(args);
00176         long startTime = System.currentTimeMillis();
00177 
00178         m.run();
00179 
00180         System.out.println("Done. Took " +
00181                            ((System.currentTimeMillis() - startTime)/1000.0)
00182                            + "s");
00183         System.exit(0);
00184     }
00185 }

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