< Back to IRCAM Forum

Cluster-rules and ta-utilities libraries don't appear

I’m having issues with the cluster-rules and ta-utilities libraries.

The libraries load but do not appear in the ‘Functions’ menu. See attached images.

Library window_Cluster Rules
Library window_TA Utilities




Lisp listener

I’m running OM 7.1 on Windows 10.
Any help is appreciated!

Dear Steven,

This is perfectly normal, since this is not packaged for OM. It just loads Lisp.
However it is not a big deal to have access to functions/method from that code.
It is just a matter of creating a lisp file to load thelib, and most important, locate the necessary functions/methods to put in the menu. Do you have some idea?

Best
K

Thanks Karim. I’m not sure how to create a lisp file to load the library/locate the functions. Are you happy to demonstrate?

Dear Steven,

After examining the code, i an afraid that this will not work in OM. It uses functions from other environment such as opusmodus, and since it is not open source we cannot import these functions. So it useless to port it in OM.
What i suggest is to contact the author of this code and ask himn to provide these missing fucntions:

om:omn, om:omn-formp, tu:map-neighbours

Best
K

That’s ok - thank you for investigating, Karim!

@torstenanders - any insights on this?

Hi Steven,

Funny that I’m running into the exact same issue so soon after you posted this. Have you tried looking into GitHub - tanders/pwgl-cluster-rules: A library for PWGL that defines rules for the PWGL library Cluster Engine, also by Torsten Anders? I figure it may be easier to port PWGL things over to OM than Common Lisp, especially if his Common Lisp version depends on Opusmodus (I hadn’t realized this). The PWGL version isn’t dependent on ta-utilities, which already reduces the complexity.

I’m still quite new to working with Lisp libraries and haven’t been able to wrap my head around the differences between OM/PWGL/Common music. I tried just substituting all instances of PWGLDef with om::defmethod!, but it seems like it’s more complicated than that. I found this project: GitHub - kisp/ompw: OMPW provides an abstraction layer for writing Lisp libraries that can be used in "pure" Common Lisp, but also in the OM or PWGL environments. which offers a way to unite the three, but there’s not much documentation, and it seems that instead of doing a conversion from PWGL to OM for instance, we would have to rewrite the whole thing in the abstraction language, which could then be converted to OM compatible Lisp. I am likely misunderstanding this, but perhaps we can figure out together how we can get this PWGL library over to OM. As far as I can tell, Cluster-engine is the most modern iteration of Örjan Sandred’s constraint programming projects, and seems to be one of the most robust. It would be great to be able to access the rich library of extensions that Torsten Anders has compiled for it!

@haddad Do you think it would be possible to port the PWGL version over to OM? If so, would you mind giving us some pointers on how to go about tackling this problem? Thanks in advance!

K

Dear Kjel,

After examining the PWGL version code, i am afraid that this will not be an immediate solution. Some work has to be done to port most of this code due to particular calls for PWGL specific methods.

You can also use this library ported to OM:

And also might contact the author. He has done a very good job porting this to OM.

Best
Karim

Hi Karim,

Thank you very much for taking the time to look that over. I figured that may be the case.

@paulohgraposo - do you think this would be a reasonable project? Your port of the cluster engine is already fantastic and I think the cluster rules would be the cherry on top. Steven and I could potentially help out if you give us some pointers!

Just for reference in case these links get buried in the thread, our choices for starting points would be either GitHub - tanders/cluster-rules: Rules defined for the music constraint solver cluster-engine by Örjan Sandred which would be porting from Common Lisp with dependencies on ta-utilities/opusmodus, or GitHub - tanders/pwgl-cluster-rules: A library for PWGL that defines rules for the PWGL library Cluster Engine from PWGL (the PWGL code is also found in the z-PWGL folder of the Common Lisp folder as an archive–not sure if it’s identical to the pwgl-cluster-rules repository code).

1 Like

Hi all,

Digging a bit deeper, I remembered noticing that Anders’ cluster-rules repository readme lists cluster-engine and ta-utilities as dependencies, and I went back and verified that he doesn’t mention opusmodus here. I may be wrong, but I think he probably included opusmodus functionality, but that it’s not actually a dependency, in that it can be used with or without opusmodus. There are places in the code (line 93 in melody-rules.lisp), that say “when using Opusmodus”, implying that it can be used without. I understand this doesn’t make the task of porting easy, but I wanted to mention it because the word dependency might not be the most accurate. The dependency on Anders’ Common Lisp version of cluster-engine might actually be more of an problem, because it won’t be possible to easily plug into Paulo’s OpenMusic version of the Cluster Engine.

