EnsureValue, model and for each loops

Bonjour !

I m encoutering a logic problem
i believe its the way i m dealing with for each loop and refreshment of the model with ensure value.

On a same object I m animating points live with a leapmotion and recording the positions in a player.

An object have multiple point. In each player i choose wich one is manipulated and record its trajectory.

With one player everything works perfectly.

But adding another player to this object just cut any output playing.

Thank you for your nice advices !

runtime animate points.vl (60.9 KB)

Are your LayerModel, PlayerRecorder, collections etc. mutable or immutable?
Your patch is all red btw. So we don’t get the full picture here.
You are saying that the Model doesn’t hold all changes that you tried to apply?

1 Like

hello @gregsn
yes sorry its difficult to get it out from the app. (big patch) Thank you for your question !

everything is Records:

LayerModel contains the points (spread ControlHandle) to be manipulated

Players recorders are handled by a manager and the record position from 2 hands in xy format:

Going inside the DoubleRecordPlayer there is a warning :

I dont know how to deal with it - surely a classic-, as it seems maybe the fault of it . trying to copy in a recorder its containt doesnt seem easy

Well, that very much sounds like the culprit yes.

Can you try to remove any functionality from your Records in order to not run into those niche situations?
If you’d just follow a simplistic approach that distinguishes data from functionality, you’d end up with your immutable data on one side and some patches operating on the data on the other side, which should allow you to fiddle the state (via accumulator and what not) and produce a new snapshot of the model that contains all the changes.

Hope that sounds like a viable approach.

first thank you @gregsn !

i think i may understand the philosophy, its not the first time i m encountering this problem with classes functionnalities from Gamma Core, and records. its possibile that i have plenty ones around…

Is there any “container” that could cheat a class to a record ? I mean there are many great tools in classes format in Gamma. No magic for it ?

except rewriting completly a sequencer in a dirty and surely less well working by s+h data in a spread, i dont see how to do this “defragmenting” thing between fonctionnalities and data.

Could you just provide a simple patch example of this that i understand ? thank you

Basically, you typically already work with records in a way that you modify them from the outside.
I see a Record with many property setters:


It tells me that often enough you feed the snapshot data from other patches.

So I was just wondering if you could move the Sequencer to the patch, that is calling MyPlayerUpdate?

Hum, the sequencers are called by this function :

This update is done in Layerruntime_players_and_transformations:

Here is enclosed its definition
runtime players definitions.vl (71.2 KB)

Aie aie aie ! :)

I see terms like player and runtime. Those sound to me as if they should be modelled as part of a runtime, which typically is mutable and has longer lifespans, like those players should conceptually be there as long as you are editing.

On the other hand the models have short lifespans. They model the different snapshots of the model. It still feels like this could be refactored. So the players’ lifetime is managed by this big ForEach loop. And the players lead to new snapshots that you then push back to the main model channel.

I can’t do it over here, because most of the nodes are red. But do understand what I am trying to say?

thank you @gregsn
First of all, thank you for the quality of this exchange. I can get a sense of where all this could go, but I have no idea how it would be implemented in practice. I’m not a skilled C coder, and I admit that all this is very, very, very abstract, or more likely at a different, very, very different level than mine. We’re missing help files concerning models, philosophy, and project structuring.
I thought my problem was one of class versus record. Seems not.
In the architecture of this project, the Leap data is processed upstream and decoupled. Everything is split and recorded, perhaps with extra steps.
All the project is a model.
No, I don’t see the concrete application. But thank you!

hum, passing to class the double recorders is cleaning the warning. still a logic probleme in my patch i think …

Any progress?

Just had another look at the screenshots and wondered if PlayersManager and DoubleRecordPlayer are just both outside of your Model and both should be classes.

Macro probably as well?

Maybe this is the first thing to get right:
deciding what is part of the model and what is part of the runtime.

So runtime types have properties, like “currently recording”, “play mode” or similar. Those are not the most crucial things that you’d want to persist and serialize. It’s more like the current mode of your editor that edits the model.

Model types have all the crucial bits in there.

Model types should be records in order to get all the snapshot-, easy-to-detect-changes- and undo/redo-functionality…

Runtime-types & Editor/Controller-patches are all just mutating (Classes) for ease-of-use. Non need to fumble new snapshots of those. They just mutate in-place.

Hoping this makes sense in a way.

1 Like

Thank you gregsn, yes it makes sens !

thats what i didnt understood clearly. it takes me quiet a few reads and a night of sleep to understand now. Thank you !

1 Like