Markup and Score from scheme function

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Markup and Score from scheme function

Sebastian Käppler
Hello,

I wonder if it is possible to return markup AND score from a single scheme function, something like this:

example = #(define-scheme-function (parser location) ()
#{
    \markup "Test"
    \score {
       c'4
    }
#}
)

I created some scripts for teaching and want to include task-markup before each score. Using markup and my functions outside of scheme works, but I couldn't get  it to work from a single function.

Kind regards


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Markup and Score from scheme function

Aaron Hill
On 2018-10-11 1:22 am, Sebastian Käppler wrote:

> Hello,
>
> I wonder if it is possible to return markup AND score from a single
> scheme
> function, something like this:
>
> example = #(define-scheme-function (parser location) ()
> #{
>     \markup "Test"
>     \score {
>        c'4
>     }
> #}
> )
>
> I created some scripts for teaching and want to include task-markup
> before
> each score. Using markup and my functions outside of scheme works, but
> I
> couldn't get  it to work from a single function.

Seems to be that the parser cannot figure out what is meant by #{
\markup ... \score ... #} even though both of those items are permitted
to appear at the top-level.  With #{ \markup ... #} or #{ \score ... #},
the parser appears to do the right thing.

While there is probably some clever trick that permits #{ \markup ...
\score ... #} to parse correctly, I am not seeing it.  So, here are two
potential options: either nest the score within the markup or vice
versa:

%%%%
\version "2.19.82"

