lilypond-user
[Top][All Lists]
Advanced

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

Re: Scheme for verbatim display of ly:music argument


From: David Kastrup
Subject: Re: Scheme for verbatim display of ly:music argument
Date: Tue, 23 Oct 2012 13:22:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

Robert Schmaus <address@hidden> writes:

> Am 10/22/12 7:42 PM, schrieb David Kastrup:
>> Robert Schmaus <address@hidden> writes:
>>
>>> Dear all,
>>>
>>> I'd like to create a scheme function with one ly:music argument which
>>> does the following: insert the music expression at the current place
>>> and display the source code (ie the argument passed to the function)
>>> verbatim above the respective place in the score.
>>> And I need to use that in a ChordNames context.
>>>
>>> Thus, I'd like to have the following:
>>>
>>> <<
>>>     \new ChordNames {
>>>             \chordmode{  \fn{ c1:7.5+ } \fn{ c1:maj7.9 }  }
>>>     }
>>>>>
>>>
>>> should produce something like
>>>
>>> c1:7.5+    c1:maj7.9
>>> C7(#5)   | Cmaj9
>>>
>>>
>>> Just passing the music expression is easy:
>>>
>>> fn = #(define-music-function (parser location myChord) (ly:music?)
>>>     #{
>>>             $myChord
>>>     #}
>>> )
>>>
>>> Is it possible to add a markup part to display myChord verbatim?
>>
>> Tricky.  You can use \displayLilyMusic (or its Scheme equivalent) for
>> recreating a representation of the input, but it will not in general be
>> the same as your input.
>>
>> Alternatively, you can try harvesting the location argument for reading
>> the actual source file via
>>
>>   -- Function: ly:input-both-locations sip
>>       Return input location in SIP as `(file-name first-line
>>       first-column last-line last-column)'.
>>
>> but this depends on the function argument being in a more or less direct
>> rather than a computed form.
>>
>> Another possibility is to pass a string into the function in the first
>> place and then use it both as a markup string as well as running one of
>> the string-interpreting functions on it for getting interpretation from
>> LilyPond.

> I looked for information on those string-interpreting functions in the
> online docs and found this (at
> http://lilypond.org/doc/v2.15/Documentation/notation/scheme-functions):
>
> ---
> Function: ly:parse-string-expression parser-smob ly-code filename line
> Parse the string ly-code with parser-smob. Return the contained music
> expression. filename and line are optional source indicators.
> ---
>
> That looks about right ... but I have no idea how to use it, and
> cannot find anything about that in the documentation. Where would I
> have to look?

Information for that is thin.  Inside of a music function you would use
(ly:parse-string-expression (ly:parser-clone parser) "c'")
or similar.  You don't have useful filename and line data to supply
(this is for error messages in the implementation of #{ ... #}), and you
need a freshly cloned parser for parsing a string, and you clone from
the parser passed to the music function.

-- 
David Kastrup



reply via email to

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