< Back to IRCAM Forum

Help updating a variable

hello om-ers,

i’m rather new to openmusic although i’ve been trying it rather extensively.
i need some help in updating a variable. i’m not sure how to do it in om, i mean in graphic mode, as i managed to do it under lisp boxes.
any help is greatly appreciated here. any tip or advice in doing this:

i have a loop taking in some data which is processed by an internal patch and i need to send this result again to the same patch over and over updating that data each time and collect all results.
i’m failing big time trying this. i know this is surely fairly easy to do, a beginner’s fault, but i think i’m lost.
thanks for pointing the right directions,
perti

Hi Perti,

It seems to me you want ot do something like in tutorial 36 and 37.
Check them out.
[hope this is what you are looking for…]

Best
K

thanks karim,

thanks for your fast reply.
i’ll look into tutorial_36, as it involves a loop. tutorial_37 does the recursive thing inside the factorial patch, something that i can do in lisp code.
to be a bit elocuent, the internal patch is called pcs-criteria, with four inputs, which takes a pcset (a list), an integer for cardinality, a float for morris similarity index, and an integer for common tones. it gives back a list of possible candidates meeting those criteria. with nth-random i get one pcset (and yes, this coarse method will be refined afterwards). so i want to put that result back in input1 and get another pcset. at the same time all other inputs change their value according to their respective lists. of course i’ve ran into cycle. is there some way to initialize and store the output and send it back to input1 ?
i wonder if i should use store and get-slot, but i didn’t understand its documentation. really, i’m lost.
thank you so much if you’re still with me. (i don’t have a screen-capture software right now)
best regards,
perti

Hi Perti,

Appart from om-tutorial36 and 37 the only ways I know for doing recursivity are resumed in the two patches below.
The basic of recursivity is a function calling itself with a condition for exit. Inside that there are many ways to do it.

Happy Christmas.

fonction-recursive.omp.zip (1.26 KB)

hello jean michel,
thanks for the omp files. i need to investigate them to understand. i’ll post when i find out how to make use of them.
thank you again!
merry xmas,
perti

hello again,

@jeanmichel
fonction-recursive2 does partially the trick. changing the function inside it produce some results. i get a sequence of pitch class sets which meet the conditions prescribed: cardinality, similarity index, quantity of common tones. so far, so good. the problem i find is that i need to pass a list of those criteria, so they change along the sequence of pcsets. if i pass a similarity index near to 1 (very different), i get a sequence alternating very dissimilar pcsets (3-1, 3-11, 3-1, 3-11…) so it gets necessary this index to change along.
i tried making a loop with your fonction, but didn’t get the right output. that’s why it seems i have to find some way of updating the pcset in the loop following the list of ‘parameters’. i know this is doable by writing code via setf in the loop, but as this patch has various levels, it got difficult for me to write it in lisp code.
please see the attached pics of how i modified fonction-recursive2, and my original (and wrong) patch. i can upload the omp file if you prefer.
thanks again!,
perti

Snap3.png

Hi Perti,

What I understand about your project is that you need recursion. The last patch (Snap3.png) is not recursive.
Going recursive in an omloop is illustrated by OMTutorial36 & 37.
The two patches I sent you are recursive in the way “patch in itself”. It’s the same thing but done differently.
You need to figure out that in the patch “function-recursive2” you used, the exit condition is the number of elements. So it updates the last value of the list then append it until there are n elements in the list. Then it stops (exit).
You can change the exit condition as you wish like comparison between numbers, value of any element etc…

If you send me the .omp patch (and what result you expect) I might (perhaps) understand it and tell you.

All the best.

Jean-Michel Darrémont

hello jean-michel,

i’m attaching the omp file. please excuse me for the mess you’ll find inside the omloop.
it’s possible to make it work if i re-write it in lisp code, “setf-ing” the in1 to the obtained candidate in the collect part of the loop.
but i’m still not sure if this can be done with om’s “graphic mode”.
thanks in advance for the time and energy you’ll put dealing with it,
perti

pcs-criteria2.omp (5.08 KB)

Hi Perti,

For a recursive programming in OM you need to make a “red patch” doing the basic task once with the required numbers of inputs. This is the core patch.
Then you put this core patch in a “green patch”, this is the function patch. Then put this function (green patch) in itself and it is where is the trick to figure out what to connect to what and choosing the elements with “last-elem” and “x-append” and/or whatever list processing functions. Last but not least, you need an exit condition otherwise this is an infinite loop.
In the patch you sent there is no core patch and it would take me too long to understand what it is supposed to do.
Anyway it is a recursive function which is perfectly graphically doable in OM. If I’m not wrong, fonction-recursive2 should do the job with few changes but I’m afraid that you are the best qualified to do it. Recursion is a very powerful and elegant programming solution.

Have a good day.

Jean-Michel Darrémont

ok jean-michel, thanks for the explanation, i think i understand better now, and i’ll try again hopefully in the right direction.
sorry the patch was so messy. i cleaned it up before sending it but forgot to turn the inner patches to red, so most changes were lost when i saved it.
thank you so much again,
best regards,
perti

Hi Perti.

it’s possible to make it work if i re-write it in lisp code, “setf-ing” the in1 to the obtained candidate in the collect part of the loop. but i’m still not sure if this can be done with om’s “graphic mode”.

In general, to make it easier for others to help with issues, try to isolate or set up a prototype case (ie. get rid of everything else than the basic problem giving you troubles) and send it as an .omp.

If you’ve got working lisp code the whole case should be easier, so bring it along.

Cheers,

-anders

hello anders,

here you have the lisp files, and also i’ve included a testing patch. as you can see i’ve got the expected results. i’m sure that you’ll find them rather horrible from a programmer’s standpoint. i’m not one. so to me, the first things to be done is to get results. then after may come the better and elegant solutions.
for a given pcset, and three more variables (cardinality, morris similarity index, common-tones), you get a list of candidates that meet those criteria.
using the same core of the other file, you will obtain one of two outcomes:

  1. just one candidate randomly chosen (i hope to refine this method)
  2. a list of pcsets which are sequentially related by criteria given in a list.
    beware i didn’t manage for errors, for those situations in which no pcset meet the prescribed criteria. that is why i put the lisp functions in a patch, so the input data is giving no errors.
    although i struggled a bit to do it in lisp code, i knew that it was possible get the expected results. my original question was about how to do it graphically in om (by the way, i’m still trying).

thanks, and have you all a very happy new year!

criteria-testing-patch.omp (7.8 KB)

oh, i don’t see the oml files attached. here they go again.

i’m not sure what happens but i did attached the files and they are not getting through…
i’ll try once again

criteria-testing-patch.omp (7.8 KB)