javascript

Javascript Structure Loops

Swiftlikeninja's picture

I've attached a composition that will better show whatI am trying to do.

In a vain attempt to use what little knowledge about javascript I have, I tried to make a patch that will go through a structure and sort matching qualifiers into sub arrays (after which ill get into keying the structure, but I actually do know how to do that!!) I've ran into a snag with the patch. Im trying to make it as dynamic as possible since the structure can vary in size. I know I have to loop the code to do what i want but cannot figure out where to initiate the loop. Below is the code I'm using. Ive got k in there because im certain thats what im going to have to loop so its acting as a placeholder. If anyone could assist me in this dilemma you will have serious brownie points with me! :D

Again I've uploaded the qtz to exemplify

function (__structure Out)
main (__structure input,__structure team)
{   
 if (!_testMode)
 {
  var tmp = new Array();
  var build = new Array(team.length);
  var k = 0
     {  
     for (i=0;i<input.length;i++)
     if (input[i][1] == team[k])
     tmp.push(input[i]);
     build[k] = tmp;
    }   
 
 }
   result = new Object();
   result.Out =build
   return result;
}

Return Structures from Javascript Patch

bonerton's picture

I'm trying to input a variable length structure of strings into a javascript patch, concatenate it's members into subdivisions of n, and output the new 'compressed' structure, but this javascript isn't returning anything:

function (__structure arrOut) main (__structure arrIn, __number n)
{
   var result = new Object();
   var out = [];
 
   if(!_testMode) {
      for(var i = 0; i < arrIn.length(); i += n) {
         out.push(arrIn.slice(i, i+n).join(" "));
      }
      return out;
   }
 
   result.arrOut = out;
   return result;
}

It's not throwing up any errors. I was getting an "expression arrIn [null] is not an Object" error, until i checked for testMode. Any help would be greatly appreciated. Thanks!

Smoothing a coordinate structure with javascript?

gtoledo3's picture

How does one setup the appropriate javascript to smooth a structure with indices that have an x/y/z/w substructure (the type of structure that would feed a GLTools Structure Renderer, or an OpenCL vertices input, etc.)?

I know it's possible to smooth a structure with a value for each index (the music visualizer does that), but I can't figure out how to smooth with javascript in this type of scenario. It's easy to smooth the values by using an iterator and queue, and publishing the results, but I want to see if avoiding that gains fps.

If this could be done with OpenCL and get higher fps, it would be really interesting, but I'm dubious. Also, I'm not sure if this is something that a dedicated plugin should do (?).

Any help would be greatly appreciated, and I'll post the subsequent result.

Nested structure (leafed) (Composition by usefuldesign.au)

Author: usefuldesign.au
License: (unknown)
Date: 2010.07.04
Compatibility: 10.5, 10.6
Categories:
Required plugins:
(none)

This is a tutorial composition demonstrating the difference of item indexes and keys when both are numbers generated within, in this case, a Javascript patch.

Was made in response to the question on this thread Sorting Part Structure

Help with Structures and Javascript

0101000101000011's picture

Hello. I'm seeking information/tutorials on using structures and Javascript in QC. Separately and together that is. What are structures, what all can they be used for and how? Same for Javascript. XML MIDI structures? I've used many objects that take structure input, as well as objects that modify a structure, and deconstructed some Javascript to try and understand how it's working. Thats been pretty much my learning curve in QC so far. Figure it out through cause and effect...

One thing that's been on my mind for a while is, somehow making an application for a Monome with QC that would visualize different data sources synced to a tempo. I'm thinking, it's probably possible, but more likely easier programmed in Max. Of which I have very little knowledge. Thus I'm thinking a better knowledge of structures and javascript may yield such an app. I just don't know where to start... I should really just learn Max and build these as M4L devices as they probably won't run as efficient as VDMX plug-ins...

Anyways... Structures and javascript in visual compositions... Rather than control^ Any responses, or perhaps demonstration comps would be greatly appreciated. Thanks.