Evaluation problem on Windows

Hi,
I have a strange problem when evaluating SC code:
Although the code does not seem to have any errors, it does not evaluate (on the first try).
But when I evaluate it 3-5 times it works.
This is the Code I tried:

(
b = Buffer.alloc(s, s.sampleRate * 1.0, 1);
c = Buffer.alloc(s, s.sampleRate * 1.0, 1);
)

(
SynthDef(\playback1, { arg out = 0, buf, startTime = 1, rate = 1, amp = 0.1, att = 0.005, rel = 0.1;
	var src = PlayBuf.ar(1, buf, rate, startPos: startTime * SampleRate.ir);
	var env = EnvGen.ar(Env.perc(att, rel), doneAction: 2) * amp;
	Out.ar(out, src * env)
}).add;


Pbindef(\x,
	\instrument, \playback1,
	\buf, b,
	\out, Pseq([0, 1], inf),
	\dur, 0.2,
	\rate, 1,
	\amp, 0.5,
	\rel, 0.5,
	\startTime, Pseg([Pwhite(0, 0.5, 10), Pn(0)])
).play;

Pbindef(\y,
	\instrument, \playback1,
	\buf, c,
	\out, Pseq([0, 1], inf),
	\dur, 0.2,
	\rate, 1,
	\amp, 0.5,
	\rel, 0.5,
	\startTime, Pwhite(0.0, 0.05)
).play
)

By evaluating the SynthDef the following ERROR appears:

ERROR: syntax error, unexpected ',', expecting end of file
  in interpreted text
  line 1 char 2:

  0, 1], inf),
   ^
  	\dur, 0.2,
-----------------------------------
ERROR: Command line parse failed
-> nil
ERROR: syntax error, unexpected ',', expecting end of file
  in interpreted text
  line 1 char 2:

  0, 1], inf),
   ^
  	\dur, 0.2,
-----------------------------------
ERROR: Command line parse failed
-> nil

-> Pbindef('y', 'instrument', 'playback1', 'buf', Buffer.new, 'out', Pseq([ 0, 1 ], inf), 'dur', 0.2, 'rate', 1, 'amp', 0.5, 'rel', 0.5, 'startTime', Pwhite(0.0, 0.05))

And after 3 times the Code works properly (As you can see in the last line, it got evaluated).

It seems, that this is a Problem with Windows, since the Code Works every time on Mac and Linux.
I recognized this strange behaviour several times with my Laptop, also on other blocks of code.

I use Windows 11 64 bit and SuperCollider 3.13.0.

hopefully someone can help me as it is very confusing for me when the evaluation works “on a wing and a prayer”.

In your code the buffers b and c are empty, but I assume you must have filled them with something when testing, here I am using an audio file. I put the synthdef and the pbinds in a waitforboot for good measure. Does this play when you run it?

(
s.waitForBoot{
	b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
	c = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
	
	SynthDef(\playback1, { arg out = 0, buf, startTime = 1, rate = 1, amp = 0.1, att = 0.005, rel = 0.1;
		var src = PlayBuf.ar(1, buf, rate, startPos: startTime * SampleRate.ir);
		var env = EnvGen.ar(Env.perc(att, rel), doneAction: 2) * amp;
		Out.ar(out, src * env)
	}).add;
	
	s.sync;	
	
	Pbindef(\x,
		\instrument, \playback1,
		\buf, b,
		\out, Pseq([0, 1], inf),
		\dur, 0.2,
		\rate, 1,
		\amp, 0.5,
		\rel, 0.5,
		\startTime, Pseg([Pwhite(0, 0.5, 10), Pn(0)])
	).play;
	
	Pbindef(\y,
		\instrument, \playback1,
		\buf, c,
		\out, Pseq([0, 1], inf),
		\dur, 0.2,
		\rate, 1,
		\amp, 0.5,
		\rel, 0.5,
		\startTime, Pwhite(0.0, 0.05)
	).play
}
)

yes, correct assumption. i actually use the buffer so i can make a delay with the microphone. but the representation of the example is reduced for my problem.
when i evaluate this code i get a similar result: after 3 times evaluating (ctlr + enter) it works.
The problem occurs every time I restart SC.
If I already managed to evaluate the code once then it works every time, even when i load it into a new file (don’t know if this information is relevant).

My error messages (the 2x errors) and the mysterious succeed:

ERROR: syntax error, unexpected ',', expecting end of file
  in interpreted text
  line 1 char 8:

  artTime, Pwhite(0.0, 0.05)
         ^
  	).play
