Hi,
is it possible to set the index of an array, eg. some_array[index], as an argument inside a SynthDef? Every time I try to do this I get the error that ‘Index not an Integer’. It being a variable all is fine.
Best,
pt
Hi,
is it possible to set the index of an array, eg. some_array[index], as an argument inside a SynthDef? Every time I try to do this I get the error that ‘Index not an Integer’. It being a variable all is fine.
Best,
pt
Hi @Petros_TatPsi ,
there’s a few things that might be going wrong here, can you post an example to narrow it down for us?
T
yes, so the SynthDef uses the following arrays:
~time=1;
(
var sph1,sph2,m_x=2,m_y=2,m_z=2,az1=0,el1=0,az2=0,el2=0,mag_x,mag_y,mag_z;
var azx=0,elx=0,azy=0,ely=0,azz=0,elz=0,sphx,sphy,sphz,rad=1;
~az = (360*~time).collect{
az1=(az1+(1)).wrap(180.neg,180);
el1=(el1+(360-(360/1.6180339887499))).wrap(90.neg,90);
sph1=Spherical(1,az1.degrad,el1.degrad).theta.round(0.00001);
};
~el = (360*~time).collect{
az2=(az2+(1)).wrap(90.neg,90);
el2=(el2+(360-(360/1.6180339887499))).wrap(90.neg,90);
sph2=Spherical(1,az2.degrad,el2.degrad).phi.round(0.00001);
};
~magx = (360*~time).collect{
azx=(azx+(1)).wrap(180.neg,180);
elx=(elx+(360-(360/1.6180339887499))).wrap(90.neg,90);
sphx=Spherical(rad,azx.degrad,elx.degrad);
mag_x=(Complex(cos((sphx.theta.round(0.00001)*m_x).wrap(pi.neg,pi)),cos((sphx.theta.round(0.00001)*m_x).wrap(pi.neg,pi))).rho*
Complex(cos((sphx.phi.round(0.00001)).wrap((pi/2).neg,(pi/2))),cos((sphx.phi.round(0.00001)).wrap((pi/2).neg,(pi/2)))).rho)*sphx.rho;
};
~magy = (360*~time).collect{
azy=(azy+(1)).wrap(180.neg,180);
ely=(ely+(360-(360/1.6180339887499))).wrap(90.neg,90);
sphy=Spherical(rad,azy.degrad,ely.degrad);
mag_y=(Complex(sin((sphy.theta.round(0.00001)*m_y).wrap(pi.neg,pi)),sin((sphy.theta.round(0.00001)*m_y).wrap(pi.neg,pi))).rho*
Complex(cos((sphy.phi.round(0.00001)).wrap((pi/2).neg,(pi/2))),cos((sphy.phi.round(0.00001)).wrap((pi/2).neg,(pi/2)))).rho)*sphy.rho;
};
~magz = (360*~time).collect{
azz=(azz+(1)).wrap(180.neg,180);
elz=(elz+(360-(360/1.6180339887499))).wrap(90.neg,90);
sphz=Spherical(rad,azz.degrad,elz.degrad);
if(
m_z.even,
mag_z=Complex(cos((sphz.phi.round(0.00001)*m_z).wrap((pi/2).neg,(pi/2))),cos((sphz.phi.round(0.00001)*m_z).wrap((pi/2).neg,(pi/2)))).rho*sphz.rho,
mag_z=Complex(sin((sphz.phi.round(0.00001)*m_z).wrap((pi/2).neg,(pi/2))),sin((sphz.phi.round(0.00001)*m_z).wrap((pi/2).neg,(pi/2)))).rho*sphz.rho
);
};
)
////////////////////////az
(
var pl1=0,az1,el1,sph1,rot1,i1,j1,k1,q1,raz1,rel1;
var pl2=0,az2,el2,sph2,rot2,i2,j2,k2,q2,raz2,rel2;
var pl3=0,az3,el3,sph3,rot3,i3,j3,k3,q3,raz3,rel3;
var r1=[0,0,1],r2=[0,0,1],r3=[0,0,1];
var v1=Quaternion(0,r1.[0],r1.[1],r1.[2]),v2=Quaternion(0,r2.[0],r2.[1],r2.[2]),v3=Quaternion(0,r3.[0],r3.[1],r3.[2]);
var angle=(360-(360/1.6180339887499));
var harm1,harn2,harm3;
~az_x=(360*~time).collect{
az1=~az.[pl1];el1=~el.[pl1];
pl1=pl1+1;
sph1=Spherical(1,az1,el1).asCartesian;
rot1=[sph1.x,sph1.y,sph1.z];
i1=Quaternion(0, rot1.[0], 0, 0);
j1=Quaternion(0, 0, rot1.[1], 0);
k1=Quaternion(0, 0, 0, rot1.[2]);
q1=(cos(angle.degrad)+(sin(angle.degrad)*(i1+j1+k1)));
v1=q1*v1*q1.conjugate;
raz1=Cartesian(v1.b.round(0.0001),v1.c.round(0.0001),v1.d.round(0.0001)).theta;
};
~az_y=(360*~time).collect{
az2=~az.[pl2];el2=~el.[pl2];
pl2=pl2+1;
sph2=Spherical(1,az2,el2).asCartesian;
rot2=[sph2.x,sph2.y,sph2.z];
i2=Quaternion(0, rot2.[0], 0, 0);
j2=Quaternion(0, 0, rot2.[1], 0);
k2=Quaternion(0, 0, 0, rot2.[2]);
q2=(cos(angle.degrad)+(sin(angle.degrad)*(i2+j2+k2)));
v2=q2*v2*q2.conjugate;
raz2=Cartesian(v2.b.round(0.0001),v2.c.round(0.0001),v2.d.round(0.0001)).theta;
};
~az_z=(360*~time).collect{
az3=~az.[pl3];el3=~el.[pl3];
pl3=pl3+1;
sph3=Spherical(1,az3,el3).asCartesian;
rot3=[sph3.x,sph3.y,sph3.z];
i3=Quaternion(0, rot3.[0], 0, 0);
j3=Quaternion(0, 0, rot3.[1], 0);
k3=Quaternion(0, 0, 0, rot3.[2]);
q3=(cos(angle.degrad)+(sin(angle.degrad)*(i3+j3+k3)));
v3=q3*v3*q3.conjugate;
raz3=Cartesian(v3.b.round(0.0001),v3.c.round(0.0001),v3.d.round(0.0001)).theta;
};
)
///////////////////////el
(
var pl1=0,az1,el1,sph1,rot1,i1,j1,k1,q1,raz1,rel1;
var pl2=0,az2,el2,sph2,rot2,i2,j2,k2,q2,raz2,rel2;
var pl3=0,az3,el3,sph3,rot3,i3,j3,k3,q3,raz3,rel3;
var r1=[0,0,1],r2=[0,1,0],r3=[1,0,0];
var v1=Quaternion(0,r1.[0],r1.[1],r1.[2]),v2=Quaternion(0,r2.[0],r2.[1],r2.[2]),v3=Quaternion(0,r3.[0],r3.[1],r3.[2]);
var angle=(360-(360/1.6180339887499));
~el_x=(360*~time).collect{
az1=~az.[pl1];el1=~el.[pl1];
pl1=pl1+1;
sph1=Spherical(1,az1,el1).asCartesian;
rot1=[sph1.x,sph1.y,sph1.z];
i1=Quaternion(0, rot1.[0], 0, 0);
j1=Quaternion(0, 0, rot1.[1], 0);
k1=Quaternion(0, 0, 0, rot1.[2]);
q1=(cos(angle.degrad)+(sin(angle.degrad)*(i1+j1+k1)));
v1=q1*v1*q1.conjugate;
rel1=Cartesian(v1.b.round(0.0001),v1.c.round(0.0001),v1.d.round(0.0001)).phi;
};
~el_y=(360*~time).collect{
az2=~az.[pl2];el2=~el.[pl2];
pl2=pl2+1;
sph2=Spherical(1,az2,el2).asCartesian;
rot2=[sph2.x,sph2.y,sph2.z];
i2=Quaternion(0, rot2.[0], 0, 0);
j2=Quaternion(0, 0, rot2.[1], 0);
k2=Quaternion(0, 0, 0, rot2.[2]);
q2=(cos(angle.degrad)+(sin(angle.degrad)*(i2+j2+k2)));
v2=q2*v2*q2.conjugate;
rel2=Cartesian(v2.b.round(0.0001),v2.c.round(0.0001),v2.d.round(0.0001)).phi;
};
~el_z=(360*~time).collect{
az3=~az.[pl3];el3=~el.[pl3];
pl3=pl3+1;
sph3=Spherical(1,az3,el3).asCartesian;
rot3=[sph3.x,sph3.y,sph3.z];
i3=Quaternion(0, rot3.[0], 0, 0);
j3=Quaternion(0, 0, rot3.[1], 0);
k3=Quaternion(0, 0, 0, rot3.[2]);
q3=(cos(angle.degrad)+(sin(angle.degrad)*(i3+j3+k3)));
v3=q3*v3*q3.conjugate;
rel3=Cartesian(v3.b.round(0.0001),v3.c.round(0.0001),v3.d.round(0.0001)).phi;
};
)
/////////////////notes and durs
(
var dur=4,ph1,ph2,ph3,pl1=0,pl2=0,pl3=0,pl4=0,pl5=0,pl6=0,sph1,sph2,sph3,n1,n2,n3,mult=10;
var mag1,mag2,mag3,rythm,index1,index2,index3,pl7=0,pl8=0,pl9=0,t1,t2,t3;
rythm=[2,1,1];
~phase2 = (360*~time).collect{
ph1=~magx.[pl1]/(2.sqrt);
index1=rythm.wrapAt(pl7);
pl7=pl7+1;
pl1=pl1+1;
ph1=(ph1*dur).round(1/256);
t1=ph1+index1;
};
~phase3 = (360*~time).collect{
ph2=~magy.[pl2]/(2.sqrt);
index2=rythm.wrapAt(pl8);
pl8=pl8+1;
pl2=pl2+1;
ph2=(ph2*dur).round(1/256);
t2=ph2+index2;
};
~phase4 = (360*~time).collect{
ph3=~magz.[pl3]/(2.sqrt);
index3=rythm.wrapAt(pl9);
pl9=pl9+1;
pl3=pl3+1;
ph3=(ph3*dur).round((1/256));
t3=ph3+index3;
};
~n2 = (360*~time).collect{
mag1=Cartesian(~magx[pl4]/(2.sqrt),~magy[pl4]/(2.sqrt),~magz[pl4]/(2.sqrt)).rho/(2.sqrt);
sph1=Spherical(mag1*mult,~az.[pl4],~el.[pl4]).x;
pl4=pl4+1;
n1=(sph1).round(1);
};
~n3 = (360*~time).collect{
mag2=Cartesian(~magx[pl5]/(2.sqrt),~magy[pl5]/(2.sqrt),~magz[pl5]/(2.sqrt)).rho/(2.sqrt);
sph2=Spherical(mag2*mult,~az.[pl5],~el.[pl5]).y;
pl5=pl5+1;
n2=(sph2).round(1);
};
~n4 = (360*~time).collect{
mag3=Cartesian(~magx[pl6]/(2.sqrt),~magy[pl6]/(2.sqrt),~magz[pl6]/(2.sqrt)).rho/(2.sqrt);
sph3=Spherical(mag3*mult,~az.[pl6],~el.[pl6]).z;
pl6=pl6+1;
n3=(sph3).round(1);
};
);
+the VBAP Buffer and the Wavetable Buffers, and the SynthDef is the following were the ‘pl’ variable is the index I want to use as an argument
(
SynthDef.new(\ob, {
arg n1=1,cutt=440,decay=6,t=2,attack=0.01;
var phase,scale=4,osc,sphere,mag_o,pl=0;
var freq, env,m=1,bank,pitch,fund=55, angle=0,rad;
var wrappedOut1 = { |busArray, signalArray|
[busArray, signalArray].flop.do { |pair|
Out.ar(pair[0], pair[1])}};
var out = NamedControl.kr(\out, [0, 1, 2, 3]); // multiple buses!
bank=180;
pitch=2.pow(n1/(2*6));
freq=(fund*scale)*pitch;
bank.do{
phase=exp(Complex(0,1)*angle.degrad).theta;
angle=(angle+(360-(360/1.6180339887499))).wrap(0,360);
mag_o=Cartesian(~magx.[pl]/(2.sqrt),~magy.[pl]/(2.sqrt),~magz.[pl]/(2.sqrt)).rho/(2.sqrt);
sphere=Spherical(mag_o,~az_x.[pl],~el_x.[pl]);
env=EnvGen.ar(Env.perc(attack,decay,pitch.reciprocal),doneAction:2,levelScale:mag_o);
// env=EnvGen.ar(Env.sine(decay,pitch.reciprocal),doneAction:2,levelScale:mag_o);
osc=VBAP.ar(4,
LeakDC.ar(Osc.ar(~w.bufnum,(freq*m),mul:m.reciprocal,phase:phase)),
~b.bufnum,
Osc.ar(~t.bufnum,sphere.rho,phase:sphere.theta.linlin(pi.neg,pi,2pi.neg,2pi),mul:180),
Osc.ar(~t.bufnum,sphere.rho,phase:sphere.phi.linlin((pi/2).neg,(pi/2),2pi.neg,2pi),mul:90)
);
m=m+1;
pl=pl+1;
wrappedOut1.value(out,LPF.ar(LeakDC.ar((osc)*env*0.2),cutt))
//Out.ar(0,LPF.ar(LeakDC.ar((osc)*env*0.1),cutt));
};
}).add;
)
the synth is controlled by a pattern therefore the argument, I plan to set a different initial index as the pattern plays
The error is as follows:
ERROR: Primitive '_BasicAt' failed.
Index not an Integer
RECEIVER:
Instance of Array { (0x13021c300, gc=2C, fmt=01, flg=00, set=09)
indexed slots [360]
0 : Float 1.473839 25BEFBCA 3FF794D8
1 : Float 0.174423 67404DF6 3FC6537F
2 : Float 1.210218 FE98D41C 3FF35D0D
3 : Float 1.950264 1E8E943E 3FFF3448
4 : Float 1.661876 74BBDADF 3FFA970B
5 : Float 0.507870 7BF7ACBF 3FE04078
6 : Float 0.894432 D01827E9 3FEC9F30
7 : Float 1.805863 EF89ED84 3FFCE4D0
8 : Float 1.758209 B5BD6D17 3FFC219F
9 : Float 0.796570 EAF54ACA 3FE97D7F
10 : Float 0.554988 B43F6F65 3FE1C276
11 : Float 1.580823 6406671B 3FF94B0D
12 : Float 1.755667 976DA31A 3FFC1736
13 : Float 1.015620 8F89966C 3FF03FFA
14 : Float 0.222586 6CAD88D5 3FCC7DAF
15 : Float 1.296922 B6C57EF0 3FF4C031
16 : Float 1.656650 A6A138C6 3FFA81A3
17 : Float 1.146908 ED280C76 3FF259BB
18 : Float 0.072797 5EE77547 3FB2A2CB
19 : Float 0.981622 E022A41F 3FEF6972
20 : Float 1.473013 19A62E90 3FF79176
21 : Float 1.180961 65608BE1 3FF2E537
22 : Float 0.304931 FCBBD16A 3FD383FD
23 : Float 0.665356 F67480A5 3FE54A98
24 : Float 1.224765 4B7FD91E 3FF398A3
25 : Float 1.117771 DCC1F218 3FF1E263
26 : Float 0.453839 E94907B5 3FDD0BB2
27 : Float 0.378528 FC57DD0F 3FD839CB
28 : Float 0.938142 5567D1B5 3FEE0542
29 : Float 0.966967 B14BBD26 3FEEF164
30 : Float 0.507823 44F8BCFA 3FE04015
31 : Float 0.148496 E77AF3E5 3FC301EB
...
}
PATH: /Users/petrostatsiopoulos/Dokuments/PROJECT FILES/SC/inst_6_sph harm/synthesized_inst-6_upgrade_3-1.scd
PROTECTED CALL STACK:
Meta_MethodError:new 0x1087f7480
arg this = PrimitiveFailedError
arg what = Index not an Integer
arg receiver = [ 1.4738389467673, 0.17442314664423, 1.2102184243388, 1.9502640908843, 1.6618761596598, 0.50786995136641, 0.89443245547704, 1.8058633191093, 1.7582089518754, 0.79656978502529, 0.55498824314735, 1.5808233172633, 1.7556672969024, 1.0156198126728, 0.22258560949837, 1.2969224109183, 1.6566502102828, 1.1469077361988, 0.072796545667605, 0.9816221597331, 1.4730130197449, 1.1809610328717, 0.30493116074583, 0.66535614143142, 1.2247651051708, 1.1177710173935, 0.45383904248967, 0.37852763789074, 0.93814198189516, 0.96...etc...
Meta_PrimitiveFailedError:new 0x1087ff340
arg this = PrimitiveFailedError
arg receiver = [ 1.4738389467673, 0.17442314664423, 1.2102184243388, 1.9502640908843, 1.6618761596598, 0.50786995136641, 0.89443245547704, 1.8058633191093, 1.7582089518754, 0.79656978502529, 0.55498824314735, 1.5808233172633, 1.7556672969024, 1.0156198126728, 0.22258560949837, 1.2969224109183, 1.6566502102828, 1.1469077361988, 0.072796545667605, 0.9816221597331, 1.4730130197449, 1.1809610328717, 0.30493116074583, 0.66535614143142, 1.2247651051708, 1.1177710173935, 0.45383904248967, 0.37852763789074, 0.93814198189516, 0.96...etc...
Object:primitiveFailed 0x10846adc0
arg this = [ 1.4738389467673, 0.17442314664423, 1.2102184243388, 1.9502640908843, 1.6618761596598, 0.50786995136641, 0.89443245547704, 1.8058633191093, 1.7582089518754, 0.79656978502529, 0.55498824314735, 1.5808233172633, 1.7556672969024, 1.0156198126728, 0.22258560949837, 1.2969224109183, 1.6566502102828, 1.1469077361988, 0.072796545667605, 0.9816221597331, 1.4730130197449, 1.1809610328717, 0.30493116074583, 0.66535614143142, 1.2247651051708, 1.1177710173935, 0.45383904248967, 0.37852763789074, 0.93814198189516, 0.96...etc...
a FunctionDef 0x1385d62f8
sourceCode = "<an open Function>"
Integer:do 0x10965e440
arg this = 180
arg function = a Function
var i = 0
SynthDef:buildUgenGraph 0x109d3a0c0
arg this = a SynthDef
arg func = a Function
arg rates = nil
arg prependArgs = [ ]
var result = nil
var saveControlNames = nil
a FunctionDef 0x109d38640
sourceCode = "<an open Function>"
Function:prTry 0x108af7d40
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.new(\ob, {
arg ..."
var doc = nil
var ideClass = <instance of Meta_ScIDE>
Process:interpretPrintCmdLine
arg this = <instance of Main>
^^ The preceding error dump is for ERROR: Primitive '_BasicAt' failed.
Index not an Integer
RECEIVER: [ 1.4738389467673, 0.17442314664423, 1.2102184243388, 1.9502640908843, 1.6618761596598, 0.50786995136641, 0.89443245547704, 1.8058633191093, 1.7582089518754, 0.79656978502529, 0.55498824314735, 1.5808233172633, 1.7556672969024, 1.0156198126728, 0.22258560949837, 1.2969224109183, 1.6566502102828, 1.1469077361988, 0.072796545667605, 0.9816221597331, 1.4730130197449, 1.1809610328717, 0.30493116074583, 0.66535614143142, 1.2247651051708, 1.1177710173935, 0.45383904248967, 0.37852763789074, 0.93814198189516, 0.96...etc...
try just putting .asInteger
to make sure the value is an integer.
Were exactly should I put it? I tried but it still gives the error.
I tried inside the .at method and as pl=pl.asInteger
Use the Select UGen to index into an array based on a server-side signal.
The at
method is language side only. You can’t use a server-side value to index with at
, only with Select.
hjh
Yes I did that, found this thread:
https://scsynth.org/t/cant-index-an-array-in-a-synthdef-using-an-argument/2410?u=petros_tatpsi
Thank you! Have a good day.