[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passing a Context to a scheme function (format-metronome-markup)

From: Reinhold Kainhofer
Subject: Re: passing a Context to a scheme function (format-metronome-markup)
Date: Tue, 7 Oct 2008 19:12:16 +0200
User-agent: KMail/1.9.10

Hash: SHA1

Am Dienstag, 7. Oktober 2008 schrieb Reinhold Kainhofer:
> Am Dienstag, 7. Oktober 2008 schrieb Han-Wen Nienhuys:
> > You can't do this; the format-metronome-markup is run during
> > interpreting, from Metronome_mark_engraver, which will pass the
> > context object by doing context()->self_scm() in C++.
> Actually, as Graham noticed, there is only one spot where the context is
> used, namely to obtain the tempoHideNote property, which Graham doesn't
> need anyway.
> A quick hack would be to simply pass some random context to the function
> and hope that things work out. For example, one can pass the default paper
> block (nothing special about that block, but it was the first thing that
> came to my mind, since we already had something similar with extracting the
> papersize names):

A much cleaner way would be to change the format-metronome-markup function to 
make the context argument optional. If it is not given, simply default to #f 
for hide-note:

(define-public (format-metronome-markup text dur count . context)
  (let* ((ctx (and (pair? context) (car context)))
         (hide-note (and ctx (eq? #t (ly:context-property 
ctx 'tempoHideNote))))
         (note-mark (if (and (not hide-note) (ly:duration? dur))

I don't know how useful this might be in general, but since it's such an easy 
feature (and I don't think it breaks anything), I prepared a patch:

What do you think?

One can then simply call 

\version "2.11.62"
  piece = #(format-metronome-markup "Allegro" (ly:make-duration 2) 120)
\relative c' { c }

- -- 
- ------------------------------------------------------------------
Reinhold Kainhofer, Vienna University of Technology, Austria
email: address@hidden,
 * Financial and Actuarial Mathematics, TU Wien,
 * K Desktop Environment,, KOrganizer maintainer
 * Chorvereinigung "Jung-Wien",
Version: GnuPG v1.4.6 (GNU/Linux)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]