Supercollider Drum Machine

Welcome Forums Example output programs Supercollider Drum Machine

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  gilFuser 2 years, 11 months ago.

  • Author
    Posts
  • #297

    gilFuser
    Participant

    Hello there

    Here one more example made in SuperCollider:

    // Drammachine
    // It replicates the way the example in that Wekinator takes the inputs come from Processing (100Inputs[from webcam]) and outputs to Chuck.

    // ready to play. Select all and evaluate (don’t forget to set output port in Wek as 57120)

    // The first number is the BPM
    TempoClock.default.tempo = 120/60;

    s.waitForBoot({

    ////// The Sound Process////
    SynthDef(\SOSkick,
    { arg out=0, freq=50, mod_freq=5, mod_index=5, decay=0.4, amp=0.8, beaterLvl=0.025, pan=0;
    var pitch_contour, drum_osc, drum_lpf, drum_env;
    var beater_source, beater_hpf, beater_lpf, lpf_cutoff_contour, beater_env;
    var kick_mix;

    pitch_contour = freq * Line.kr(2, 1, 0.02);
    drum_osc = PMOsc.ar( pitch_contour, mod_freq, mod_index/1.3 );
    drum_lpf = LPF.ar(in: drum_osc, freq: 1000, mul: 1, add: 0);
    drum_env = drum_lpf * EnvGen.ar(Env.perc(0.00625, decay), 1.0, doneAction: 2);

    beater_source = WhiteNoise.ar(beaterLvl);
    beater_hpf = HPF.ar( beater_source, 500);
    lpf_cutoff_contour = Line.kr(6000, 500, 0.03);
    beater_lpf = LPF.ar(in: beater_hpf, freq: lpf_cutoff_contour, mul: 1, add: 0);
    beater_env = beater_lpf * EnvGen.ar(Env.perc(0, decay*0.5), 1.0);

    kick_mix = Mix.new([drum_env, beater_env]) * amp;
    Out.ar(out, Pan2.ar(kick_mix, pan))
    }
    ).add;

    ///////// The Rhythm ////////////
    Pdef(\kick,
    Pbind(
    \instrument, \SOSkick,
    \dur, 0.25,
    \freq, 50,
    \mod_freq, 7,
    \mod_index, 7,
    \decay, Pkey(\dur)*0.9,
    \beaterLvl, 0.1,
    \amp, Pseq([0.8, 0, 0, 0, 0.9, 0, 0, 0, 0.8, 0, 0, 0.8, 0, 0, 0, 0, ],inf),
    )
    );
    Pdef(\tamburete,
    Pbind(
    \instrument, \SOSkick,
    \dur, 0.3333333,
    \freq, Pseq([200, 300, Pn(200,5)], inf),
    \mod_freq, 200 + Pwhite(-2, 2),
    \mod_index, 50 + Pwhite(-10, 10),
    \decay, Pkey(\dur)*0.66,
    \beaterLvl, 2,
    \amp, Pseq([0, 0.01, 0.1, 0, 0.01, 0.01, 0.1, 0.01, 0.1, 0, 0.25, 0.01, ], inf) * 0.75 * Pdefn(\on_off_T, 1),
    )
    );
    Pdef(\levada,
    Pbind(
    \instrument, \SOSkick,
    \dur, 0.2,
    \freq, 600,
    \mod_freq, 820 + Pwhite(-6, 6),
    \mod_index, 200 + Pwhite(-6, 6),
    \decay, Pkey(\dur)*Pwhite(0.25, 0.66),
    \beaterLvl, 0,
    \amp, Pseq([0.4, 0.2, 0.05, 0.05, 0.3, 0.05, 0.2, 0.05, 0.2, 0, ], inf) * Pdefn(\on_off_L, 0),
    \pan, Pwhite(-0.5, 0.5)
    )
    );

    Task({
    1.wait;
    Pdef.all.do(_.play);
    }).start;

    });

    ////////// getting osc msgs from Weki ///////////
    OSCdef(\fromWek, { |msg|
    MFdef(\wekOuts).value(msg);
    }, ‘/wek/outputs’).permanent_(true);

    /////// when class change in Weki, turn rhythm lines on and off //////////

    ~previousMsg = 0;

    MFdef(\wekOuts).add(\getWeki, { |msg|
    var actualMsg = msg[1];
    if (actualMsg != ~previousMsg.value)
    {
    ~previousMsg = actualMsg;
    case
    { actualMsg==1 } { Pdefn(\on_off_T, 0); Pdefn(\on_off_L, 0) }
    { actualMsg==2 } { Pdefn(\on_off_T, 1); Pdefn(\on_off_L, 0) }
    { actualMsg==3 } { Pdefn(\on_off_T, 1); Pdefn(\on_off_L, 1) };
    ~previousMsg.postln
    }
    });

    // Turning things on and off manually
    /*
    Pdef.all.do(_.stop);
    Pdef(\kick).stop;
    Pdef(\tamburete).stop;
    Pdef(\levada).stop;
    Pdef.all.do(_.stop);
    Pdef.all.clear;
    Pdefn(\on_off_T, 1);
    Pdefn(\on_off_L, 1);
    OSCdef(\fromWek).enable;
    OSCdef(\fromWek).disable;
    MFdef(\wekOuts).enable
    MFdef(\wekOuts).remove(\getWeki)
    MFdef(\wekOuts).disable;
    MFdef.all.clear
    s.quit
    */

  • #328

    LowellR
    Participant

    Hi GilFuser,

    thanks so much for sharing this code. When I evaluate it I get the following error.

    ERROR: syntax error, unexpected BINOP, expecting ‘)’
    in file ‘selected text’
    line 78 char 7:

    }, ‘/wek/outputs’).permanent_(true);
    ^
    I’m new to Supercollider. Am I missing something simple?

    thanks. Lowell

  • #335

    gilFuser
    Participant

    Hi Lowell. Sorry about the late answer.

    I think the problem is with these characteres: }, -> ‘ <- /wek/outputs -> ’ <- ).permanent_(true);

    change them to -> ‘
    Or maybe -> ”

    I don’t have how to test it right now. Or of the two should solve the problem.

    Please tell me if you do it, and which was the right one and I’ll edit the post.

    best regards,
    Gil

You must be logged in to reply to this topic.

  •  
  •  
  •  
  •  
  •