miSCellaneous_lib icon indicating copy to clipboard operation
miSCellaneous_lib copied to clipboard

sVarGui.gui throws error for curve warp

Open avdrd opened this issue 3 years ago • 1 comments

While my previous bug report was a red herring, it did ultimately discover a real, albeit small problem in miSC.

\foo.asCompileString // -> 'foo' 
// ^^ just checking that I'm using the stock version of that 

Spec.specs[\freq].warp = 0.1
\default.sVarGui.gui

throws error:

ERROR: Message 'at' 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 = 'at'
		arg args = [*1]
	ControlSpec:miSC_specAsArray
		arg this = <instance of ControlSpec>
		arg synthName = nil
		arg metaKey = 'specs'
		arg useGlobalSpecs = true
		var s = "ControlSpec(20, 20000, 0.1, ..."
		var i = nil
		var typeString = nil
		var indices = nil
	< FunctionDef in Method Symbol:miSC_sVarGuiSpecsFromTuples >
		arg keyNumPair = [*2]
	ArrayedCollection:do
		arg this = [*3]
		arg function = <instance of Function>
		var i = 0
	List:do
		arg this = <instance of List>
		arg function = <instance of Function>
	Symbol:miSC_sVarGuiSpecsFromTuples
		arg this = 'default'
		arg tuples = <instance of List>
		arg exclude = [*0]
		arg metaKey = 'specs'
		var specData = <instance of ControlSpec>
		var varGuiSpecs = <instance of List>
		var key = 'freq'
		var num = 1
	< FunctionDef in Method Symbol:sVarGuiSpecs >
		arg i = 0
	Integer:do
		arg this = 1
		arg function = <instance of Function>
		var i = 0
	Symbol:sVarGuiSpecs
		arg this = 'default'
		arg ctrBefore = [*0]
		arg ctrReplace = [*0]
		arg ctrAfter = [*0]
		arg exclude = [*0]
		arg metaKey = 'specs'
		arg useGlobalSpecs = true
		arg num = 1
		var excludeI = [*0]
		var controlTuples = <instance of List>
		var expand = <instance of Function>
		var ctrs = [*1]
		var replaceIndex = nil
	Symbol:sVarGui
		arg this = 'default'
		arg ctrBefore = nil
		arg ctrReplace = nil
		arg ctrAfter = nil
		arg exclude = nil
		arg metaKey = 'specs'
		arg useGlobalSpecs = true
		arg num = 1
		arg server = nil
	< closed FunctionDef >  (no arguments or variables)
	Interpreter:interpretPrintCmdLine
		arg this = <instance of Interpreter>
		var res = nil
		var func = <instance of Function>
		var code = "\default.sVarGui.gui"
		var doc = nil
		var ideClass = <instance of Meta_ScIDE>
...
^^ ERROR: Message 'at' not understood.
RECEIVER: nil

Basically, 0.1.asWarp.asSpecifier.class is a Float, but you are hoping to find it as a single-quoted Symbol in ControlSpec.miSC_specAsArray.

The correct version of that method is in fact much simpler, and avoids the forced conversion that breaks the above use case:

+ ControlSpec {
	
	miSC_specAsArray { |synthName, metaKey = \specs, useGlobalSpecs = true|
		^[this.minval, this.maxval, this.warp.asSpecifier, this.step, this.default]
	}
}

To be more explicit, after setting the warp to a number, which is a legit thing to do, as that translates into a CurveWarp with the standard SC library (of SC 3.12.1 anyway), the default asCompileString for a Spec of that kind will print it like

Spec.specs[\freq].warp = 0.1
Spec.specs[\freq].asCompileString
// -> ControlSpec(20, 20000, 0.1, 0, 440, " Hz")

Your miSC_specAsArray method tries to look for a single quoted string in there, such 'exp', but fails to find one when CurveWarp is used, because that prints itself as a mere unquoted number in response to asCompileString.

avdrd avatar Dec 22 '21 17:12 avdrd

Hey, thanks for the report and the suggestion. VarGui is very old, I'd have to look into it if this doesn't break other use cases. I will look at it before the next update. Cheers, Daniel

dkmayer avatar Dec 22 '21 18:12 dkmayer