SOLVED: Maybe a timing issue from reading the JSON file and executing it

Hi @jean-emmanuel

I have a new version of the harp and it works, but most of the time when I start it there are problems.


Line 21 is the scale.length in the "matrix_2A_harp"

My way is from "variable_harpScale".

IMPORT{add_scale_v2.json}

to the "menu_2A_harp_scale" widget to set "scaleJSON".

var harpScale = get('variable_harpScale')
setVar ("matrix_2A_harp","scaleJSON",harpScale.scale[s].scale)

to the "matrix_2A_harp" widget with the "scale.length" (This is the 21 error)

var scale = VAR{scaleJSON}
var octave = 12 * Math.floor($ / scale.length)

I think that one is a timing problem: Here I have the session. You only have to open the "HARP_v2.json" file, but the "add_scale_v2.json" file has to be in the same folder.

HarpV2.zip (4.7 KB)
Maybe I built it too complicated.
I need a little bit fresh air in my brain.

2 Likes

You need to wrap the code that reads the content of variable scale in a conditional so that it doesn't fail when VAR{} returns undefined

var scale = VAR{scaleJSON}
if (scale) {

} else {

}

or provide a fallback value that works until it's loaded:

var scale = VAR{scaleJSON} || []

Thank you... I will try that tomorrow.

Is this correct if I use a variable
"var i = 0" in a widget, is it only valid within the widget? (Except of course setVar)

Yes It is.

That looks amazing. And you added a bunch of extra scales :wink:

Just curious why you removed the pedal buttons?

many thanks @Mike1
I'm not quite done yet, still need to work on a few timing problems.
I had to decide if with pedals I was bound with 7 strings per octave or if I wanted to be free. Now it can be "Eqyptian" with 5 or bebob with 8 strings. Also the "add_scale_v2.json" file with the scales is easier to understand and you can expand it yourself. See Picture the green column.
Bildschirmfoto 2023-04-17 um 07.50.06

@jean-emmanuel

Just to understand.
In your manual you wrote " VAR{}: use getVar()instead"
Bildschirmfoto 2023-04-17 um 10.56.28

In my "matrix.props" example I use a lot of VAR{}

JS{
var props = {}
var scaleNumberOfKeys = VAR{countKeys} || []

return props
}

1). Is there possible to use "getVar" or is it ok if I continue programming there with VAR{} in the matrix props??
2.) If I use...

var keyNote = VAR{keyNoteNumber} || []

... The Value 0 will not be tranfered!

To help me I can calculate the 0 plus 1...

setVar ("matrix_2A_harp","keyNoteNumber",k+1)

... and than calculate back with minus 1

var keyNote = VAR{keyNoteNumber} || []
var keyNoteMinusOne = keyNote-1

but isn't there an easier way?

Wow, you did it! It's really great! Very practical the range slider.Thanks for sharing.
I had started to look at this idea from your previous harp file but I'm not good enough with script.

Eventually some proposals for improvement:

  • have a keyboard widget that updates according to the notes in the chosen mode and offers the possibility to add notes in the mode by clicking on the keyboard.
  • to have a matrix slider (which updates according to the number of notes in the chosen mode) and which gives the possibility to change the order of notes in the matrix harp.

@denisspycher props is not a scripting property, this warning doesn't apply and scripting functions are not available here.

I'm not sure to understand your second question, but it seems you're providing an empty array as fallback value for a variable that's supposed to be a number (I guess || [] should be || 0 here). Note that for simple (non-object) values you can provide a default value directly in the VAR syntax (VAR{name, default}).

ahhhh... Thanks
now I understand the syntax.
|| 0 will be for a number and I think
|| "" will be then for a string.

Sometimes it could be so simple :wink: