lilypond-user
[Top][All Lists]
Advanced

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

Print "pizz." only once until "ord."


From: Pine, Zachary V
Subject: Print "pizz." only once until "ord."
Date: Fri, 29 Jan 2021 06:36:20 +0000

Hello All,

"pizz." is usually marked above a score only once. Performers presume all subsequent music is pizzicato until "ord." appears. 

I'm looking to write scheme functions \pizz and \ord with this behavior. \pizz should only print the first time it is called and then do nothing until after \ord is called. \ord should behave the same way, only printing once in a row.

I attempted to hack up a solution but couldn't get the markup to print!

\version "2.20.0"

pizz-list = #'()

add-pizz-list = #(define-scheme-function
	(cont bool)
	(ly:context? boolean?)
	(set! pizz-list (cons (cons (ly:context-id cont) bool) pizz-list)))

flip-pizz-list = #(define-scheme-function
	(cont)
	(ly:context?)
	(if (not (apply (lambda (a b) (or a b)) 
		            (map (lambda (x) (let ((condition (equal? (car x) (ly:context-id cont))))
	                                      (if condition (set-cdr! x (not (cdr x))))
						                  condition)) pizz-list) (list #f)))
        (add-pizz-list cont #f))
	)

#(define* (pizz? cont #:optional (list pizz-list))
	(let ((name (ly:context-id cont)))
	    (cond ((or (not (list? list)) (null? list)) #f)
	          ((and (equal? name (car (car list))) (cdr (car list))) #t)
	          (else (pizz? cont (cdr list))))))



pizz-scheme = #(define-music-function
	(cont)
	(ly:context?)
	(if (not (pizz? cont))
		(begin (flip-pizz-list cont)
			#{ ^\markup \italic "pizz." #})
		#{ #}))

pizz = \applyContext #(lambda (x) (pizz-scheme x))

ord-scheme = #(define-music-function
	(cont)
	(ly:context?)
	(if (pizz? cont)
		(begin (flip-pizz-list cont)
			#{ ^\markup \italic "ord." #})
		#{ #}))

ord = \applyContext #(lambda (x) (ord-scheme x))

\score {
	<<
		\new Staff = "cl" {
			\applyContext #(lambda (x) (add-pizz-list x #t))
			c1 \pizz
			c1 \pizz
			c1 \ord
			c1 \ord
		}
	>>
}
​Any easy fixes to my attempt here? I'm also open to taking a different approach if there's a more idiomatic lilypond angle.
Best,
Zach

reply via email to

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