PageRenderTime 66ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/AudioGen4MusicSegmentation/src/main/java/umslt/agmsa/Expander.java

http://umslt.googlecode.com/
Java | 70 lines | 53 code | 8 blank | 9 comment | 2 complexity | a0e177a8eff78d13502099e89509125f MD5 | raw file
Possible License(s): BSD-2-Clause
  1. package umslt.agmsa;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.util.Properties;
  7. import umslt.agmsa.util.Exec;
  8. public class Expander {
  9. private String sectionsDirectory;
  10. private final Integer secTimeInSec;
  11. private final String outputfile;
  12. /**
  13. * @param totalTimeInSeconds
  14. * @param forceallsections
  15. * @param forceonepersection
  16. */
  17. public Expander(String sectionsDirectory,
  18. String outputfile, Integer secTimeInSec) {
  19. this.sectionsDirectory = sectionsDirectory;
  20. this.outputfile = outputfile;
  21. this.secTimeInSec = secTimeInSec;
  22. }
  23. public void run() throws Exception {
  24. RandomSection rndSection = new RandomSection(this.sectionsDirectory, true, -1);
  25. createScoreFile(rndSection);
  26. }
  27. private void createScoreFile(RandomSection rndSection) throws Exception, IOException {
  28. int len = rndSection.sections.length;
  29. while(len-- > 0) {
  30. String nextSection = rndSection.nextSection(0, secTimeInSec);
  31. FileWriter fw = null;
  32. try {
  33. //write score file
  34. fw = new FileWriter(outputfile + "#"+ len + ".sco");
  35. fw.write(rndSection.getTableDefinitions());
  36. //clear table names
  37. rndSection.usedTableDefinitions.clear();
  38. fw.write(nextSection.toString());
  39. fw.flush();
  40. } finally {
  41. if (fw != null)
  42. fw.close();
  43. }
  44. //render wav file
  45. Exec.execPrintWait("csound -d -W -o " + outputfile + "#"+ len + ".wav bricolage.orc " + outputfile + "#"+ len + ".sco");
  46. //create transition file
  47. }
  48. }
  49. public static void main(String[] args) {
  50. Properties prop = new Properties();
  51. try {
  52. prop.load(new FileInputStream(new File("./bricolage.properties")));
  53. String sectionsDirectory = prop.getProperty("wav.dir");
  54. Integer secTimeInSec = new Integer(prop.getProperty("force.sectime"));
  55. String outputfile = prop.getProperty("output.file");
  56. Expander main = new Expander(sectionsDirectory, outputfile, secTimeInSec);
  57. main.run();
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. }
  61. }
  62. }