asCode vs asCompileString

I developed something in an old machine which allowed to use something like this

~selectWindow = Window("Capture Patterns")
.front.view.layout = VLayout (
	* ([menu = PopUpMenu(), ~text = TextView().focus(true);])
);

~funcDict[\pattern] = {|id, data|
	var def, pat = data.values.asArray.collect({|val| (val.asInteger.cpsmidi.round(0.1) / 10.0).abs });
	~def = Pbindef(id.asSymbol, \freq, Pseq(pat, inf));
	~midi = ((0..7)).collect({|i, item| (~sliders[item].value.midicps) });
	p = Pbind(\degree, Pseq(pat, inf));
	~lick[0] = Pdef(id.asSymbol);
	~text.setString("\n" + p.asCode + "\n"); // => asCode not understood in new machine.
};

But opening the same program in Ventura - M2 machine didn’t work and I had to change it with a bit of messing to

	~text.setString("\n" + p.asCompileString + "\n");

While my knowledge is limited to the above I was wondering if the workable version is actually unnecessary and something less is okay.

Hello @Kon_Vas

Try this:

Pbind.findRespondingMethodFor(\asCode)

And this:

Pbind.findRespondingMethodFor(\asCompileString)

What do you get?

First one (asCode) => nil

Second is: Object:asCompileString

So is the asCode method deprecated? And asCompileString the next most reasonable way?

It’s a shortcut from a Quark wslib

// W. Snoei 2005

  • Object {
    asCode { ^this.asCompileString; }
    }

Here 'tis: https://github.com/supercollider-quarks/wslib/blob/master/wslib-classes/GUI/Extensions/extSCWindow-asCode.sc

@Kon_Vas, sounds like you had wslib installed on your old machine.

Oh yes, okay… that solves part of the problem, however, would that be necessary now, I wonder if the asCode could just be replaced with asCompileString since its native to SC?

You can install wslib quark. But if you don’t use it much, just replace your asCode methods with asCompileString

you can also simply provide this method yourself

+ Object {
    asCode {^this.asCompileString }
}