Hi everyone!

This is a great project!
I remember that I looked at the Cluster-Rules library when I was working on CE. It is very laborious to port it to OM, but it is possible.

First, I believe it is important to know the differences between the PWGLDef from OM defmethod! .
Then it is neccessary to check if there is any PWGL function that is not available in OM (like pw::g-mod. This can be replaced by the om// function, for example). This is problematic when dealing with PWGL’s BFPs and ENP Score objects.
There are some annoying things too. For example, in OM the function arithm-ser have the arguments begin-end-step and the PWGL equivalent, pw::arithm-ser, have begin-step-end as arguments.
Cluster-Rules.zip (73.1 KB)

I’ve made a little test today porting the function no-voice-crossing to OM.

The workspace is attached here (the lisp file, with some notes, was placed in the infiles folder).

I believe this is a start.

Best,

Paulo

1 Like

Hi again!
I’m checking the Ta-Utilities library and I believe most of the code is compatible with OM.
This is a starting version:
ta-utilities.zip (98.3 KB)
P.S.: the functions that appears in the menu was included in the file “/libraries/ta-utilities/ta-utilities.lisp”. All other files was moved to the "/libraries/ta-utilities/sources/ folder)
I dont know if everything works visually, but if it is just a dependency for the cluster-rules library, maybe it will not be necessary to finish this. Maybe just load the lisp files will be good enough.

Best,
Paulo

1 Like

Hi Paulo,

Thank you for you very detailed and illuminating reply! I learned a lot from your example. I have a few follow up questions in you don’t mind:

  1. Your code works flawlessly when evaluated in the lambda function and used in the patch like in your example, but I tried to turn this into a library
    Cluster-Rules.zip (81.1 KB), and when loading it I’m getting the error “Cannot read character U+0080 as part of a token because it has constituent trait ‘invalid’.” Is this maybe because defmethod! are not supposed to be in the sources files? I’ve noticed that typically the .lisp files in library source folders contain mainly defun, and in your ta-utilities library (which looks to be working, bravo!), you have a couple defmacro as well, but not so much defmethod!. This leads me to my second question.
  2. What is the difference between defmethod! and defun? So far in my limited Lisp programming exposure I’ve been dealing mainly with defun/lambda, and it seems like these is more or less standardized across implementations of Lisp (I may be wrong), but I’m a bit baffled by how different defmethod! is from PWGLDef. From a quick search is seems like defmethod! provides some kind of object oriented elements, but I don’t quite understand why we need them.

Thanks again for taking the time to look into this. I’m becoming hopeful that we can make this happen!

Kjel

Dear Kjel,

Here you have a working cluster-rules library:
Cluster-Rules.zip (71.3 KB)

Two problems you had:

  1. You should have the same named lisp file Cluster-Rules.lisp as your library’s folder, and it is case sensitive.
  2. You had an encoding problems coming from the second line of the sources file: cluster-rules-test.lisp:
(require-library "Cluster-Engine")

It is corrected.

However, it seems to me not very logical to make a library just for one method. Maybe Paulo can include this into his Cluster main library?

Now concerning defun, defmethod and defmethod!
There is a big, huge difference between a method and a function:

A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed.

A method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for two key differences:

  1. A method is implicitly passed the object on which it was called.
  2. A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data).
    (from : oop - What's the difference between a method and a function? - Stack Overflow)

Now defmethod! is a special method declaration implemented in OM allowing you to allocate, input/outputs, icons, documentation of a method. Beside that it is still a CLOS (Common Lisp Object System) method.

Hope this helps.

Best
K

Hi Karim and Kjel,

Thanks Karim for the explanation and for the fixing.
And yes, it makes no sense to create a library for just one method.
I think what Kjel have in mind is to port all the Cluster-Rules functions to OM, if I understood correctly.

I’m also examining the sources from pwgl-cluster-rules and cluster-rules repositories and I realize that the author already create a partial version for plain Common Lisp that is independant from PWGL. Because of that we have two different versions of the same rule.
For the no-voice-crossing rule, for example, we have:

1-) The DEFUN version (that works in any LISP implementation with the plain Lisp version of CE too):
no-voice-crossing-lisp.txt (1.4 KB)
2-) The PWGL version, that works only in PWGL environment (requires PWGLDef for creating the visual box, similar to defmethod! in OM):
no-voice-crossing-pwgl.txt (1.5 KB)
3-) The new OM version (created with defmethod! - this should be done with all functions if we want a nice visual interface in OM):
no-voice-crossing-om.txt (1.4 KB)
4-) We can also use the defun versions fom Cluster-Rules (not pwgl-cluster-rules) inside the OM version, but the name name of the method defined with defmethod! cannot be the same name of the function (that’s why I’ve change the names in the OM version of the CE library).

