< Back to IRCAM Forum

How to execute a function when loading a library?

Is there a way to automatically execute a MIDI function when loading a library, for example to select a default bank. To load my library, I use the following code:

(defvar Opus-lib-files nil)

(setf Opus-lib-files
(list (om::om-relative-path '(“sources” “opus”) “midi”)

(mapc #'compile&load Opus-lib-files)

If I introduce a line of code of type (ctrlchg 0 1 1) into my “source/opus/midi” file, I have to evaluate it again so that the message is sent.

Thanks a lot for your help

Dear Philippe,

In fact when you load a library you execute code. The problem you are mentioning with ctrlchg is that it is executed within your library, but since this method just sends MIDI messages to what is connected to your MIDI port, and if nothing is connected YET to your port, the message i sent in the void.

I think what you are looking for, is a customized ready OM launch with everything connected, etc…NO?


Dear Karim,
Yes, that’s exactly it. I have temporarily worked around the problem with a small “bank-init” tool that I only need to evaluate once at the beginning of a session (after loading my library). But if there is a solution that is not too complicated so that this can be done automatically, I’m interested of course.
Have a great week and see you soon.

Dear Philippe,

Didn’t think about this. What you can do is create a lisp file and
put your bank-init as a function inside and whatever. This will be evaluated AFTER all loads (but before loading the workspace). If you have your midi devices (virutal or Hard) on and already connected, the function will send whatever midi send you want.

I enclose a workspace example based on the program change of tutorial 10.

test.wrk.zip (5.5 KB)


Dear karim,

Thank you very much for giving me the right location to evaluate my MIDI initialisations. Your method works perfectly. I naively thought that it could work by inserting it in the last evaluated file of my own library.

Have a nice day!

1 Like