Group Admins

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Public Group active 21 hours, 51 minutes ago

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

Set slot values in Lisp

Author 3 Subscribed Users |
Profile photo of davidsg
davidsg

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!

Attachments:
  1. note-to-chord

    note-to-chord.png

October 11, 2018 at 18:26 #28051
Profile photo of Karim
Karim

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

October 11, 2018 at 19:16 #28055
Profile photo of Jean
Jean

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

October 11, 2018 at 19:28 #28060
Profile photo of davidsg
davidsg

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

October 11, 2018 at 21:17 #28061

You must be logged in to reply to this topic.

Log in now