bearing in mind the following piece of code
// Define the SynthDef object first
(
SynthDef(\example, {
|freq = 440, amp = 0.5, numVoices = 5|
var sig = Mix.fill(numVoices, { |i|
var freqOffset = Rand(-10, 10).exprange;
var ampOffset = Rand(-0.2, 0.2).exprange;
var gate = Impulse.ar(freq * (1 + freqOffset), 0, numVoices - i);
var env = EnvGen.kr(Env.perc(0.01, 0.1), gate, doneAction: Done.freeSelf);
var snd = SinOsc.ar(freq * (1 + freqOffset), 0, amp * (1 + ampOffset)) * env;
snd;
});
Out.ar(0, sig);
}).add;
)
// Define the OSC function that uses the SynthDef object
(
OSCFunc({ |msg|
SynthDef(\example).clear; // clear all existing instances of the synth
Synth.new(\example, [\freq, msg[1].asFloat, \amp, msg[2].asFloat, \numVoices, msg[3].asInteger]);
}, '/sound');
)
and this
// Processing code
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress scAddr;
float freq = 440;
float amp = 0.5;
void setup() {
size(800, 600);
smooth();
oscP5 = new OscP5(this, 12000);
scAddr = new NetAddress("127.0.0.1", 57120);
}
void draw() {
background(0);
noStroke();
fill(255);
ellipse(width/2, height/2, map(freq, 0, 1000, 0, width), map(amp, 0, 1, 0, height));
}
void mouseMoved() {
freq = map(mouseX, 0, width, 0, 1000);
amp = map(mouseY, 0, height, 1, 0);
OscMessage msg = new OscMessage("/sound");
msg.add(freq);
msg.add(amp);
oscP5.send(msg, scAddr);
}
what am i theoretically doing wrong?
i am getting the following error while evaluating the supercollider code:
ERROR: Primitive '_BasicNew' failed.
Index not an Integer
RECEIVER:
class Array (0000021B98D32D40) {
instance variables [19]
name : Symbol 'Array'
nextclass : instance of Meta_Array2D (0000021BA141E840, size=19, set=5)
superclass : Symbol 'ArrayedCollection'
subclasses : nil
methods : instance of Array (0000021BA14BB400, size=50, set=6)
instVarNames : nil
classVarNames : nil
iprototype : nil
cprototype : nil
constNames : nil
constValues : nil
instanceFormat : Integer 1
instanceFlags : Integer 0
classIndex : Integer 1128
classFlags : Integer 3
maxSubclassIndex : Integer 1128
filenameSymbol : Symbol 'C:\Program Files\SuperCollider-3.13.0\SCClassLibrary\Common\Collections\Array.sc'
charPos : Integer 0
classVarIndex : Integer 5
}
PATH: D:/_CS/TMM_SUPERCOLLIDER/2/1.scd
PROTECTED CALL STACK:
Meta_MethodError:new 0000021BA01A2180
arg this = PrimitiveFailedError
arg what = Index not an Integer
arg receiver = Array
Meta_PrimitiveFailedError:new 0000021BA01A9F40
arg this = PrimitiveFailedError
arg receiver = Array
Object:primitiveFailed 0000021B9FD7C300
arg this = Array
Meta_Collection:fill 0000021BA14248C0
arg this = Array
arg size = an OutputProxy
arg function = a Function
var obj = nil
Meta_Mix:fill 0000021B9FF66480
arg this = Mix
arg n = an OutputProxy
arg function = a Function
var array = nil
a FunctionDef 0000021BA3ADDE68
sourceCode = "{
|freq = 440, amp = 0.5, numVoices = 5|
var sig = Mix.fill(numVoices, { |i|
var freqOffset = Rand(-10, 10).exprange;
var ampOffset = Rand(-0.2, 0.2).exprange;
var gate = Impulse.ar(freq * (1 + freqOffset), 0, numVoices - i);
var env = EnvGen.kr(Env.perc(0.01, 0.1), gate, doneAction: Done.freeSelf);
var snd = SinOsc.ar(freq * (1 + freqOffset), 0, amp * (1 + ampOffset)) * env;
snd;
});
Out.ar(0, sig);
}"
arg freq = an OutputProxy
arg amp = an OutputProxy
arg numVoices = an OutputProxy
var sig = nil
SynthDef:buildUgenGraph 0000021BA1919F00
arg this = a SynthDef
arg func = a Function
arg rates = nil
arg prependArgs = [ ]
var result = nil
var saveControlNames = nil
a FunctionDef 0000021BA18D5B40
sourceCode = "<an open Function>"
Function:prTry 0000021BA0420D00
arg this = a Function
var result = nil
var thread = a Thread
var next = nil
var wasInProtectedFunc = false
CALL STACK:
MethodError:reportError
arg this = <instance of PrimitiveFailedError>
Nil:handleError
arg this = nil
arg error = <instance of PrimitiveFailedError>
Thread:handleError
arg this = <instance of Thread>
arg error = <instance of PrimitiveFailedError>
Object:throw
arg this = <instance of PrimitiveFailedError>
Function:protect
arg this = <instance of Function>
arg handler = <instance of Function>
var result = <instance of PrimitiveFailedError>
SynthDef:build
arg this = <instance of SynthDef>
arg ugenGraphFunc = <instance of Function>
arg rates = nil
arg prependArgs = nil
< closed FunctionDef > (no arguments or variables)
Interpreter:interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
var code = "(
SynthDef(\example, {
|..."
var doc = nil
var ideClass = <instance of Meta_ScIDE>
Process:interpretPrintCmdLine
arg this = <instance of Main>
^^ The preceding error dump is for ERROR: Primitive '_BasicNew' failed.
Index not an Integer
RECEIVER: Array
vielen danke!!!
T.