\markup "Hello, World!" \score { { a'4 b' g'2 } }

scoreInsideMarkup =
   #(define-scheme-function (label notes) (string? ly:music?)
     #{ \markup { \column { $label \score { $notes } } } #})

markupInsideScore =
   #(define-scheme-function (label notes) (string? ly:music?)
     #{ \score { { \tweak X-offset #(/ -15 1.7573)
        \mark \markup \fontsize #-2 $label $notes } } #})

\scoreInsideMarkup "Hello, World!" { a'4 b' g'2 }
\markupInsideScore "Hello, World!" { a'4 b' g'2 }
%%%%

Note that when using a RehearsalMark, a suitable adjustment to the
alignment and font size is needed to match the appearance of the other
two.


-- Aaron Hill

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Markup and Score from scheme function

Jan-Peter Voigt
In reply to this post by Sebastian Käppler
Hello Sebastian,

what do you mean with "return"? Do want to add the score immediatly or
do you want to return an object containing both?
You used the parser-location arguments in your scheme-function, so I
guess you are using stable (2.18). I created an example for 2.18
(incomplete) and one for 2.19.82. For three possible functions.

HTH
Jan-Peter


Am 11.10.2018 um 10:22 schrieb Sebastian Käppler:

> Hello,
>
> I wonder if it is possible to return markup AND score from a single
> scheme function, something like this:
>
> example = #(define-scheme-function (parser location) ()
> #{
>     \markup "Test"
>     \score {
>        c'4
>     }
> #}
> )
>
> I created some scripts for teaching and want to include task-markup
> before each score. Using markup and my functions outside of scheme
> works, but I couldn't get  it to work from a single function.
>
> Kind regards
>
>
>
> _______________________________________________
> lilypond-user mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/lilypond-user
>

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

add-markup-and-score.ly (1018 bytes) Download Attachment
add-markup-and-score-2.18.ly (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Markup and Score from scheme function

Sebastian Käppler
Thanks for your help, I found the add-score function to work in the way I want it to. Never stumbled across it in the documentation, though...

Jan-Peter, I want to add both the markup and the score immediately.

Another question, is it possible to determine inside the function if it is called from a score context, that means to distinguish these two cases:

A:
\score {
 \myfunction
}

B:
\myfunction

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Markup and Score from scheme function

Thomas Morley-2
In reply to this post by Jan-Peter Voigt
Am Fr., 12. Okt. 2018 um 08:10 Uhr schrieb Jan-Peter Voigt <[hidden email]>:

>
> Hello Sebastian,
>
> what do you mean with "return"? Do want to add the score immediatly or
> do you want to return an object containing both?
> You used the parser-location arguments in your scheme-function, so I
> guess you are using stable (2.18). I created an example for 2.18
> (incomplete) and one for 2.19.82. For three possible functions.
>
> HTH
> Jan-Peter

Hi,

for immediate addings, why not the simpler:

example =
#(define-void-function (mrkp scr) (markup? ly:score?)
  (add-text mrkp)
  (add-score scr))

\example
 \markup \bold "Test"
 \score { c'4 }

\example
 \markup \italic "Test"
 \score { cis'4 }

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Markup and Score from scheme function

Sebastian Käppler
Add-text is even better. Still curious if it's possible to get the "context" inside the function. Isn't that what the location parameter is for?

Thomas Morley <[hidden email]> schrieb am Fr., 12. Okt. 2018, 10:29:
Am Fr., 12. Okt. 2018 um 08:10 Uhr schrieb Jan-Peter Voigt <[hidden email]>:
>
> Hello Sebastian,
>
> what do you mean with "return"? Do want to add the score immediatly or
> do you want to return an object containing both?
> You used the parser-location arguments in your scheme-function, so I
> guess you are using stable (2.18). I created an example for 2.18
> (incomplete) and one for 2.19.82. For three possible functions.
>
> HTH
> Jan-Peter

Hi,

for immediate addings, why not the simpler:

example =
#(define-void-function (mrkp scr) (markup? ly:score?)
  (add-text mrkp)
  (add-score scr))

\example
 \markup \bold "Test"
 \score { c'4 }

\example
 \markup \italic "Test"
 \score { cis'4 }

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Markup and Score from scheme function

Sebastian Käppler
Finally, I found that the given answers satisfy all my needs as of now. Thank you very much!

Sebastian Käppler <[hidden email]> schrieb am Sa., 13. Okt. 2018, 09:26:
Add-text is even better. Still curious if it's possible to get the "context" inside the function. Isn't that what the location parameter is for?

Thomas Morley <[hidden email]> schrieb am Fr., 12. Okt. 2018, 10:29:
Am Fr., 12. Okt. 2018 um 08:10 Uhr schrieb Jan-Peter Voigt <[hidden email]>:
>
> Hello Sebastian,
>
> what do you mean with "return"? Do want to add the score immediatly or
> do you want to return an object containing both?
> You used the parser-location arguments in your scheme-function, so I
> guess you are using stable (2.18). I created an example for 2.18
> (incomplete) and one for 2.19.82. For three possible functions.
>
> HTH
> Jan-Peter

Hi,

for immediate addings, why not the simpler:

example =
#(define-void-function (mrkp scr) (markup? ly:score?)
  (add-text mrkp)
  (add-score scr))

\example
 \markup \bold "Test"
 \score { c'4 }

\example
 \markup \italic "Test"
 \score { cis'4 }

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Markup and Score from scheme function

Thomas Morley-2
Am So., 14. Okt. 2018 um 12:57 Uhr schrieb Sebastian Käppler
<[hidden email]>:
>
> Finally, I found that the given answers satisfy all my needs as of now. Thank you very much!

Glad you like it.

>
> Sebastian Käppler <[hidden email]> schrieb am Sa., 13. Okt. 2018, 09:26:
>>
>> Add-text is even better.

Well, 'add-text' is shorter. It's defined as (add-score (list text)), though.

>> Still curious if it's possible to get the "context" inside the function.

No.
Furthermore, my function is void-function, i.e. it _returns_ nothing!
Ofcourse it _does_ something. In this case text and score are added to
the current bookpart, book or toplevel

>> Isn't that what the location parameter is for?

Nope, it makes point-and-click work.
it's meant to point to a location in your input file. But you can
watch what it does.
See:
\version "2.19.82"

foo = #(define-void-function ()() (write (*location*)))

{ R1 \foo R1 }

In my case it display in terminal:
#<location atest-80.ly:890:6>
i.e. a certain line and column

Cheers,
  Harm

>> Thomas Morley <[hidden email]> schrieb am Fr., 12. Okt. 2018, 10:29:
>>>
>>> Am Fr., 12. Okt. 2018 um 08:10 Uhr schrieb Jan-Peter Voigt <[hidden email]>:
>>> >
>>> > Hello Sebastian,
>>> >
>>> > what do you mean with "return"? Do want to add the score immediatly or
>>> > do you want to return an object containing both?
>>> > You used the parser-location arguments in your scheme-function, so I
>>> > guess you are using stable (2.18). I created an example for 2.18
>>> > (incomplete) and one for 2.19.82. For three possible functions.
>>> >
>>> > HTH
>>> > Jan-Peter
>>>
>>> Hi,
>>>
>>> for immediate addings, why not the simpler:
>>>
>>> example =
>>> #(define-void-function (mrkp scr) (markup? ly:score?)
>>>   (add-text mrkp)
>>>   (add-score scr))
>>>
>>> \example
>>>  \markup \bold "Test"
>>>  \score { c'4 }
>>>
>>> \example
>>>  \markup \italic "Test"
>>>  \score { cis'4 }
>>>
>>> Cheers,
>>>   Harm
>>>
>>> _______________________________________________
>>> lilypond-user mailing list
>>> [hidden email]
>>> https://lists.gnu.org/mailman/listinfo/lilypond-user
>
> _______________________________________________
> lilypond-user mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/lilypond-user

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user