PROTECTED CALL STACK:
Meta_MethodError:new 0x7fa598782680
arg this = PrimitiveFailedError
arg what = Failed.
arg receiver = a Routine
Meta_PrimitiveFailedError:new 0x7fa598792780
arg this = PrimitiveFailedError
arg receiver = a Routine
Object:primitiveFailed 0x7fa5680ab640
arg this = a Routine
a FunctionDef 0x7fa599783640
sourceCode = ""
Function:prTry 0x7fa598a627c0
arg this = a Function
var result = nil
var thread = a Thread
var next = a Function
var wasInProtectedFunc = true
CALL STACK:
MethodError:reportError
arg this =
< closed FunctionDef >
arg error =
Function:try
arg this =
arg handler =
var result =
< FunctionDef in Method Scheduler:seconds_ >
arg time = 39620.44976
arg item =
< FunctionDef in Method SequenceableCollection:pairsDo >
arg i = 0
Integer:forBy
arg this = 0
arg endval = 4
arg stepval = 2
arg function =
var i = 0
var j = 0
SequenceableCollection:pairsDo
arg this = [*6]
arg function =
Scheduler:seconds_
arg this =
arg newSeconds = 40076.265151042
Meta_AppClock:tick
arg this =
var saveClock =
Process:tick
arg this =
^^ The preceding error dump is for ERROR: Primitive '_RoutineResume' failed.
Failed.
RECEIVER: a Routine
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Thanks — that error happens when SuperCollider is asked to resume (play) a Routine/Task that's already running (often because you re-evaluate code while the old Task is still active, or because the Play button ends up calling .play twice). The safe approach is:
stop any old Task when re-evaluating, and
always create a fresh Task when starting playback (or guard start with a reliable check).
Below is a single copy‑and‑paste ready SuperCollider file that:
cleans up a previous run if present,
creates a new Task each time you press Play,
prevents resuming an already running Task,
uses SC-style ifs (no ternary operators),
avoids duplicate doneAction warnings.
Evaluate the whole block in the IDE. Use the Stop button before re‑evaluating if you want to be extra safe.
supercollider
(
// EUCLIDEAN SEQUENCER — robust (stops old Task if present, creates new Task on Play)
/// CLEANUP if re-evaluating while an old instance exists
if (~seqTask.notNil) {
if (~seqTask.isPlaying) { ~seqTask.stop; };
~seqTask = nil;
};
if (~seqWindow.notNil) { ~seqWindow.close; ~seqWindow = nil; };
if (~mel.notNil) {
~mel.keys.do { |p|
var s = ~mel[p][\synth];
if (s.notNil and: { s.isRunning }) { s.set(\gate, 0) };
~mel[p][\synth] = nil;
};
};
s = Server.default;
s.options.numOutputBusChannels = 2;
s.waitForBoot({
// global context
~ctx = (
tempo: 120,
rootName: "c",
rootOct: 4,
scaleName: \major,
octaves: 2
);
// scales / helpers
~scales = (
major: [0,2,4,5,7,9,11],
minor: [0,2,3,5,7,8,10],
dorian: [0,2,3,5,7,9,10],
mixolydian: [0,2,4,5,7,9,10]
);
~noteNameToMidi = { |name, oct=4|
var nms = ["c","c#","d","d#","e","f","f#","g","g#","a","a#","b"];
var i = nms.indexOf(name.asString.toLower);
if (i.isNil) { "Unknown note %".format(name).warn; ^60 };
^i + (oct * 12);
};
~expandScale = { |scale, root, octs|
Array.fill(octs, { |o| scale.collect(_ + root + (o * 12)) }).flat;
};
// SynthDefs (use named doneAction where needed; consistent usage avoids duplicate warnings)
SynthDef(\kick, { |out=0, amp=0.7|
var fenv = Env([400,60],[0.1],\exp).ar;
var aenv = Env.perc(0.001,0.3,1,-4).ar(doneAction:2);
Out.ar(out, (SinOsc.ar(fenv) * aenv * 5).tanh ! 2 * amp);
}).add;
SynthDef(\snare, { |out=0, amp=0.7|
var n = WhiteNoise.ar;
var s = BPF.ar(n,200,0.3) + BPF.ar(n,2000,0.1);
var aenv = Env.perc(0.001,0.2,1,-4).ar(doneAction:2);
Out.ar(out, (s * aenv * 3).tanh ! 2 * amp);
}).add;
SynthDef(\hihat, { |out=0, amp=0.7|
var n = WhiteNoise.ar + PinkNoise.ar(0.5);
var s = BPF.ar(RHPF.ar(n,8000,0.3),10000,0.8);
var aenv = Env.perc(0.001,0.15,0.3,-8).ar(doneAction:2);
Out.ar(out, (s * aenv * 5).tanh ! 2 * 0.5 * amp);
}).add;
SynthDef(\bass, { |out=0, freq=110, amp=0.7, gate=1, glide=0.01|
var f = Lag.kr(freq, glide);
var src = Saw.ar(f) + Pulse.ar(f*0.99, 0.6);
var env = Env.adsr(0.01,0.3,0.5,0.2).ar(gate, doneAction:2);
Out.ar(out, (MoogFF.ar(src, f*4, 2.5) * env * amp) ! 2);
}).add;
SynthDef(\lead, { |out=0, freq=440, amp=0.7, gate=1, glide=0.05|
var f = Lag.kr(freq, glide);
var src = Saw.ar(f) + Pulse.ar(f*1.01, 0.4);
var env = Env.adsr(0.01,0.5,0.7,0.3).ar(gate, doneAction:2);
Out.ar(out, (MoogFF.ar(src, f*3, 2) * env * amp) ! 2);
}).add;
s.sync;
// sequencer state
~step = 0;
~drum = (
kick: (steps:16, pulses:4, rot:0, amp:0.8),
snare: (steps:16, pulses:2, rot:4, amp:0.7),
hihat: (steps:16, pulses:8, rot:0, amp:0.5),
perc: (steps:16, pulses:3, rot:8, amp:0.6)
);
~mel = (
bass:(seq:Array.fill(16,{ [0,2,4,7,nil].choose }), amp:0.7, glide:0.1, glProb:0.3, synth:nil),
lead:(seq:Array.fill(16,{ [0,2,4,5,7,9,11,nil].choose }), amp:0.6, glide:0.2, glProb:0.5, synth:nil)
);
// Euclidean generator
~euclid = { |steps, pulses, rot=0|
var pat = Array.fill(steps, false), bucket = 0;
if (pulses <= 0) { ^pat };
if (pulses >= steps) { ^Array.fill(steps, true) };
steps.do { |i|
bucket = bucket + pulses;
if (bucket >= steps) { bucket = bucket - steps; pat[i] = true };
};
^pat.rotate(rot);
};
// patterns and updater
~patterns = ();
~updatePatterns = {
~patterns.clear;
~drum.keys.do { |k|
var d = ~drum[k];
~patterns[k] = ~euclid.(d[\steps], d[\pulses], d[\rot]);
};
if (~patternView.notNil) { { ~patternView.refresh }.defer };
};
~updatePatterns.();
// randomisers
~rndDrum = { |inst, amt=4|
var d = ~drum[inst];
d[\pulses] = (d[\pulses] + amt.rand2).clip(1, d[\steps]-1).round;
d[\rot] = (d[\rot] + amt.rand2).clip(0, d[\steps]-1).round;
d[\amp] = (d[\amp] + (amt * 0.05).rand2).clip(0.1, 1);
~updatePatterns.();
};
~rndMel = { |part, amt=4|
~mel[part][\seq] = ~mel[part][\seq].collect { |n|
if (1.0.rand < amt/8) {
if (part == \bass) { [0,2,4,7,nil].choose } { [0,2,4,5,7,9,11,nil].choose }
} { n }
};
if (~patternView.notNil) { { ~patternView.refresh }.defer };
};
// create a fresh Task when needed (avoid reusing running Task)
~makeSeqTask = {
Task({
loop {
var beat = (60 / ~ctx.tempo) / 4;
var root = ~noteNameToMidi.(~ctx.rootName, ~ctx.rootOct);
var scale = ~scales[~ctx.scaleName];
var full = ~expandScale.(scale, root, ~ctx.octaves);
if (~patternView.notNil) { { ~patternView.refresh }.defer };
// drums
~patterns.keys.do { |k|
if (~patterns[k][~step]) { Synth(k, [\amp, ~drum[k][\amp]]) };
};
// melody: stop previous synth, start new if degree present
~mel.keys.do { |part|
var p = ~mel[part];
var deg = p[\seq][~step];
if (p[\synth].notNil and: { p[\synth].isRunning }) { p[\synth].set(\gate, 0) };
if (deg.notNil) {
var midi = full.wrapAt(deg);
var glide = 0.01;
if (1.0.rand < p[\glProb]) { glide = p[\glide] };
p[\synth] = Synth(part, [\freq, midi.midicps, \amp, p[\amp], \glide, glide]);
};
};
~step = (~step + 1) % 16;
beat.wait;
}
})
};
// silence helper
~silenceAll = {
~mel.keys.do { |p|
var s = ~mel[p][\synth];
if (s.notNil and: { s.isRunning }) { s.set(\gate, 0) };
~mel[p][\synth] = nil;
};
};
// holder for the currently running Task (nil when not running)
~seqTask = nil;
// GUI (closes previous window on re-eval)
~makeGUI = {
if (~seqWindow.notNil) { ~seqWindow.close; ~seqWindow = nil };
~seqWindow = Window("Euclidean Sequencer", Rect(100,100,1000,700)).front;
// Play button: create & play a new Task unless already playing
Button(~seqWindow, Rect(20,20,80,30)).states_([["Play"]]).action_({
if (~seqTask.notNil and: { ~seqTask.isPlaying }) {
// already running -> do nothing
} {
// ensure any previous task is stopped, then create+play a fresh one
if (~seqTask.notNil) { ~seqTask.stop; ~seqTask = nil };
~seqTask = ~makeSeqTask.();
~seqTask.play(AppClock);
};
});
// Stop button
Button(~seqWindow, Rect(110,20,80,30)).states_([["Stop"]]).action_({
if (~seqTask.notNil and: { ~seqTask.isPlaying }) {
~seqTask.stop;
~seqTask = nil;
~silenceAll.();
~step = 0;
if (~patternView.notNil) { { ~patternView.refresh }.defer };
};
});
// tempo
EZSlider(~seqWindow, Rect(20,60,200,20), "Tempo",
ControlSpec(40,300,\lin,1, ~ctx.tempo),
{ |v| ~ctx.tempo = v.value });
// scale / root
StaticText(~seqWindow, Rect(250,20,60,18)).string_("Scale");
PopUpMenu(~seqWindow, Rect(250,40,100,20))
.items_(~scales.keys.asArray)
.value_(~scales.keys.asArray.indexOf(~ctx.scaleName))
.action_({ |m| ~ctx.scaleName = m.item; ~updatePatterns.() });
StaticText(~seqWindow, Rect(360,20,60,18)).string_("Root");
PopUpMenu(~seqWindow, Rect(360,40,100,20))
.items_(["c","c#","d","d#","e","f","f#","g","g#","a","a#","b"])
.value_(["c","c#","d","d#","e","f","f#","g","g#","a","a#","b"].indexOf(~ctx.rootName))
.action_({ |m| ~ctx.rootName = m.item });
// drum controls
[\kick,\snare,\hihat,\perc].do { |ins, i|
var y = 100 + i*120;
StaticText(~seqWindow, Rect(20,y,90,18)).string_(ins.asString.toUpper);
EZSlider(~seqWindow, Rect(20,y+20,200,18), "Pulses", ControlSpec(0,16,\lin,1, ~drum[ins][\pulses]),
{ |v| ~drum[ins][\pulses] = v.value.round; ~updatePatterns.() });
EZSlider(~seqWindow, Rect(20,y+40,200,18), "Rotation", ControlSpec(0,16,\lin,1, ~drum[ins][\rot]),
{ |v| ~drum[ins][\rot] = v.value.round; ~updatePatterns.() });
EZSlider(~seqWindow, Rect(20,y+60,200,18), "Amp", ControlSpec(0,1,\lin,0.01, ~drum[ins][\amp]),
{ |v| ~drum[ins][\amp] = v.value });
Button(~seqWindow, Rect(20,y+85,90,18)).states_([["Rand"]]).action_({ ~rndDrum.(ins, 4.rand+1) });
};
Button(~seqWindow, Rect(500,40,120,25)).states_([["Rand Bass"]]).action_({ ~rndMel.(\bass, 4.rand+1) });
Button(~seqWindow, Rect(630,40,120,25)).states_([["Rand Lead"]]).action_({ ~rndMel.(\lead, 4.rand+1) });
// pattern view
~patternView = UserView(~seqWindow, Rect(250,100,730,560)).drawFunc_({
var cw = ~patternView.bounds.width / 16;
var ch = ~patternView.bounds.height / 6;
var parts = [\kick,\snare,\hihat,\perc,\bass,\lead];
var cols = [Color.red, Color.blue, Color.cyan, Color.magenta, Color.green, Color.orange];
var ph;
if (~seqTask.notNil and: { ~seqTask.isPlaying }) { ph = Color.yellow(0.3) } { ph = Color.clear };
Pen.color = ph;
Pen.addRect(Rect(~step*cw, 0, cw, ~patternView.bounds.height)); Pen.fill;
parts.do { |p, i|
var y = i*ch, pat;
Pen.color = cols[i].withAlpha(0.6);
if (~patterns.includesKey(p)) {
pat = ~patterns[p];
pat.do { |on, st| if (on) { Pen.addRect(Rect(st*cw+2, y+2, cw-4, ch-4)); Pen.fill } };
} {
pat = ~mel[p][\seq];
pat.do { |n, st| if (n.notNil) { Pen.addRect(Rect(st*cw+2, y+2, cw-4, ch-4)); Pen.fill } };
};
Pen.strokeColor_(Color.gray(0.5));
Pen.line(Point(0,y), Point(~patternView.bounds.width,y)); Pen.stroke;
Pen.stringAtPoint(p.asString.toUpper, Point(4,y+4), Font.default, Color.black);
};
});
~seqWindow.onClose_({
if (~seqTask.notNil and: { ~seqTask.isPlaying }) { ~seqTask.stop; ~seqTask = nil };
~silenceAll.();
s.freeAll;
});
};
~makeGUI.();
"Euclidean sequencer ready — use Play / Stop.".postln;
});
)
If you still see the "Tried to resume the running thread" error after pasting/evaluating the whole block:
Press the Stop button (or evaluate: if (~seqTask.notNil and: { ~seqTask.isPlaying }) { ~seqTask.stop; ~seqTask = nil }); then re-evaluate the block.
Or restart the SuperCollider server (Server.quit; Server.default.reboot) if something stubbornly remains.
If you want, I can trim the script to a minimal reproducer (only the Task + 1 synth + 1 Play button) so we can isolate exactly which action is causing the resume attempt on your machine — or I can adapt the GUI to disable the Play button while the Task is starting to make re-entrancy impossible. Which would you prefer?