Jump to content

Integrating LilyPond expressions inside Scheme functions: Difference between revisions

From LilyPond wiki
Import snippet from LSR
 
m New category
Tags: Mobile edit Mobile web edit
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
It is possible to use fragments of LilyPond syntax inside Scheme, by putting them between #{ and #}. In this example, three functions are defined to apply different paddings on the TextScript markups, using native LilyPond commands such as <code>\override TextScript #'padding</code>.
It is possible to use fragments of LilyPond syntax inside Scheme, by putting them between #{ and #}. In this example, three functions are defined to apply different paddings on the TextScript markups, using native LilyPond commands such as <code>\override TextScript #'padding</code>.


<lilypond version="2.24.0">
<lilypond version="2.24">
%% http://lsr.di.unimi.it/LSR/Item?id=251
%% http://lsr.di.unimi.it/LSR/Item?id=251


Line 37: Line 37:
[[Category:Syntax and expressions]]
[[Category:Syntax and expressions]]
[[Category:Really simple]]
[[Category:Really simple]]
[[Category:Snippet]]

Latest revision as of 23:37, 21 November 2025

It is possible to use fragments of LilyPond syntax inside Scheme, by putting them between #{ and #}. In this example, three functions are defined to apply different paddings on the TextScript markups, using native LilyPond commands such as \override TextScript #'padding.

\version "2.24"

%% http://lsr.di.unimi.it/LSR/Item?id=251

withPaddingA = #(define-music-function (padding music) (number? ly:music?)
		 #{ \override TextScript.padding = #padding
		 $music 
		 \revert TextScript.padding #})

withPaddingB = #(define-music-function (padding music) (number? ly:music?)
		 #{ \override TextScript.padding = #(* padding 2)
		 $music 
		 \revert TextScript.padding #})

withPaddingC = #(define-music-function (padding music) (number? ly:music?)
		 #{ \override TextScript.padding = #(+ 1 (* padding 2))
		    $music 
		    \revert TextScript.padding #})

{
  c'^"1"
  \withPaddingA #2
  { c'^"2" c'^"3" }
  c'^"4"
  \withPaddingB #2
  { c'^"5" c'^"6" }
  c'^"7"
  \withPaddingC #2
  { c'^"8" c'^"9" }
  c'^"10"
}