-----------------------------------
ERROR: Command line parse failed
-> nil
ERROR: syntax error, unexpected VAR, expecting end of file
  in interpreted text
  line 2 char 5:

  		var src = PlayBuf.ar(1, buf, rate, startPos: startTime * SampleRate.ir);
    ^^^
  		var env = EnvGen.ar(Env.perc(att, rel), doneAction: 2) * amp;
-----------------------------------
ERROR: Command line parse failed
-> nil
-> localhost

It looks like the IDE is mis-identifying the code region boundaries, but I don’t know why.

I have seen some weird IDE behavior in Windows before, related to the document text mirroring vs the sclang process. But code region bounds should be 100% in the IDE, no inter-process anything, so I have no idea.

hjh

Hm, that’s an unfortunate situation. Weird, unpredictable behaviour as this might cause SC beginners to stop using SC at all.
I’ve found surprising reports about IDE behaviour on the issue tracker too, e.g.:

or this one:

From the latter report I take that it might be worth trying with the internal server.

I’d further try setting the option of not starting the interpreter with IDE (SC preferences → Interpreter, uncheck first box). After restarting you can boot the interpreter from the menu or the bottom of the IDE window.

Sure, but we need more Windows-specific experience on the dev side.

The syntax error problem with region parsing is because a region beginning is defined as an opening parenthesis on its own line, at the top level of parsing the whole document. If a previous statement didn’t close a parenthesis, then parsing is not at the top level. So then the question is: how do we know that the statement is incomplete, and reset the parsing level?

a = Array.fill(5, |x|
    var t = x * (2pi / 5);

// I'm going to finish that later
// but first I want to run this
(
s.waitForBoot {
    ... bootup stuff...
}
)

This is an ambiguous case. The parenthesized block could be a region following an incomplete expression, or it could be an expression sequence within the loop body. Humans see it as a freestanding code block, but if you’re parsing it character by character, you can’t distinguish the two possibilities. Solving that might even require devising a new syntax for code regions (a difficult culture shift, since we have a couple decades of history).

hjh

At the first glance it seems to me, that starting from the internal Server with

Server.default = Server.internal;

s.boot;

is a solution to the Problem.

Now I can evaluate the Code (every time) and it works proper.
I still get some strange error messages, but these do not affect the functionality of the code.

Thank you!

I will continue to look at it…

Something really strange happened, and maybe it can be helpfull to solve the problem:

I started SC with the internal Server as i used to and copied some Code into a new file.
Just when copying and pasting i got these error message:

ERROR: syntax error, unexpected NAME, expecting end of file
  in interpreted text
  line 1 char 5:

  -4e4e-9fb1-eadb9ade60e8}');ScIDE.currentPath_(nil); 
      ^
-----------------------------------
ERROR: Command line parse failed
WARNING: Attempted to modify missing Text Mirror for Document {c512d910-6462-4e4e-9fb1-eadb9ade60e8}
ERROR: Message 'prSetEdited' not understood.
RECEIVER:
   nil
ARGS:
   Integer 1
PATH: C:/Users/josep/Documents/SuperCollider/1_Focusrite setup.scd
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg this = nil
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of DoesNotUnderstandError>
	Object:throw
		arg this = <instance of DoesNotUnderstandError>
	Object:doesNotUnderstand
		arg this = nil
		arg selector = 'prSetEdited'
		arg args = [*1]
	Process:interpretCmdLine
		arg this = <instance of Main>
^^ ERROR: Message 'prSetEdited' not understood.
RECEIVER: nil

the code itself was a very simple one:

MIDIIn.connectAll
MIDIIn.disconnectAll
MIDIdef.freeAll
(
MIDIdef.noteOn(\noteOnTest, {
	arg vel, nn, chan, src;
	[Ável, nn, chan, src].postln;

});
)

(
MIDIdef.cc(\noteOnTest, {
	arg vel, nn, chan, src;
	[Ável, nn, chan, src].postln;

});
)


///////////////////____Sin Synth____//////////// expo mantissa ex 7a(?)


g = { SinOsc.ar(44, 0, 0.1) + PinkNoise.ar(0.01) }.play;
g.free;
s.options.dump

(
SynthDef.new(\sinpk, { arg freq = 40, lagTime = 3, amp = 0.8;
	Out.ar(0, Pan2.ar(SinOsc.ar(freq.lag(lagTime), 0, 0.1) + PinkNoise.ar(0.01)* amp) );
}).add;
)
(
h = Synth(\sinpk, [\freq, 40]);


h.set("freq", (0).midicps);


MIDIdef.cc(\changefreq, {arg val, num, chan;
	[val, num, chan].postln;
	(num == 10).if {
		h.set("freq", val.midicps)
	};
}, ccNum: nil);
)

