00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00099
00100
00101 FeatChunk currChunk = (FeatChunk)featFile.chunks.get(0);
00102
00103 dist.setTarget(currChunk);
00104
00105
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
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
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 }