static { root = new Key(); root.name = "<root>"; root.subKeys = new java.util.HashMap(); java.io.File aliceHasNotExitedFile = new java.io.File( edu.cmu.cs.stage3.alice.authoringtool.JAlice.getAliceUserDirectory(), "aliceHasNotExited.txt"); if (aliceHasNotExitedFile.canRead()) { try { storeConfig(); } catch (java.io.IOException e2) { edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog( java.util.ResourceBundle.getBundle( "edu/cmu/cs/stage3/alice/authoringtool/util/Configuration") .getString("UNABLE_TO_CREATE_NEW_PREFERENCES_FILE."), e2); } } else { try { loadConfig(configLocation); } catch (Exception e) { } } }
private static void storeConfig(java.io.OutputStream os) throws java.io.IOException { javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); try { javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder(); org.w3c.dom.Document document = builder.newDocument(); org.w3c.dom.Element rootElement = document.createElement("configuration"); document.appendChild(rootElement); if (root.subKeys != null) { for (java.util.Iterator iter = root.subKeys.values().iterator(); iter.hasNext(); ) { Key key = (Key) iter.next(); rootElement.appendChild(makeKeyElement(document, key)); } } document.getDocumentElement().normalize(); edu.cmu.cs.stage3.xml.Encoder.write(document, os); // try { // Class documentClass = document.getClass(); // java.lang.reflect.Method writeMethod = documentClass.getMethod( "write", new Class[] { // java.io.OutputStream.class } ); // writeMethod.invoke( document, new Object[] { os } ); // } catch( Exception e ) { // edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog( "Unable to store // preferences. Cannot invoke 'write' method.", e ); // } // ((org.apache.crimson.tree.XmlDocument)document).write( os ); // ((com.sun.xml.tree.XmlDocument)document).write( os ); } catch (javax.xml.parsers.ParserConfigurationException pce) { edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog( java.util.ResourceBundle.getBundle( "edu/cmu/cs/stage3/alice/authoringtool/util/Configuration") .getString("ERROR_PARSING_PREFERENCES_FILE."), pce); } }
public Vector encodeFiles(double length, String exportDirectory) // get { Vector newDS = new Vector(); String orig_file = "", final_sound = "", sound_slice = "", sound_cut = "", track_file = "", silence = exportDirectory + "silence.wav"; int currentChunk = 0; int currentLength = 0; convertTimes(); convertCaptureTimes(); // print("size of length " + soundList.size()); for (int y = 0; y < soundList.size(); y++) { double blankLength = 0; SoundData sd = (SoundData) soundList.get(y); if ((sd.duration < sd.clippedDuration) || (sd.clippedDuration == 0.0)) sd.clippedDuration = sd.duration; sd.stopTime = sd.duration; while (sd.worldTime > ((Double) stopCaptureTimes.get(currentChunk)).doubleValue()) { currentLength += ((Double) stopCaptureTimes.get(currentChunk)).doubleValue(); currentChunk++; if (currentChunk >= stopCaptureTimes.size()) break; } // if no more capturing Chunks OR start+duration <startCapture if (currentChunk >= stopCaptureTimes.size()) break; if (((Double) startCaptureTimes.get(currentChunk)).doubleValue() > (sd.worldTime + sd.clippedDuration)) continue; // know that sound must intersect with capturing // print("Current Chunk Values: Start "+ startCaptureTimes.get(currentChunk) + " Stop: " + // stopCaptureTimes.get(currentChunk)); // print("Current Sound: Start " + sd.worldTime + " End: " + (sd.worldTime + // sd.clippedDuration)); if (sd.worldTime > ((Double) startCaptureTimes.get(currentChunk)).doubleValue()) { blankLength = sd.worldTime - ((Double) startCaptureTimes.get(currentChunk)).doubleValue() + currentLength; } else { blankLength = currentLength; } orig_file = exportDirectory + "sound" + y + "." + sd.data.getExtension(); sound_slice = exportDirectory + "sound" + y + ".wav"; sound_cut = exportDirectory + "soundCut" + y + ".wav"; track_file = exportDirectory + "track" + y + ".wav"; writeToFile(sd.data.getJMFDataSource(), createURL(orig_file)); if (sd.data.getExtension().equals("MP3")) { // print("About to try and Convert!" + sound_slice + " " + orig_file); SimpleSound.convert(orig_file, sound_slice); } // try to crop sound if necessary double beginning = 0.0; double ending = 0.0; beginning = cropBeginning(sd, length, currentChunk); ending = cropEnding(sd, length, currentChunk); // print("Trying to Cut"); if (beginning != 0 || ending != 0) { sound_slice = tryToCut(length, sd, sound_slice, sound_cut, beginning, ending, blankLength); } // if ( sound_slice.endsWith(".wav") ){ // String filename = "file:" + sound_slice.replace('/', '\\'); // SaveAsDialog dlgSaveAs = new SaveAsDialog (new Frame(), filename, null, null); // sound_slice = sound_slice.substring(0, sound_slice.length() - 4) + "a.wav"; // } // create sound try { SimpleSound s = new SimpleSound(); s.loadFromFile(sound_slice); // create silent sound of length blankLength, and type s SimpleSound blank = new SimpleSound(blankLength, s); blank.writeToFile(silence); } catch (SoundException e) { AuthoringTool.showErrorDialog("Error encoding sound file. ", e); return null; } if (blankLength > 0.0) { Vector v = new Vector(); v.add(createURL(silence)); v.add(createURL(sound_slice)); final_sound = createURL(track_file); if (concat(v, final_sound) == false) return null; } else { // print("No SILENCE"); final_sound = createURL(sound_slice); } // print("Sound " + y); newDS.add(final_sound); } // merging sounds!! // print(" Right before merging "); return newDS; }