Group Admins

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Public Group active 16 hours, 42 minutes ago

User group for OpenMusic and computer-aided composition. Visit the Forum for discussions.

writing an OM library

Author 3 Subscribed Users |
Profile photo of
Anonymous

Hi all,

I would like to know how to create an Om library.
So far I have copied the file into the user file folder of the workspace but it would be nice to access the functions from anyworkspace.
On the user manual there is a link about how to create a library but it doesn’t seem to work.

Thanks!

Michele

October 20, 2013 at 17:14 #6345
Profile photo of Jean
Jean

Hi Michele,
Maybe this can help : http://repmus.ircam.fr/openmusic/dev-resources/userlib
(we shoold update the link in the user manual…)
Best
Jean

  • This reply was modified 5 years, 4 months ago by Profile photo of Jean Jean.
October 20, 2013 at 23:27 #6401
Profile photo of
Anonymous

Thanks Jean,

One more question: can I change/add functions to the lisp buffer stored in the user folder of my workspace on the fly without having to reopen the workspace?
What I mean is, if I change one of the fuctions can I use it right away or do I have to quit and restart open music?
I tried evaluating and saving the lisp file but it doesn’t work.

Best,

Michele

October 21, 2013 at 22:32 #6427
Profile photo of Karim
Karim

Hi Michele,

Of course.
Here what to do :

If you want to create a new fuction of yours, just create a file named “foo.lisp” or whatever.
THe first line must have this :
(in-package :om)

then your function :

So this will look like that :

;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :om)

(defun whatevermyfunction ( x y)
(list x y))

;;;;;;;;;;;;;;;;;;;;;;;;;

THen you save your file in the /Application/OM 6.xx/patches folder

and that’s it.

THe thing is , if you want to use your function, (once you restart OM) you should invoke it by its name “whatevermyfunction”
by cmd+click in a patch and type its name…
this is the diff between having a lib, where you’ll have the names of your functions in the lib menu, and on the other hand, have to type and remember your own functions in the .lisp file in the patches folder.

However one thing to be careful with , is the function’s and method name. Beware not to use the same names for these, or else, either they will be re-defined, or you’ll have some sort of a lisp error message .

Hope this helps
Best
K

October 21, 2013 at 22:40 #6429
Profile photo of
Anonymous

Thank you Karim, it works great!
So I guess I will use the lisp file in the /Application/OM 6.xx/patches directory rather than a library. It seems to be more readily changeable, is that correct?
What would be the advantage of having the function in a library, aside from icons?

Best,

Michele

October 22, 2013 at 10:15 #6430
Profile photo of Karim
Karim

The good thing using a lib rather than a simple lisp file, is that when you will have a lot of functions and you’ll begin to forget the names, etc.. in the lib you have the menu where you can overview your funcitons. Beside that , it’s the same.

Best
K

October 22, 2013 at 11:45 #6439
Profile photo of Jean
Jean

Hi all,

Just to make things clear: these files in “patches” (or in the “user” folder of your workspace) are loaded at startup, but if you want to edit and reload it, you don’t necessarily need to restart OM, but can just open and evaluate the contents of the Lisp file (menu Lisp > Eval All), or event reload the file without opening it (Lisp > Load file).

Libraries are a little bit more tricky to set up but as Karim says, they offer the possibility to better integrate the code in the OM “graphical” workflow.
They are also better suited to pack code and projects in a consistent way, typically if your code is in several Lisp files, which you need to load in a specific order etc. (you don’t control the order with the previous options)
Libraries can, be loaded “on-demand” when they are needed. They also allow you to document your code, and pack it with resources and tutorial patches, for example. That’s probably what you want to do if your code / project is to be shared/distributed.

About the “dynamic” aspects, you can reload edited code from the Lisp buffer at anytime. You can also reload the all library (and have the changes evaluated) with right-click + “reload library”.

Jean

October 22, 2013 at 11:50 #6440
Profile photo of
Anonymous

This is all very helpful! Thank you,

Michele

October 23, 2013 at 00:55 #6469

You must be logged in to reply to this topic.

Log in now