[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Pasting together markup expressions
From: |
David Kastrup |
Subject: |
Re: Pasting together markup expressions |
Date: |
Sat, 17 Oct 2009 18:19:12 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
David Kastrup <address@hidden> writes:
> Ok, the following somewhat naive approach which treats music and markup
> expressions sort of like cut&pasteable strings falls apart horribly.
>
> How do I do this sort of thing properly?
>
> The goal is to be able to write something like
>
> \Discant #130
>
> and get an accordion discant symbol with 1 dot at the top, 3 in the
> middle, and none in the bottom. There is a slight twist where the
> digits 4 5 6 7 in the middle place deliver asymmetric one- and two-dot
> patterns (those are sometimes used to indicate different configurations
> on special instruments). But that just pertains to the right-dot
> formula and is not really relevant for the problem.
>
> discant = \markup {
> \musicglyph #"accordion.accDiscant"
> }
> dot = \markup {
> \musicglyph #"accordion.accDot"
> }
> Discant = #(define-music-function (parser location code) (number?)
> (let* ((piccolo (if (zero? (modulo code 100)) #{ #}
> #{ \combine \raise #2.5 \dot #}))
> (left (if (even? (quotient code 20)) #{ #}
> #{ \combine \translate #'(-1 . 0) \raise #1.5 \dot #}))
> (middle (if (even? (quotient code 10)) #{ #}
> #{ \combine \raise #1.5 \dot #}))
> (right (if (eq? (even? (quotient code 20))
> (even? (quotient code 40))) #{ #}
> #{ \combine \translate #'(1 . 0) \raise #1.5 \dot #}))
> (bass (if (even? code) #{ #}
> #{ \combine \raise #0.5 \dot #})))
> #{ ^\markup { $piccolo $left $middle $right $bass discant } #}))
>
> \layout { ragged-right = ##t }
>
> \score { \relative c' { c\Discant #131 d \Discant #11 }}
Hm. I have no clue what I am actually doing here, but this ended up as
the following.
\version "2.13.6"
discant = \markup {
\musicglyph #"accordion.accDiscant"
}
dot = \markup {
\musicglyph #"accordion.accDot"
}
nodot = \markup { }
#(define-markup-command (Discant layout props code) (number?)
(interpret-markup layout props
(markup #:combine #:musicglyph "accordion.accDiscant"
#:combine #:raise 2.5
(if (odd? (quotient code 100)) dot nodot)
#:combine #:raise 1.5
#:combine #:translate '(-1 . 0)
(if (odd? (quotient (remainder code 100) 20)) dot nodot)
#:combine (if (odd? (quotient code 10)) dot nodot)
#:translate '(1 . 0)
(if (eq? (odd? (quotient (remainder code 100) 20))
(even? (quotient (remainder code 100) 40))) dot nodot)
#:raise 0.5 (if (odd? code) dot nodot))))
\layout { ragged-right = ##t }
\score { \relative c' { c^\markup { \Discant #121 } d^\markup { \Discant #11 }
e }}
--
David Kastrup