h.set("velo", (100).midicps);

MIDIdef.cc(\changevelo, {arg val, note, chan;
	[val, note, chan].postln;
	h.set("velo", (val).midicps, note:10);




MIDIIn.doControlAction(120, 10, num, val);
MIDIIn.doControlAction(120, 10, 10, 10);

And by just switching the taps of SC to see my files, I get these strange errors:

ERROR: Message 'didBecomeKey' not understood.
RECEIVER:
   nil
ARGS:
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg this = nil
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of DoesNotUnderstandError>
	Object:throw
		arg this = <instance of DoesNotUnderstandError>
	Object:doesNotUnderstand
		arg this = nil
		arg selector = 'didBecomeKey'
		arg args = [*0]
	Meta_Document:prCurrent_
		arg this = <instance of Meta_Document>
		arg newCurrent = nil
	Meta_Document:setActiveDocByQUuid
		arg this = <instance of Meta_Document>
		arg quuid = '{c512d910-6462-4e4e-9fb1-eadb9ade60e8}'
		var newCurrent = nil
	< closed FunctionDef >  (no arguments or variables)
	Process:interpretCmdLine
		arg this = <instance of Main>
^^ ERROR: Message 'didBecomeKey' not understood.
RECEIVER: nil


ERROR: Message 'didBecomeKey' not understood.
RECEIVER:
   nil
ARGS:
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg this = nil
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of DoesNotUnderstandError>
	Object:throw
		arg this = <instance of DoesNotUnderstandError>
	Object:doesNotUnderstand
		arg this = nil
		arg selector = 'didBecomeKey'
		arg args = [*0]
	Meta_Document:prCurrent_
		arg this = <instance of Meta_Document>
		arg newCurrent = nil
	Meta_Document:setActiveDocByQUuid
		arg this = <instance of Meta_Document>
		arg quuid = '{c512d910-6462-4e4e-9fb1-eadb9ade60e8}'
		var newCurrent = nil
	< closed FunctionDef >  (no arguments or variables)
	Process:interpretCmdLine
		arg this = <instance of Main>
^^ ERROR: Message 'didBecomeKey' not understood.
RECEIVER: nil

Maybe it can help to solve the problem. It still is a big issue for me

And when I try to save a file, i get this error message:

ERROR: Message 'prSetEdited' not understood.
RECEIVER:
   nil
ARGS:
   Integer 0
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg this = nil
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of DoesNotUnderstandError>
	Object:throw
		arg this = <instance of DoesNotUnderstandError>
	Object:doesNotUnderstand
		arg this = nil
		arg selector = 'prSetEdited'
		arg args = [*1]
	Process:interpretCmdLine
		arg this = <instance of Main>
^^ ERROR: Message 'prSetEdited' not understood.
RECEIVER: nil


ERROR: Message 'didBecomeKey' not understood.
RECEIVER:
   nil
ARGS:
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg this = nil
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of DoesNotUnderstandError>
	Object:throw
		arg this = <instance of DoesNotUnderstandError>
	Object:doesNotUnderstand
		arg this = nil
		arg selector = 'didBecomeKey'
		arg args = [*0]
	Meta_Document:prCurrent_
		arg this = <instance of Meta_Document>
		arg newCurrent = nil
	Meta_Document:setActiveDocByQUuid
		arg this = <instance of Meta_Document>
		arg quuid = '{c512d910-6462-4e4e-9fb1-eadb9ade60e8}'
		var newCurrent = nil
	< closed FunctionDef >  (no arguments or variables)
	Process:interpretCmdLine
		arg this = <instance of Main>
^^ ERROR: Message 'didBecomeKey' not understood.
RECEIVER: nil

But the save works.

Ável – variable names should begin with a lowercase letter – it isn’t legal to begin it with an accented character. (Of course, that’s not your intention – I’m pointing out that there’s an accidental wrong character in two places in your code, and speculating that this could be causing the failures.)

The IDE should handle it better – that may be a valid bug report – but I’m curious if it’s better after removing the syntax errors.

hjh

Thanks for your answer! Must me a relict from copying the code in a textfile.

I removed the symbols (À). The bug is still there. It also seems to me, that SC don’t like it, when i comment things out

//like this

I get weird errors sometimes (it seems to me that it happen per accident).
After i restarted SC a few times, it works properly…