lilypond-user
[Top][All Lists]
Advanced

[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 17:32:19 +0200
User-agent: KMail/1.9.10

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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):

\version "2.11.62"
\header{
  piece = #(format-metronome-markup "Allegro" 
             (ly:make-duration 2) 120 
             (ly:make-global-context (eval '$defaultpaper (current-module))))
}
\relative c' { c }

This works without an error message and produces the desired result. I don't 
know how one can create an empty context, which would be nicer than the ugly 
hack of misusing some unrelated context.

How did I arrive at the above hack? Since the last argument of the 
format-metronome-markup is a context, I searched the code for lines 
with "make"/"create"/"generate" and "context" and found 
ly:make-global-context. Since that needs an Output_def, one only needs to get 
some Output_def (i.e. a paper block or something similar).

Note, however, that the second argument needs to be a duration rather than an 
integer, so one has to call ly:make-duration (where the argument is 
the -log_2 of the duration, i.e. 2 means a quarter, 3 an eighth, etc.)

Sample file is attached.

Cheers,
Reinhold

- -- 
- ------------------------------------------------------------------
Reinhold Kainhofer, Vienna University of Technology, Austria
email: address@hidden, http://reinhold.kainhofer.com/
 * Financial and Actuarial Mathematics, TU Wien, http://www.fam.tuwien.ac.at/
 * K Desktop Environment, http://www.kde.org, KOrganizer maintainer
 * Chorvereinigung "Jung-Wien", http://www.jung-wien.at/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFI64EJTqjEwhXvPN0RAlAPAJ47vbvRpzBQuQ6GBgsUmypitVBOpgCeIjp+
Lw+nSDGuYQyCd4PPccPN20E=
=pm5G
-----END PGP SIGNATURE-----

Attachment: graham_metronome_mark_outside.ly
Description: Text Data

Attachment: graham_metronome_mark_outside.pdf
Description: Adobe PDF document


reply via email to

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