Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sampleholder extends Chubgraph
- {
- SndBuf buffy;
- string path;
- string sampleLocation;
- buffy => outlet;
- fun void setSamplePath(string givenPath)
- {
- givenPath => path;
- }
- fun void setSample(string filename)
- {
- path + "/" + filename => sampleLocation;
- sampleLocation => buffy.read;
- buffy.samples() => buffy.pos;
- }
- fun void setPositionToStart()
- {
- 0 => buffy.pos;
- }
- fun void setPositionToEnd()
- {
- buffy.samples() => buffy.pos;
- }
- }
- /**************************************************************************************/
- /* GLOBAL VARIABLES */
- /**************************************************************************************/
- // OSC stuff
- OscRecv recv;
- 8001 => recv.port;
- recv.listen();
- // define BPM
- 120.0 => float BPM;
- 4 => int signature;
- 60.0 / BPM => float crotchet; //float representing the number of seconds that a crotched lasts
- crotchet::second => dur cr;
- signature::cr => dur bar;
- // master gain
- Gain masterGain => dac;
- // array of files to load
- [
- [me.dir(-5) + "/Samples/DISCRETEENERGYII[SAMPLE PACK]/SYNTHS", "152bpm_UO_BELLS_C.wav"]
- ] @=> string files[][];
- /**************************************************************************************/
- /* SHREDS */
- /**************************************************************************************/
- fun void touchSampleShred(int sampleIndex, Sampleholder sample)
- {
- recv.event("/chooper/touchsample/" + sampleIndex + ", f") @=> OscEvent touchEvent;
- while (true)
- {
- touchEvent => now;
- while (touchEvent.nextMsg()) {
- touchEvent.getFloat() => float f;
- <<< "touchEvent: ",f, "sample: ", sampleIndex >>>;
- if (f > 0) {
- sample.setPositionToStart();
- } else {
- sample.setPositionToEnd();
- }
- }
- }
- }
- /**************************************************************************************/
- /* MAIN PROGRAM */
- /**************************************************************************************/
- // create instances of Sampleholder
- Sampleholder s[files.cap()];
- // connect the instances to dac and initialize them
- for (0 => int i; i < files.cap(); i++) {
- s[i] => masterGain;
- // load the files
- files[i][0] => s[i].setSamplePath;
- files[i][1] => s[i].setSample;
- }
- 0.6 => masterGain.gain;
- // spork 'em all
- for (0 => int i; i < files.cap(); i++) {
- spork ~ touchSampleShred(i, s[i]);
- }
- while (true)
- {
- bar => now;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement