Javascript question

wayna's picture

Hello All!

I have a little question about javascript, i'm pretty sure this is an easy thing for anybody who is above my level whith this language.Here is my problem:

I use this code to convert audio structure into an XYZ structure:

// Initialise objects
var points = new Object();
var levels = new Object();
function (__structure outputStructure) main (__structure inputStructure, __number dummy, __number ScaleX,__number ScaleY, __number ScaleZ, __number AudioMultiplier)
   // Adjustment variables
   var scalex = ScaleX;      // Scale points on X-axis
   var scaley = ScaleY;      // Scale points on Y-axis
   var scalez = ScaleZ ;      // Scale points on Z-axis
   var AudioMultiplier = AudioMultiplier ; // Audio Sensitivy
   // Copy input levels struct if not undefined
   if(inputStructure != undefined)
      levels = inputStructure[0];
   // Create points structure
   for(i = 0; i < dummy; i++) {
      px = levels[i] * scalex * AudioMultiplier;      // Point X
      py = levels[i] * scaley * AudioMultiplier;      // Point Y
      pz = levels[i] * scalez * AudioMultiplier;      // Point Z
      points[i] = Array(px,py,pz);   // Point XYZ
   var result = new Object();
   result.outputStructure = points;
   return result;

The thing is, the output point are named "0","1" and "2" (as you can see on the above picture)

but i would like them to be named "X", "Y" and "Z" so i could directly use the structure to feed the amazing 1024_structure_plugin patches.

Anybody who has an idea how i can do that?

Many thank in advance Wayna

Capture d’écran 2013-05-08 à 17.37.24.png
Capture d’écran 2013-05-08 à 17.37.24.png26.34 KB

cybero's picture
Re: Javascript question

Firstly, using your patch code I end up with a structural output that reduces directly down to a structure of only a single member with only three point values. Perhaps I've got it hooked up incorrectly ...?

Whatever output you get from your patch, you could feed that into a named structure maker patch [available as part of Kineme Structure Tools] and then feed that into _1024 structure plugin patches.

You could also use _1024's _1024_Structure_XYZ_Maker patch, takes three inputs, outputs an XYZ structure. Hope that helps.

wayna's picture
Re: Javascript question


You have to feed the patch directly out from the "frequency" output from the Kineme Audio patch.

It is possible to make the way you are saying, but i sometimes use 250 frequencies * 3 value points (X,Y,Z), that is really too much outputs to transform. Anyway, the turnaround i found for now, is to feed it to a 1024 3D_math patch, this one is able to read the structure, and transform the output names to "X", "Y" and "Z".

Thanks anyway

Serious Cyrus's picture
Re: Javascript question

Arrays can't have strings for keys, i think you can only do it with an object in JS. try this where you create your point structure

   for(i = 0; i < dummy; i++) {
      var xyz = new Object();
      xyz.x = levels[i] * scalex * AudioMultiplier;      // Point X
      xyz.y = levels[i] * scaley * AudioMultiplier;      // Point Y
      xyz.z = levels[i] * scalez * AudioMultiplier;      // Point Z
      points[i] = xyz;

gtoledo3's picture
Re: Javascript question

Without getting into the js, did you just try plugging in the structure as is? To my memory, franz's patches will also be able to take in structures that are have three or four numbered objects (I think two is ok as well?). But maybe something had changed with more recent plugins.