OM# Documentation

Writing classes and functions

Any Lisp function or class can be used in OM# graphical programs. However, some specific syntax enables additional features.

OM# inherits from OpenMusic the syntax of function and class definitions that follow, so that any code written for OpenMusic can also be loaded and used in OM#.

The macros defclass! and defmethod! allow for your defined classes and methods:

The OpenMusic developer resources give the following examples:

(defclass! my-chord (om::chord) 
   ((tonality :initform '(C Major) :initarg :tonality :accessor tonality))
  (:icon :tonal-chord))
(defmethod! is-major? ((self my-chord)) 
   :doc "tells if the associated tonality of the note is major" 
   :icon 193 
   (eq (second (tonality self)) 'Major))
(defmethod! compare ((c1 my-chord) (c2 my-chord) lowest) 
   :icon 180 
   :initvals (list nil nil T) 
   :indoc '("a note" "a note" "mode-menu") 
   :doc "compares the pitch of 2 notes, and yields the lowest (or the highest) one" 
   :menuins '( (2 ( ("lowest" T) ("highest" NIL)))) 
   (if lowest 
     (if (<= (om::list-min (om::lmidic c1) (om::list-min (om::lmidic c2))) c1 c2) 
    (if (>= (om::list-max (om::lmidic c1) (om::list-max (om::lmidic c2))) c1 c2)
   )
 )

The defmethod!-specific attributes in these definitions are:

Note: :initvals applies to the visible inputs in the order of definition. In case of optional or keyword inputs, it is recommended that the default value specified in :initvals be the same as the one defined for the arguments in the function definition. Otherwise, the input woudl have a different default value depending whether it is visible or not.

Example:

(defmethod! my-fun (arg1 arg2 &optional (arg3 999)) 
   :initvals (list 0 0 999) 
   ...
 )