Advertisement
Guest User

Untitled

a guest
Dec 26th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. public class Sampleholder extends Chubgraph
  2. {
  3. SndBuf buffy;
  4. string path;
  5. string sampleLocation;
  6.  
  7. buffy => outlet;
  8.  
  9. fun void setSamplePath(string givenPath)
  10. {
  11. givenPath => path;
  12. }
  13.  
  14. fun void setSample(string filename)
  15. {
  16. path + "/" + filename => sampleLocation;
  17.  
  18. sampleLocation => buffy.read;
  19.  
  20. buffy.samples() => buffy.pos;
  21. }
  22.  
  23. fun void setPositionToStart()
  24. {
  25. 0 => buffy.pos;
  26. }
  27.  
  28. fun void setPositionToEnd()
  29. {
  30. buffy.samples() => buffy.pos;
  31. }
  32. }
  33.  
  34. /**************************************************************************************/
  35. /* GLOBAL VARIABLES */
  36. /**************************************************************************************/
  37.  
  38. // OSC stuff
  39. OscRecv recv;
  40. 8001 => recv.port;
  41. recv.listen();
  42.  
  43. // define BPM
  44. 120.0 => float BPM;
  45. 4 => int signature;
  46. 60.0 / BPM => float crotchet; //float representing the number of seconds that a crotched lasts
  47. crotchet::second => dur cr;
  48. signature::cr => dur bar;
  49.  
  50. // master gain
  51. Gain masterGain => dac;
  52.  
  53. // array of files to load
  54. [
  55. [me.dir(-5) + "/Samples/DISCRETEENERGYII[SAMPLE PACK]/SYNTHS", "152bpm_UO_BELLS_C.wav"]
  56. ] @=> string files[][];
  57.  
  58. /**************************************************************************************/
  59. /* SHREDS */
  60. /**************************************************************************************/
  61. fun void touchSampleShred(int sampleIndex, Sampleholder sample)
  62. {
  63. recv.event("/chooper/touchsample/" + sampleIndex + ", f") @=> OscEvent touchEvent;
  64.  
  65. while (true)
  66. {
  67. touchEvent => now;
  68.  
  69. while (touchEvent.nextMsg()) {
  70. touchEvent.getFloat() => float f;
  71. <<< "touchEvent: ",f, "sample: ", sampleIndex >>>;
  72.  
  73. if (f > 0) {
  74. sample.setPositionToStart();
  75. } else {
  76. sample.setPositionToEnd();
  77. }
  78. }
  79. }
  80. }
  81.  
  82. /**************************************************************************************/
  83. /* MAIN PROGRAM */
  84. /**************************************************************************************/
  85.  
  86. // create instances of Sampleholder
  87. Sampleholder s[files.cap()];
  88.  
  89. // connect the instances to dac and initialize them
  90. for (0 => int i; i < files.cap(); i++) {
  91. s[i] => masterGain;
  92.  
  93. // load the files
  94. files[i][0] => s[i].setSamplePath;
  95. files[i][1] => s[i].setSample;
  96. }
  97.  
  98. 0.6 => masterGain.gain;
  99.  
  100. // spork 'em all
  101. for (0 => int i; i < files.cap(); i++) {
  102. spork ~ touchSampleShred(i, s[i]);
  103. }
  104.  
  105. while (true)
  106. {
  107. bar => now;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement