RE: Notehead color on programmed pitch change
Thankyou David but how is color associated with NoteHead? I hope these ramblings of a gnarled old scheme/Lily tyro can be of general interest I'm guessing that 'tweaks is some sort of switch to open up properties of the current music object. In this case pitch is a property of 'NoteEvent and I'm guessing that color here is just NoteHead colour not NoteStem because NoteStem is not within the NoteEvent including 'pitch. NoteStem color may be available in a tweak of another music object or possibly supplied by another bit of code (engraver??). I do not know how code a tweak for stem color (apart from an override in the Lily .ly file) maybe you can't (anyway I don't want to). Also AFSIU ly:music-property extracts various elements of the current music item (possibly contained in a deeper Lily code), and allows user scheme to extract data from the current music object. ly:music-set-property! does the reverse? This part of my script kindly supplied by Thomas Morley (if (ly:pitch? p) (let ((new-pitch (naturalize-instrument-range p instrument))) (ly:music-set-property! music 'pitch new-pitch) (if (and (not (equal? p new-pitch)) (color? my-color)) (ly:music-set-property! music 'tweaks (acons 'color my-color (ly:music-property music 'tweaks)) In line 3 a pitch is written to the music event it may be the old pitch or a new pitch. In line 4 further action is taken if the pitch has been changed, first the variable my-color (previously defined) is type checked In line 5 'tweaks is inserted into the current music object. lines 6 - 8 are a bit obscure somehow the current color is replaced by my-color but how? Cannot find a definition for acons but it must be a variant of cons (consists) it occurs 8 times in snippets and once in notation and is clearly the way to tweak associating the Lily 'color with the user supplied color my-color. Rather confusingly the format of color has many guises (x11-color 'red), (1 0 0), simply 'red (no pun intended) and notehead colour can also be approached via a grob. The notehead grob must be somehow implied in the (make-music . Various different approaches to Notehead color are evident in the snippet repositry agin not much detailed explanation is to be found. upline = #(let ((m (make-articulation stopped))) (set! (ly:music-property m 'tweaks) (acons 'font-size 3 (acons 'stencil (lambda (grob) (grob-interpret-markup grob (make-draw-line-markup '(0 . 1 (ly:music-property m 'tweaks m) \relative c' { a'4^\upline a( c d')_\upline } which results in (make-music 'RelativeOctaveMusic 'element (make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'articulations (list (make-music 'ArticulationEvent 'direction 1 'tweaks (list (cons (quote font-size) 3) (cons (quote stencil) #procedure #f (grob))) 'articulation-type stopped)) 'duration (ly:make-duration 2) 'pitch (ly:make-pitch 0 5)) (make-music 'NoteEvent 'articulations (list (make-music 'SlurEvent 'span-direction -1)) 'duration (ly:make-duration 2) 'pitch (ly:make-pitch 0 5)) (make-music 'NoteEvent 'pitch (ly:make-pitch 1 0) 'duration (ly:make-duration 2)) (make-music 'NoteEvent 'articulations (list (make-music 'SlurEvent 'span-direction 1) (make-music 'ArticulationEvent 'direction -1 'tweaks (list (cons (quote font-size) 3) (cons (quote stencil) #procedure #f (grob))) 'articulation-type stopped)) 'duration (ly:make-duration 2) 'pitch (ly:make-pitch 2 1) AFAICS tweaks are not documented properly anywhere - some of the possible tweaks are presented without detailed explanation in the notation and snippet manuals - is there another source of information? _ From: David Nalesnik [mailto:david.nales...@gmail.com] Sent: Wednesday, May 27, 2015 5:51 PM To: Peter Gentry Cc: lilypond-user; Thomas Morley Subject: Re: Notehead color on programmed pitch change On Wed, May 27, 2015 at 4:15 AM, Peter Gentry peter.gen...@sunscales.co.uk wrote: [...] (make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'duration (ly:make-duration 0) 'pitch (ly:make-pitch 0 0)) (make-music 'NoteEvent 'tweaks (list (list (quote color) 1.0 0.0 0.0)) [...] Still not sure how to interpret (list (list... But as long as Lily does.:) We're simply creating a nested list: (list (quote color) 1.0 0.0 0.0) == (color 1.0 0.0 0.0) (list (list (quote color) 1.0 0.0 0.0)) == ((color 1.0 0.0 0.0)) By the way, (quote color) is just longhand for 'color Hope that helps, David ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Notehead color on programmed pitch change
On Thu, May 28, 2015 at 6:43 AM, Peter Gentry peter.gen...@sunscales.co.uk wrote: Thankyou David but how is color associated with NoteHead? I hope these ramblings of a gnarled old scheme/Lily tyro can be of general interest I'm guessing that 'tweaks is some sort of switch to open up properties of the current music object. You've seen http://lilypond.org/doc/v2.18/Documentation/notation/the-tweak-command? Any usage of \tweak in the ly file would appear in the 'tweaks list in the music representation. Here, instead of using \tweak in the file, we're achieving the same result by modifying the music representation directly. To see the music representation (basically what LilyPond does to your ly code to make it more digestible) wrap various music expressions in \displayMusic. For example: \displayMusic { \tweak NoteHead.color #red c''4 } Note how the tweak is represented. In this case pitch is a property of 'NoteEvent and I'm guessing that color here is just NoteHead colour not NoteStem because NoteStem is not within the NoteEvent including 'pitch. NoteStem color may be available in a tweak of another music object or possibly supplied by another bit of code (engraver??). I do not know how code a tweak for stem color (apart from an override in the Lily .ly file) maybe you can't (anyway I don't want to). Well, you'd tweak Stem. And once again, \displayMusic will show you what is done with your ly code: \displayMusic { \tweak Stem.color #blue c''4 } Also AFSIU don't know this one :) ly:music-property extracts various elements of the current music item (possibly contained in a deeper Lily code), and allows user scheme to extract data from the current music object. ly:music-set-property! does the reverse? Basically. *This part of my script kindly supplied by Thomas Morley* (if (ly:pitch? p) (let ((new-pitch (naturalize-instrument-range p instrument))) (ly:music-set-property! music 'pitch new-pitch) (if (and (not (equal? p new-pitch)) (color? my-color)) (ly:music-set-property! music 'tweaks (acons 'color my-color (ly:music-property music 'tweaks)) In line 3 a pitch is written to the music event it may be the old pitch or a new pitch. In line 4 further action is taken if the pitch has been changed, first the variable my-color (previously defined) is type checked In line 5 'tweaks is inserted into the current music object. lines 6 - 8 are a bit obscure somehow the current color is replaced by my-color but how? Cannot find a definition for acons but it must be a variant of cons (consists) it occurs 8 times in snippets and once in notation and is clearly the way to tweak associating the Lily 'color with the user supplied color my-color. You have to look to sources specifically devoted to Scheme. http://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Adding-or-Setting-Alist-Entries.html#index-acons-1603 Rather confusingly the format of color has many guises (x11-color 'red), (1 0 0), simply 'red (no pun intended) and notehead colour can also be approached via a grob. The notehead grob must be somehow implied in the (make-music . The NoteHead grob will ultimately be made as a result of processing the NoteEvent. (As will a Stem, any Dots, an Accidental, etc.) Various different approaches to Notehead color are evident in the snippet repositry agin not much detailed explanation is to be found. http://www.lilypond.org/doc/v2.18/Documentation/learning/visibility-and-color-of-objects#the-color-property upline = #(let ((m (make-articulation stopped))) (set! (ly:music-property m 'tweaks) (acons 'font-size 3 (acons 'stencil (lambda (grob) (grob-interpret-markup grob (make-draw-line-markup '(0 . 1 (ly:music-property m 'tweaks m) \relative c' { a'4^\upline a( c d')_\upline } which results in (make-music 'RelativeOctaveMusic 'element (make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'articulations (list (make-music 'ArticulationEvent 'direction 1 'tweaks (list (cons (quote font-size) 3) (cons (quote stencil) #procedure #f (grob))) 'articulation-type stopped)) 'duration (ly:make-duration 2) 'pitch (ly:make-pitch 0 5)) (make-music 'NoteEvent 'articulations (list (make-music 'SlurEvent 'span-direction -1)) 'duration (ly:make-duration 2) 'pitch (ly:make-pitch 0 5)) (make-music 'NoteEvent 'pitch (ly:make-pitch 1 0) 'duration (ly:make-duration 2)) (make-music 'NoteEvent 'articulations (list (make-music 'SlurEvent 'span-direction 1) (make-music 'ArticulationEvent 'direction -1 'tweaks (list (cons (quote font-size) 3) (cons (quote stencil) #procedure #f (grob))) 'articulation-type stopped)) 'duration (ly:make-duration 2) 'pitch (ly:make-pitch 2 1) Please format this--it's really hard to digest. With gmail, Paste as plain text rather than Paste does the trick for me. Maybe there's a similar option with Outlook? AFAICS
Re: Notehead color on programmed pitch change
-Original Message- From: Thomas Morley [mailto:thomasmorle...@gmail.com] Sent: Tuesday, May 26, 2015 5:33 PM To: Peter Gentry Cc: lilypond-user Subject: Re: Subject: Re: Notehead color on programmed pitch change 2015-05-26 18:09 GMT+02:00 Peter Gentry peter.gen...@sunscales.co.uk: Thanks very much for your solution - I'm not yet sure why it works...how does 'tweaks know about notehead color? All very baffling Well, most (every?) music-event may be tweaked. Look at the terminal-output from: \displayMusic { \tweak color #red c''1 } My code adds this tweak to the NoteEvent under certain conditions. Outlook strikes again - try this Well, perhaps you'll have success persuading outlook to keep your formating. If not I'd look out for another mail-program ;) Cheers, Harm Thanks for the pointer... I tried this { c'1 \tweak color #red c''1 } And the log gives (make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'duration (ly:make-duration 0) 'pitch (ly:make-pitch 0 0)) (make-music 'NoteEvent 'tweaks (list (list (quote color) 1.0 0.0 0.0)) 'duration (ly:make-duration 0) 'pitch (ly:make-pitch 1 0 Maybe this use of \tweak would be useful to many people - like a door opening. Still not sure how to interpret (list (list... But as long as Lily does.:) Now to experiment with other music properties.. ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Notehead color on programmed pitch change (now \tweak)
-Original Message- From: Peter Gentry [mailto:peter.gen...@sunscales.co.uk] Sent: Wednesday, May 27, 2015 10:16 AM To: 'lilypond-user@gnu.org' Cc: 'Thomas Morley' Subject: Re: Notehead color on programmed pitch change -Original Message- From: Thomas Morley [mailto:thomasmorle...@gmail.com] Sent: Tuesday, May 26, 2015 5:33 PM To: Peter Gentry Cc: lilypond-user Subject: Re: Subject: Re: Notehead color on programmed pitch change 2015-05-26 18:09 GMT+02:00 Peter Gentry peter.gen...@sunscales.co.uk: Thanks very much for your solution - I'm not yet sure why it works...how does 'tweaks know about notehead color? All very baffling Well, most (every?) music-event may be tweaked. Look at the terminal-output from: \displayMusic { \tweak color #red c''1 } My code adds this tweak to the NoteEvent under certain conditions. Outlook strikes again - try this Well, perhaps you'll have success persuading outlook to keep your formating. If not I'd look out for another mail-program ;) Cheers, Harm Thanks for the pointer... I tried this { c'1 \tweak color #red c''1 } And the log gives (make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'duration (ly:make-duration 0) 'pitch (ly:make-pitch 0 0)) (make-music 'NoteEvent 'tweaks (list (list (quote color) 1.0 0.0 0.0)) 'duration (ly:make-duration 0) 'pitch (ly:make-pitch 1 0 Maybe this use of \tweak would be useful to many people - like a door opening. Still not sure how to interpret (list (list... But as long as Lily does.:) Now to experiment with other music properties.. Further to this it seems the effect of this tweak is rather odd. The color of the following note head is changed but the note stem is also thinner and this effect carries over to the next notes and indeed the number of notes affected varies see \version 2.19.15 \displayMusic \relative { c'4 c4 c4 c4 \tweak color #red c''4 c4 c4 c4 } The plot thickens. ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
RE: Notehead color on programmed pitch change (now \tweak)
-Original Message- From: Phil Holmes [mailto:m...@philholmes.net] Sent: Wednesday, May 27, 2015 11:49 AM To: Peter Gentry; lilypond-user@gnu.org Cc: 'Thomas Morley' Subject: Re: Notehead color on programmed pitch change (now \tweak) - Original Message - From: Peter Gentry peter.gen...@sunscales.co.uk To: lilypond-user@gnu.org Cc: 'Thomas Morley' thomasmorle...@gmail.com Sent: Wednesday, May 27, 2015 10:27 AM Subject: Re: Notehead color on programmed pitch change (now \tweak) Further to this it seems the effect of this tweak is rather odd. The color of the following note head is changed but the note stem is also thinner and this effect carries over to the next notes and indeed the number of notes affected varies see I think you'll find that this is nothing to do with tweak: it's either the way your PDF viewer rasterises the stems where the notehead is above the stave, or an optical illusion. Rasterising them at 1200 dpi and overlaying the stems in a image manipulating program showed them to be all identical. -- Phil Holmes Yes it is noting to do with tweak it arises from using the magnifier in the Frecobaldi output window - this can produce apparent variations in note stem width. They are an artefact and do not affect the printed output. Case closed. ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Notehead color on programmed pitch change
On Wed, May 27, 2015 at 4:15 AM, Peter Gentry peter.gen...@sunscales.co.uk wrote: [...] (make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'duration (ly:make-duration 0) 'pitch (ly:make-pitch 0 0)) (make-music 'NoteEvent 'tweaks (list (list (quote color) 1.0 0.0 0.0)) [...] Still not sure how to interpret (list (list... But as long as Lily does.:) We're simply creating a nested list: (list (quote color) 1.0 0.0 0.0) == (color 1.0 0.0 0.0) (list (list (quote color) 1.0 0.0 0.0)) == ((color 1.0 0.0 0.0)) By the way, (quote color) is just longhand for 'color Hope that helps, David ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Notehead color on programmed pitch change
Thanks very much for your solution - I'm not yet sure why it works...how does 'tweaks know about notehead color? All very baffling 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \version 2.19.15 #(define (naturalize-instrument-range p instrument ) (let ((o (ly:pitch-octave p)) (a (* 4 (ly:pitch-alteration p))) ;; alteration, a, in quarter tone steps, ;; for historical reasons (n (ly:pitch-notename p))) (cond ((equal? instrument clarinet ) (if (= o -1) (begin (set! o -1 ))) (if (= o 3) (begin (set! o 2 ))) (cond ( (and (= o -1) (= a 2) (= n 1)) (set! o 0)) ( (and (= o 2) (n 3))(set! o 1)) ( (and (= o 2) (= n 3))(set! o 2)) ) (if ( o 2) (begin (set! o 2 ((equal? instrument flute) (if ( o 0) (begin (set! o 0 ))) (cond ( (and (= o 0) ( a 0) (= n 0)) (set! o 1)) ( (and (= o 2) ( n 3)) (set! o 1)) ( (and (= o 2) (= n 3)) (set! o 2)) ) (if ( o 2) (begin (set! o 2 ) (ly:make-pitch o n (/ a 4)) )) my-color = #(x11-color 'red) #(define (instrumentrange music instrument ) ( ly:music? string? ) (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (if (pair? es) (ly:music-set-property! music 'elements (map (lambda (x) (instrumentrange x instrument)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (instrumentrange e instrument ))) (if (ly:pitch? p) (let ((new-pitch (naturalize-instrument-range p instrument))) (ly:music-set-property! music 'pitch new-pitch) (if (and (not (equal? p new-pitch)) (color? my-color)) (ly:music-set-property! music 'tweaks (acons 'color my-color (ly:music-property music 'tweaks)) music)) naturalizeInstrumentRange = #(define-music-function (parser location instrument m ) ( string? ly:music? ) (instrumentrange m instrument )) \score { \new Staff \naturalizeInstrumentRange clarinet \relative c'' { d4 r16 d,,16 [ e'16 f16 ] e8 [ a,8 ] a''16 [ g'16 a16 e16 ] | % 4 f8 [ d8 ] r4 r2 | % 5 } } \score { \new Staff \relative c'' { d4 r16 d,,16 [ e'16 f16 ] e8 [ a,8 ] a''16 [ g'16 a16 e16 ] | % 4 f8 [ d8 ] r4 r2 | % 5 }} regards Peter Gentry ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Subject: Re: Notehead color on programmed pitch change
2015-05-26 18:09 GMT+02:00 Peter Gentry peter.gen...@sunscales.co.uk: Thanks very much for your solution - I'm not yet sure why it works...how does 'tweaks know about notehead color? All very baffling Well, most (every?) music-event may be tweaked. Look at the terminal-output from: \displayMusic { \tweak color #red c''1 } My code adds this tweak to the NoteEvent under certain conditions. Outlook strikes again - try this Well, perhaps you'll have success persuading outlook to keep your formating. If not I'd look out for another mail-program ;) Cheers, Harm ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Subject: Re: Notehead color on programmed pitch change
Thanks very much for your solution - I'm not yet sure why it works...how does 'tweaks know about notehead color? All very baffling Outlook strikes again - try this \version 2.19.15 #(define (naturalize-instrument-range p instrument ) (let ((o (ly:pitch-octave p)) (a (* 4 (ly:pitch-alteration p))) ;; alteration, a, in quarter tone steps, ;; for historical reasons (n (ly:pitch-notename p))) (cond ((equal? instrument clarinet ) (if (= o -1) (begin (set! o -1 ))) (if (= o 3) (begin (set! o 2 ))) (cond ( (and (= o -1) (= a 2) (= n 1)) (set! o 0)) ( (and (= o 2) (n 3))(set! o 1)) ( (and (= o 2) (= n 3))(set! o 2)) ) (if ( o 2) (begin (set! o 2 ((equal? instrument flute) (if ( o 0) (begin (set! o 0 ))) (cond ( (and (= o 0) ( a 0) (= n 0)) (set! o 1)) ( (and (= o 2) ( n 3)) (set! o 1)) ( (and (= o 2) (= n 3)) (set! o 2)) ) (if ( o 2) (begin (set! o 2 ) (ly:make-pitch o n (/ a 4)) )) my-color = #(x11-color 'red) #(define (instrumentrange music instrument ) ( ly:music? string? ) (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (if (pair? es) (ly:music-set-property! music 'elements (map (lambda (x) (instrumentrange x instrument)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (instrumentrange e instrument ))) (if (ly:pitch? p) (let ((new-pitch (naturalize-instrument-range p instrument))) (ly:music-set-property! music 'pitch new-pitch) (if (and (not (equal? p new-pitch)) (color? my-color)) (ly:music-set-property! music 'tweaks (acons 'color my-color (ly:music-property music 'tweaks)) music)) naturalizeInstrumentRange = #(define-music-function (parser location instrument m ) ( string? ly:music? ) (instrumentrange m instrument )) \score { \new Staff \naturalizeInstrumentRange clarinet \relative c'' { d4 r16 d,,16 [ e'16 f16 ] e8 [ a,8 ] a''16 [ g'16 a16 e16 ] | % 4 f8 [ d8 ] r4 r2 | % 5 } } \score { \new Staff \relative c'' { d4 r16 d,,16 [ e'16 f16 ] e8 [ a,8 ] a''16 [ g'16 a16 e16 ] | % 4 f8 [ d8 ] r4 r2 | % 5 }} regards Peter Gentry ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Notehead color on programmed pitch change
Hi Peter, 2015-05-25 13:20 GMT+02:00 Peter Gentry peter.gen...@sunscales.co.uk: I have a short script to confine music to an instruments range. I wish to colour the noteheads on any pitches which have been changed to fit the instrument range. Try as I may all attempts to modify existing snippets have failed - I was particulary baffled by the snippet No idea about this code is supposed to do: #(define (pitch-to-color pitch) (let ((color (assoc pitch colo-mapping pitch-equals?))) (if color (cdr color))) which in the abscence of a need for color-mapping I couldn't replace with (color (x11-color 'red)) The above is not in the script as all attempts just failed - can anyone help please. All formating, indentation you may have done is gone in your mail. Please make sure it is kept. It's very hard to read ... \version 2.19.15 #(define (naturalize-instrument-range p instrument) (let ((o (ly:pitch-octave p)) (a (* 4 (ly:pitch-alteration p))) ;; alteration, a, in quarter tone steps, ;; for historical reasons (n (ly:pitch-notename p))) (define oct1 o) (cond ((equal? instrument clarinet ) (if (= o -1) (begin (set! o -1 ))) (if (= o 3) (begin (set! o 2 ))) (cond ( (and (= o -1) (= a 2) (= n 1)) (set! o 0)) ( (and (= o 2) ( n 3)) (set! o 1)) ( (and (= o 2) (= n 3)) (set! o 2)) ) This is done already, delete it: (if ( o 2) (begin (set! o 2 ((equal? instrument flute) (if ( o 0) (begin (set! o 0 ))) (cond ( (and (= o 0) ( a 0) (= n 0)) (set! o 1)) ( (and (= o 2) ( n 3)) (set! o 1)) ( (and (= o 2) (= n 3)) (set! o 2)) ) (if ( o 2) (begin (set! o 2 ) ;; just in for checking (if (or ( oct1 o) ( oct1 o)) (display (string-append oct= (number-string oct1) o= (number-string o) \n))) (ly:make-pitch o n (/ a 4)) )) #(define (instrumentrange music instrument ) no type checking needed nor done here, delete it ( ly:music? number? ) (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (if (pair? es) (ly:music-set-property! music 'elements (map (lambda (x) (instrumentrange x instrument)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (instrumentrange e instrument ))) (if (ly:pitch? p) (begin (set! p (naturalize-instrument-range p instrument)) (ly:music-set-property! music 'pitch p))) music)) naturalizeInstrumentRange = #(define-music-function (parser location instrument m ) ( string? ly:music? ) (instrumentrange m instrument )) \score { \naturalizeInstrumentRange clarinet \new Staff \relative c'' { d4 r16 d,,16 [ e'16 f16 ] e8 [ a,8 ] a'16 [ g'16 a16 e16 ] | % 4 f8 [ d8 ] r4 r2 | % 5 }} regards Peter Gentry How about: \version 2.19.15 #(define (naturalize-instrument-range p instrument) (let ((o (ly:pitch-octave p)) (a (* 4 (ly:pitch-alteration p))) ;; alteration, a, in quarter tone steps, ;; for historical reasons (n (ly:pitch-notename p))) (define oct1 o) (cond ((equal? instrument clarinet) (if (= o -1) (set! o -1)) (if (= o 3) (set! o 2)) (cond ((and (= o -1) (= a 2) (= n 1)) (set! o 0)) ((and (= o 2) ( n 3)) (set! o 1)) ((and (= o 2) (= n 3)) (set! o 2 ((equal? instrument flute) (if ( o 0) (set! o 0 )) (cond ((and (= o 0) ( a 0) (= n 0)) (set! o 1)) ((and (= o 2) ( n 3)) (set! o 1)) ((and (= o 2) (= n 3)) (set! o 2))) (if ( o 2) (set! o 2 ;;; just in for checking ;(if (or ( oct1 o) ( oct1 o)) ;(display ; (string-append ; oct= ;(number-string oct1) ; o= ;(number-string o) ;\n))) (ly:make-pitch o n (/ a 4 my-color = #(x11-color 'red) #(define (instrumentrange music instrument) (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (if (pair? es) (ly:music-set-property! music 'elements (map (lambda (x) (instrumentrange x instrument)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (instrumentrange e instrument ))) (if (ly:pitch? p) (let ((new-pitch (naturalize-instrument-range p instrument))) (ly:music-set-property! music 'pitch new-pitch) (if (and (not (equal? p new-pitch)) (color? my-color)) (ly:music-set-property! music 'tweaks (acons 'color my-color (ly:music-property music 'tweaks)) music)) naturalizeInstrumentRange = #(define-music-function (parser location instrument m)(string? ly:music?) (instrumentrange m instrument)) mus = \relative c'' {
Notehead color on programmed pitch change
I have a short script to confine music to an instruments range. I wish to colour the noteheads on any pitches which have been changed to fit the instrument range. Try as I may all attempts to modify existing snippets have failed - I was particulary baffled by the snippet #(define (pitch-to-color pitch) (let ((color (assoc pitch colo-mapping pitch-equals?))) (if color (cdr color))) which in the abscence of a need for color-mapping I couldn't replace with (color (x11-color 'red)) The above is not in the script as all attempts just failed - can anyone help please. \version 2.19.15 #(define (naturalize-instrument-range p instrument) (let ((o (ly:pitch-octave p)) (a (* 4 (ly:pitch-alteration p))) ;; alteration, a, in quarter tone steps, ;; for historical reasons (n (ly:pitch-notename p))) (define oct1 o) (cond ((equal? instrument clarinet ) (if (= o -1) (begin (set! o -1 ))) (if (= o 3) (begin (set! o 2 ))) (cond ( (and (= o -1) (= a 2) (= n 1)) (set! o 0)) ( (and (= o 2) ( n 3)) (set! o 1)) ( (and (= o 2) (= n 3)) (set! o 2)) ) (if ( o 2) (begin (set! o 2 ((equal? instrument flute) (if ( o 0) (begin (set! o 0 ))) (cond ( (and (= o 0) ( a 0) (= n 0)) (set! o 1)) ( (and (= o 2) ( n 3)) (set! o 1)) ( (and (= o 2) (= n 3)) (set! o 2)) ) (if ( o 2) (begin (set! o 2 ) ;; just in for checking (if (or ( oct1 o) ( oct1 o)) (display (string-append oct= (number-string oct1) o= (number-string o) \n))) (ly:make-pitch o n (/ a 4)) )) #(define (instrumentrange music instrument ) ( ly:music? number? ) (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (if (pair? es) (ly:music-set-property! music 'elements (map (lambda (x) (instrumentrange x instrument)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (instrumentrange e instrument ))) (if (ly:pitch? p) (begin (set! p (naturalize-instrument-range p instrument)) (ly:music-set-property! music 'pitch p))) music)) naturalizeInstrumentRange = #(define-music-function (parser location instrument m ) ( string? ly:music? ) (instrumentrange m instrument )) \score { \naturalizeInstrumentRange clarinet \new Staff \relative c'' { d4 r16 d,,16 [ e'16 f16 ] e8 [ a,8 ] a'16 [ g'16 a16 e16 ] | % 4 f8 [ d8 ] r4 r2 | % 5 }} regards Peter Gentry ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user