< Back to IRCAM Forum

Set slot values in Lisp

I can’t work out how to correctly set slot values for objects in Lisp code.

Here is a minimal example:

(defmethod note->chord ((self note) (offset list))  
  (let ((chord (objfromobjs self (mki 'chord))))  
    (setf (slot-value chord 'LOffset) offset)  
    chord))

Please see attached screenshot:
When I evaluate the CHORD from the fourth outlet (lonset) the return value is (0), but I was hoping for (50). Can someone help me out?

Thanks!

note-to-chord.png

Hi David,

i propose the following, since it is non destructive (it will not change the chord but creates a new one with your offset values.

(defmethod setchordoffset ((self chord) (offsets list))
(let ((clone (clone self)))
(setf (loffset clone) offsets)
clone))

Patch in attachment.

BEst
K

Patch-12.omp (4.74 KB)

Hi there. The explanation is: the visible slots of score objets (e.g. Loffset, etc.) are kind of “fake” slots, which are used as accessors (get/set) from the OM graphical interface to read or set the list of NOTE objects which actually make the contents of a CHORD object.

In order to change the offset of the notes, you shound therefore either go through this list on NOTEs (using the slot inside), or (as proposed by Karim) use the (setf (loffset chord) offsets) accessor function (which will internally calls the chord-building initializer for you) instead of (setf (slot-value chord 'LOffset) offsets) (which will have no effect on the inside NOTEs).

Best regards,
Jean

Thank you both for your prompt replies - much appreciated!
All the best