Way of modifying state of "fluid.robustscale" in puredata

Hello,

a bit of an odd question here,
I’m adapting some max code from Rodrigo Constanzo in Pure Data which implies at some point the modification of “fluid.robustscale” state:

fetch the “Range” in the json file
multiply by 2
replace the “Range” in the json by the result.

Yesterday I gave it a go, I fetched the “Range”, I multiplied, once I had to modify the json I ended up with an incorrect json file, not readable by “fluid.robustscale”. This task is made quite complex by pd itself, I know there’s an external for JSON parsing ( haven’t tried yet ) but the goal here is to rely on Flucoma only, no other externals.

So I’m wondering if I could get some help to get the same result without having to manually construct a json file in pd.

for reference, this is what’s to be achieved:

here’s what the data looks like before the processing:
{

“cols”: 8,

“data_high”: [ -26.247343063354492, 0.241597786545753, 63.95220947265625, 0.081183396279812, -40.074893951416016, 0.244581758975983, 90.867919921875, 0.000858980114572 ],

“data_low”: [ -42.08658981323242, -0.129064902663231, 47.55539321899414, -0.309432119131088, -96.38632202148438, -0.207946330308914, 27.48699951171875, 0.0 ],

“high”: 75.0,

“low”: 25.0,

“median”: [ -33.885108947753906, 0.090700931847095, 52.845741271972656, -0.018240973353386, -77.57266998291016, -0.012044765986502, 83.26824188232422, 0.0 ],

“range”: [ 15.83924674987793, 0.370662689208984, 16.39681625366211, 0.3906155154109, 56.31142807006836, 0.452528089284897, 63.38092041015625, 0.000858980114572 ]

}

And here’s what’s loaded into that dict in the patch:

{

“cols”: 8,

“data_high”: [ -26.247343063354492, 0.241597786545753, 63.95220947265625, 0.081183396279812, -40.074893951416016, 0.244581758975983, 90.867919921875, 0.000858980114572 ],

“data_low”: [ -42.08658981323242, -0.129064902663231, 47.55539321899414, -0.309432119131088, -96.38632202148438, -0.207946330308914, 27.48699951171875, 0.0 ],

“high”: 75.0,

“low”: 25.0,

“median”: [ -33.885108947753906, 0.090700931847095, 52.845741271972656, -0.018240973353386, -77.57266998291016, -0.012044765986502, 83.26824188232422, 0.0 ],

“range”: [ 31.67849349975586, 0.741325378417968, 32.79363250732422, 0.7812310308218, 112.62285614013672, 0.905056178569794, 126.7618408203125, 0.001717960229144 ]

}

So it’s literally just “range” multiplied by two.

1 Like

Curious if there’s some pd-specific thing that makes this approach trickier.

I’m curious if @tremblap has used this kind of robustscale “hack” in pd. In Max it works well and I use it all over as per his suggestion.

Well I managed to implement this, in an ugly way…
I hope it’s done right, I spent 3 hours on this.

Ooh, what’d you have to do as a workaround?

And what/where was the issue?

this looks great but I’m not able to look at it properly until next week…

1 Like

I read the json with “text” object, it comes up sliced in many elements, it just took time to figure out how to extract values then recompose the json formatted text. ( I never noticed one couldn’t type a “{” in pd it gets ignored )

There’s interesting re: special characters.

I guess the fluid. objects internally parse that just fine, but in pd-land the characters get absorbed.

I wonder if it would be possible to have an alternative parser for fits in pd-land for the flucoma objects as this “hack” of using fluid.robustscale and fluid.normalize with custom fits is massively useful.

In your patchers you manually edit a fluid.standardize state :

dict.pack std: mean:0 0 cols:8

then load in fluid.standardize

In pd I have to create a template json file, then modify it in pd ( with all json formatting issues to solve ) then save it and “read” it with fluid.standardize.

a way of doing this easily would be great ( & I think your way of adding weigths is interesting enough ! )

2 Likes

hello

So, an ‘easy’ way to `dump` the state, and `load` it, would be nice indeed. but Pd doesn’t have a native dictionary style file/data structure. So @weefuzzy and I got stuck.

Let’s brainstorm here what would be good, ideally without needing an external dependency. I am not a super specialist of [text] - would you be able to share your current hack? Maybe we could think of dumping and loadingfrom [text] but that is not going to be trivial…

2 Likes

Hello,

here’s the way I ended up changing the state of “fluid.robustscale”:
changeState.zip (1.7 KB)

it implies writing a file to disk and loading for each change
as the “load” method does not exist in Pd.

indeed, and in SC we use a temp file too. making load/dump work in pd natively with the interface to text would need a double coding ninja, one that has the patience to deal with the aweful old c pd api, and that also has modern c++ template ninja skills.

So that is on the ice for the time being, but finding hacks around by native pd-ist like you is what might give us the right interface once/if we bite that bullet.

thanks for sharing

the patch I uploaded seems to work, but looks aweful.
Main issue was that the json format turns into new lines at every comma.

inside “text” object it looks like this:

and here are the lines of the text object:

also using “{” and “}” is complicated in Pd that’s why I ended up loading a template json file, then modifying it.

while looking into that I just wished I could pass a message to fluid.robustscale with “std” then 8 values and it would set the state immediately.

the problem is that everyone has a different desire, hence using dictionaries when available… and then the problem is pd not supporting associative (key value) collections…

this would be a great pd feature.

1 Like

I went on with improving this hack, with another solution, with no template file, writing the whole json file in pd:

stdWeights.pd.zip (730 Bytes)

I add here also a method for modifying “median” and “range” sections of an existing fluid.robustscale state file:

rangeAndMedian.zip (3.4 KB)

These are not tested in real use case yet, but produce correct json files.

@yogi this is very elegant. It won’t replace a proper dump and load, but for that I’d need a lot of discussions with @weefuzzy to see how to change the wrapper to add those mechanisms, to a text object for instance - but for mlp for instance, or knn, where the dumped json is immense, a single line approach wouln’t work and I have tried multi-line in text and it seems to delete them.

Have you give a try the 2 json externals listed on deken in the end? they are only for macos so I feel your pain, but I’ll also write to the pd list about json parsing to structure and text being looked at with pointers - it is a complete brainblowing but some people might have done a native json parsing method with that, i have a hunch it is possible.

in all cases, I’m happy you found a way around. I’d write the file as .json and not .txt but it changes nothing for pd or our objects :slight_smile:

1 Like

No I didn’t, I’d like to keep it all “vanilla” apart from Flucoma itself, and I want the patches to load on any os.

I understand. the pd list is providing me with ideas, I’ll see if we can get something vanilla going…

oh that went fast: Request: A new object to handle dictionaries · Issue #2831 · pure-data/pure-data · GitHub . It seems that pd might get a dictionnary object in the near future!
Cheers for the pd list messaging !

2 Likes