Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active December 31, 2015 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/7934859 to your computer and use it in GitHub Desktop.
Save zeffii/7934859 to your computer and use it in GitHub Desktop.

initialize.ck

Machine.add(me.dir() + "/Sampler.ck"); 
Machine.add(me.dir() + "/score.ck"); 

score.ck

Sampler some_sound;
some_sound.set_sample(-1, "click_01");

Machine.add(me.dir() + "/patterns.ck"); 

2::second => now;

patterns.ck

Sampler some_sound;

some_sound.mout => dac;
some_sound.trigger(.9, 0);

2::second => now;

Sampler.ck

public class Sampler{

    static SndBuf @ sound;
    static Mix2 @ mout;
    string sound_path;

    fun void set_sample(int dir, string wavname){
        set_path(dir, wavname);
        Mix2 tmix @=> this.mout;
        SndBuf tmp => this.mout;
        this.sound_path => tmp.read;
        tmp.samples() => tmp.pos;   
        tmp @=> this.sound;
    }

    fun void trigger(float vol, int pos){
        this.sound.gain(vol);
        this.sound.pos(pos);
    }

    fun void set_path(int dir, string wavname){
        me.dir(dir) + "/audio/" + wavname  + ".wav" => this.sound_path;
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment