// Ctk example 1 ( // first, declare variables var osc_2b, simple, score; // create a prototype class out of the synthdef osc_2b = CtkNoteObject( SynthDef(\osc_2b, {arg freq = 440.0, dur = 1.0, attackdur = 0.01, releasedur = 0.01, amp = 1; var osc, env; // env will ramp from 0 to 1, scaled by amp. env = EnvGen.kr( Env([0, 1, 1, 0], [attackdur, dur - attackdur - releasedur, releasedur], \lin), levelScale: amp, doneAction: 2); osc = SinOsc.ar(freq, 0, env); // use the env as the 'mul' arg Out.ar(0, osc); }) ); // create a new, empty score score = CtkScore.new; // a simple function - create 20 notes // it takes no arguments simple = { var dur, time, note; time = 0.0; dur = 2.0; // do(numIterations, function) ... iterate 20 times; do(20, {arg i; // i is an incrementer in this case (0..19) i.postln; // post what the current value of i is note = osc_2b.new(time); // create a new note, and tell SC it's start time // fill in its other slots using note.freq = 220 * i; note.dur = dur; note.amp = 0.0625; score.add(note); }) }; // call the .value on simple to run the function simple.value; // populate the score with notes score.play; // play the score ) // another example ( var osc_2b, simple, score; osc_2b = CtkNoteObject( SynthDef(\osc_2b, {arg freq = 440.0, dur = 1.0, attackdur = 0.01, releasedur = 0.01, amp = 1; var osc, env; env = EnvGen.kr( Env([0, 1, 1, 0], [attackdur, dur - attackdur - releasedur, releasedur], \lin), levelScale: amp, doneAction: 2); osc = SinOsc.ar(freq, 0, env); Out.ar(0, osc); }) ); score = CtkScore.new; // this time the function can take one parameter (startpartial) // this function plays partials sequentially simple = {arg startpartial = 1; var dur, time, note; // set time variable to 0 time = 0.0; dur = 0.5; // forBy(start, end, skip, function) forBy(startpartial, 20, 2, {arg cur, i; // cur is the current value, i is the incrementer [cur, i].postln; // post what the current value of cur and i are note = osc_2b.new(time); note.freq = 440 * cur; note.dur = dur; note.amp = 0.125; note.attackdur = 0.25; note.releasedur = 0.25; score.add(note); // increment time by dur time = time + dur; }) }; // call the .value on simple to run the function simple.value(2); // populate the score, start from partial 2 (even partials) score.play; // play the score ) // finally... more arguments that can be passed into the function ( var osc_2b, simple, score; osc_2b = CtkNoteObject( SynthDef(\osc_2b, {arg freq = 440.0, dur = 1.0, attackdur = 0.01, releasedur = 0.01, amp = 1; var osc, env; env = EnvGen.kr( Env([0, 1, 1, 0], [attackdur, dur - attackdur - releasedur, releasedur], \lin), levelScale: amp, doneAction: 2); osc = SinOsc.ar(freq, 0, env); Out.ar(0, osc); }) ); score = CtkScore.new; simple = {arg fundamental, skip, startpartial, toppartial, dur, ramp = 0.1; var time, note; time = 0.0; forBy(startpartial, toppartial, skip, {arg cur, i; [cur, i].postln; // use '.' and setter notations to set values at once note = osc_2b.new(time, dur).freq_(fundamental * cur).dur_(dur).amp_(0.125) .attackdur_(ramp).releasedur_(ramp); score.add(note); time = time + dur; }) }; // start at partial 3 skiping by 2 ending at partial 21 simple.value(110.0, 2, 3, 21, 1.0, 0.25); // you can save the CtkScore score.saveToFile("~/Desktop/trashme.sc".standardizePath); ) // then load the score and play it // igore the "FAILURE n_free Node not found" messages z = Score.newFromFile("~/Desktop/trashme.sc".standardizePath); z.play;