My suggestion is to start with something like this (I’ve included the ta-utilities inside the previous file sent by Karim with all the original sources):
Cluster-Rules.zip (189.4 KB)
Then we have to create a new method with defmethod! for each function of the Cluster-Rules library defined with PWGLDef (or defun) and substitute the PWGL functions and classes for OM equivalent ones. The new methods should be placed in new lisp files inside the /Cluster-Rules/sources/ folder (harmony-rules.lisp, melody-rules.lisp, etc.). Finally we have to find a good icon for the methods, rewrite the readme file and create the tutorial patches (should be placed inside the examples folder).

I believe this covers all the work, but will take some time to finish.

P.S.: Karim, I know this is another subject, but I believe I’ve found a way to avoid the lexical closure error in CE library with a new function (fix-ompatch-rule):

(defun fix-ompatch-rule (lambda-patch)
(let ((exp (om::function-lambda-expression lambda-patch)))
(eval `(function ,exp))))

When using this in all CE methods, like (fix-ompatch-rule rule), the lexical closure error disappears, even with all rules inside of patches (there no need anymore to lock the rules->cluster). This needs more testing and I don’t know why this is happening, but I’ve included these changes in the CE repository yesterday (for a future update release).

Thank you all.

Best,
Paulo

Dear Paulo,

Great for the lexical-closure fix!

Now concerning the above cluster-rules functions, I don’t think it is worth transforming all defuns into defmethod!s, since even a defun could be called in OM and loaded in a library menus. The difference will be, that all defuns will not have an icon, and that’s all.
I don’t know pretty much the code (but will look into it) and maybe one should decide to turn main functions into defmethods only for end functions.

Thank you a lot all of you for your enthusiasm to all of this.
Best
Karim

Dear Karim,
Thanks for your fast response.

I agree. Complementing, only the functions that are listed in the original menus.lisp file needs a defmethod! version (not all defuns).

Best,
Paulo

Dear All,

Here is a version with all functions in the menu following the model of the cl version code.
Yes, I left these as defuns and not methods. But this should work mostly.
There are some “dark spots” in the code particularly in the melodic-rules, where some fenv:: package was used. After examining the code, i assumed that this is related to BPFs.
So it is still work in progress.

Here it is:
Cluster-Rules.zip (443.7 KB)

By the way maybe we should consider to put it in a repository.
What do you think?

Best
K

Hi all,

This is exciting stuff! Paulo is right that my idea was to port all the functionality. I just wanted to have a proof of concept, with the idea being that if I can get one function working in a library, then I should be able to keep going with the rest.

I’ve created a GitHub repository for om-cluster-rules with Karim’s most recent version. The only changes I’ve made are that I drafted up a preliminary icon in GIMP, and I tried my hand at creating a defmethod! for the no-parallels function of counterpoint. It seems to be working as a single rule from what I can tell, but when I try combining it with no-voice-crossing in a rules-to-cluster object I get a “variable intervals is unbound” error. I’m also not sure how I would integrate fix-ompatch-rule.

You guys might prefer to run your own repository because you have a lot more experience than I do and are much faster. All the projects repos that I’ve managed so far have just been me working alone, but if you guys are keen, I can take pull requests as necessary and I can slowly chip away at replacing defuns with defmethod!s in the coming months.

Let me know what you think.

Kjel

Thank you @haddad, @kjel and @paulohgraposo for your enthusiastic response to this!

I will test what you have created so far and let you know how I go.

Best,
Steven

(btw, I’m the original poster; I have a new ircam forum account)

Dear K,

I’ve installed your version. I have this error, nothing appers in the Listener but : OM > “Loading library Cluster-Rules”

image

Best,

Jerome