[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Coloring adjacent notes by interval
From: |
Michael Käppler |
Subject: |
Re: Coloring adjacent notes by interval |
Date: |
Thu, 5 Dec 2019 10:41:52 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 |
Thanks David,
at the bottom is what I got so far.
Two problems I could not tackle so far:
1. I would like the engraver to be usable in two modes of operation:
A. acknowledging grobs from the note-head-engraver, coloring them
B. directly listening to note-events, output some kind of text, graphviz
output etc.
even when there is no note-head-engraver present in the context.
Is it somehow possible to merge these two approaches into one engraver?
The only
possibility I can think of at this moment is to use the
listener-approach and
to override and revert NoteHead.color as a context property.
Would this be the right way to go?
2. At this moment the engraver colors only the second note of the
interval found.
I would like to color also the first note, this would however require
some kind of lookahead
because when the engraver acknowledges the first NoteHead grob it does
not know which
step will follow.
Any advice is kindly appreciated.
Michael
%%%%%%%%%%%%%%%%%%%
\version "2.19.21"
% Interval definitions
% Number determines the interval type, 1=prime, 2=second, 3=third ...
% plus and minus signs determine variant, no sign=perfect interval,
+=major ++=augmented
% -=minor, --=diminished
% This list may be extended or completely overwritten
% Usage: #(display (assoc-get "4--" intervaldefs))
#(define intervaldefs
'(("1++" . (0 . 1))
("1" . (0 . 0))
("2-" . (1 . 1))
("2--" . (1 . 0))
("2+" . (1 . 2))
("2++" . (1 . 3))
("3-" . (2 . 3))
("3--" . (2 . 2))
("3+" . (2 . 4))
("3++" . (2 . 5))
("4--" . (3 . 4))
("4++" . (3 . 6))
("4" . (3 . 5))
("5--" . (4 . 6))
("5++" . (4 . 8))
("5" . (4 . 7))
("6-" . (5 . 8))
("6--" . (5 . 7))
("6+" . (5 . 9))
("6++" . (5 . 10))
("7-" . (6 . 10))
("7--" . (6 . 9))
("7+" . (6 . 11))
("7++" . (6 . 12))
("8--" . (7 . 11))
("8++" . (7 . 13))
("8" . (7 . 12))
("9-" . (8 . 13))
("9--" . (8 . 12))
("9+" . (8 . 14))
("9++" . (8 . 15))
("10-" . (9 . 15))
("10--" . (9 . 14))
("10+" . (9 . 16))
("10++" . (9 . 17))
("11--" . (10 . 16))
("11++" . (10 . 18))
("11" . (10 . 17))
("12--" . (11 . 18))
("12" . (11 . 19))))
interval-color-engraver = #(define-scheme-function (interval
intervaldefs color)
(string? list? color?)
(lambda (context)
(let ((last-pitch #f))
(make-engraver
(acknowledgers
((note-head-interface engraver grob
source-engraver)
(let* ((current-pitch
(ly:event-property (ly:grob-property grob 'cause) 'pitch))
(current-interval-dt-st (if
last-pitch
(cons
(- (ly:pitch-steps current-pitch)
(ly:pitch-steps last-pitch))
(- (ly:pitch-semitones current-pitch)
(ly:pitch-semitones last-pitch)))
(cons #f #f)))
(given-interval-dt-st
(assoc-get interval intervaldefs))
(color-grob? (equal?
current-interval-dt-st given-interval-dt-st)))
(format (current-error-port)
"Previous pitch: ~a\n" last-pitch)
(format (current-error-port)
"Current pitch: ~a\n" current-pitch)
(format (current-error-port)
"Diatonic diff: ~a\n" (car current-interval-dt-st))
(format (current-error-port)
"Semitonic diff: ~a\n" (cdr current-interval-dt-st))
(format (current-error-port)
"Color grob?: ~a\n" color-grob?)
(if color-grob?
(set! (ly:grob-property grob
'color) color))
(set! last-pitch
current-pitch))))))))
\layout {
\context {
\Voice
\consists \interval-color-engraver #"2-" #intervaldefs #red
}
}
\relative c'' { c4 c cis c des c d c }
Am 30.11.2019 um 21:47 schrieb David Kastrup:
Michael Käppler <address@hidden> writes:
Am 29.11.2019 um 23:27 schrieb David Kastrup:
Michael Käppler <address@hidden> writes:
Hi all,
I would like to color all successive notes in a voice that span a
certain interval, like e.g. a perfect fifth upwards.
Seems to me the most straightforward and extensible way would be to
write a scheme engraver for this, right?
No, just a callback function for a NoteHead's color property should be
fine.
That means it is possible to access properties of a preceding or
subsequent event from within a callback?
Ah, no. I didn't really get what you meant using "successive" here.
Yes, this sounds like something that you'd use an engraver for.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Coloring adjacent notes by interval,
Michael Käppler <=