[gsharp-devel] remove-current-note command

Robert J. Macomber gsharp at rojoma.com
Mon Nov 14 23:01:25 UTC 2005


Here's the command I (as Thas) talked about on #lisp today, to remove
the current note from the current cluster.  Once the note's removed,
the current one becomes the next-lower remaining note, or if the
removed note was the lowest, the next-higher one, or otherwise the
cluster is empty and is removed.  This may be too complex (easier just
to make the lowest note the new current, for example) but it fits my
usage pattern for music typesetting software, which in the past has
been "build chords lowest to highest", so this command acts like
backspace for chords.

I'm not sure LOWER-BOUND is in a good place - maybe it should live in
utilities.lisp?

The command's not bound to anything as I'm not yet comfortable enough
with G#'s keymapping to have a good idea where it'd fit in with
existing keystrokes.

Index: buffer.lisp
===================================================================
RCS file: /project/gsharp/cvsroot/gsharp/buffer.lisp,v
retrieving revision 1.25
diff -r1.25 buffer.lisp
354a355,372
> (defun lower-bound (bound list &key (test #'<))
>   "Return the `largest' element in the sorted list LIST such that
> \(TEST element BOUND) is true."
>   (let ((last nil))
>     (dolist (item list)
>       (unless (funcall test item bound)
>         (return-from lower-bound last))
>       (setf last item))
>     last))
> 
> (defmethod cluster-lower-bound ((cluster cluster) (bound note))
>   (with-slots (notes) cluster
>     (lower-bound bound notes :test #'note-less)))
> 
> (defmethod cluster-upper-bound ((cluster cluster) (bound note))
>   (with-slots (notes) cluster
>     (lower-bound bound (reverse notes) :test (complement #'note-less))))
> 
Index: gui.lisp
===================================================================
RCS file: /project/gsharp/cvsroot/gsharp/gui.lisp,v
retrieving revision 1.43
diff -r1.43 gui.lisp
814a815,827
> (define-gsharp-command com-remove-current-note ()
>   (let ((cluster (cur-cluster))
>         (note (cur-note)))
>     (when note
>       (remove-note note)
>       ;; try to set current-note to the highest note lower than the
>       ;; removed note.  If that fails, to the lowest note higher than
>       ;; it.
>       (setf *current-note* (or (cluster-lower-bound cluster note)
>                                (cluster-upper-bound cluster note)))
>       (unless *current-note*
>         (com-erase-element)))))
> 
Index: packages.lisp
===================================================================
RCS file: /project/gsharp/cvsroot/gsharp/packages.lisp,v
retrieving revision 1.27
diff -r1.27 packages.lisp
47a48
>            #:cluster-upper-bound #:cluster-lower-bound



More information about the gsharp-devel mailing list