v8 JS: push successive lists into an array and output a dict

Falk Grieffenhagen's icon

Hi,

I am stuck finishing a JS that is supposed to push successive lists into an array which is a subkey of a dictionary. I made comments into the v8codebox to describe my problem.

there is a dict in the bottom left that I want the output of the v8 to be. The coll on the top simulates the data coming in.

In other words: stream the coll dump into a dictionary with the structure below where the pitch sequence (chords or single notes) is represented by an array of arrays. Maybe its smarter to have an array of dics...

I am close but not there...

thanks Falk

{

"seqA" : {

"1" : {

"pitch" : [ [ 1, 2, 3 ], [ 4, 5, 6 ], 7, [ 8, 9, 10, 11, 12 ] ]

}

}

}

Max Patch
Copy patch and select New From Clipboard in Max.

TFL's icon

Could you explain at a higher level what you actually want to do? I feel like you're overcomplicating things.

Why the output needs to be a dict? Can it be something else (list, array, coll)?

Is there a reason why you use JS to do this instead of plain Max objects?

Anyway, your problem is that b gets reset every time you call pitchAdump. You would get the expected result if you declare b outside of the pitchAdump function, and use b.push(a) to append the current array to b.

But then you need a way to clear b, but it's not very clear when it should clear regarding your example.

Max Patch
Copy patch and select New From Clipboard in Max.

But again, maybe there's an even simpler solution but for that I need better explanation of what all this is for.

Falk Grieffenhagen's icon

Hi TFL,

this looks great, many thanks!! I don´t see a problem with b since I can add a function that gets called before my dump:

function reset() {

b=[];

}

This is an excerpt of a multitrack midi Sequencer I made with RNBO where the only controller is a note-only midi keyboard. The sequencer is more or less in beta and working fine but so far there is no way to save sequences in an editable format. I also want to port this to a web browser incorporating P5.js and I want a way to make presets as JSON files that can be made with JS out of a browser, without any further max programming. These Coll Dump messages stream right out of RNBO into a Dict, that's wat I had in mind. Well The other reason I am doing this is to reanimate my dusty JS skills and learn the benefits of v8. --doing JS with the codebox really rocks!-- There is a Max GUI that shows the state of the sequencer, porting this will be the next thing to focus on.

thanks again Falk