Hi, Great work.
I've done some testing and found some bugs. Below the code I've tested, attached the PDF with the result (on second page, first page are your examples).
\autoSplitChord doesn't works with curly braces, it returns blank output (like a blank space in the score), so it's not possible to work with:
- chordmode - more than one chord a time - moltiple voicesAlso, \autoSplitChord doesn't works with single notes, it returns blank space.
It accepts variables, but the result is the same.
Pippo = <c e g c' e'>1
PippoDue = \chordmode {c1:/g}
PippoTre = c1
PippoQuattro = {<c e g>}
\new PianoStaff
\with { \consists #Span_stem_engraver }
<<
\new Staff = "up"
{
\key c\major
%chord with stem up
\autoSplitChord #UP <f a a' f'>2 %works
%chord without stem
\autoSplitChord <g c' e'>4 %works
%chord with stem down
\autoSplitChord #DOWN <g c' e'> %works
%chord, whole note
\autoSplitChord <c g e' c''>1 %works
%chordmode
\autoSplitChord \chordmode {c:/g} %blank output
%chord entered in curly braces
\autoSplitChord {<c g e' c''>} %blank output
%more than one chord, in curly braces
\autoSplitChord {<c e g> <d f a>} %blank output
%single note
\autoSplitChord c %blank output
%single note in a chord
\autoSplitChord <c'> %works
%chord entered in polyphonic style
\autoSplitChord <<c\\e'\\g''\\g,>> %works
%polyphonic style, different durations
\autoSplitChord <<c1\\e'2\\g''\\g,>> %warning & strange output
%polyphonic style, with some curly braces
\autoSplitChord <<c1 \\ {e2 f}\\d'1>> %notes in curly braces are
not printed
%polyphonic style, with curly braces
\autoSplitChord <<
{c4 d e f}
\\
{c' d' e' f'}
>> %blank output
%chord in a variable
\autoSplitChord \Pippo %works
%chord in a variable with chordmode
\autoSplitChord \PippoDue %blank output
%single note in a variable
\autoSplitChord \PippoTre %blank output
%chord in curly braces in a variable
\autoSplitChord \PippoQuattro %blank output
}
\new Staff = "down"
{
\key c\major
\clef bass
s1
}
>>
Thank you for the work.
Cheers
Davide
--
Questa e-mail è stata controllata per individuare virus con Avast antivirus.
https://www.avast.com/antivirus
\version "2.20.0"
#(define (make-autosplit-chord chord . ref-pitch)
"Return a pair of lists, containing the pitches of @var{chord}, splitted at
a reference pitch. The reference pitch is derived from @var{ref-pitch}.
If @var{ref-pitch} is empty, @code{c'} is regarded as reference.
"
(define ref-pitch-steps
(if (and (pair? ref-pitch) (car ref-pitch))
(ly:pitch-steps (car ref-pitch))
0))
(call-with-values
(lambda ()
(partition
(lambda (note)
(> (ly:pitch-steps (ly:music-property note 'pitch))
ref-pitch-steps))
(event-chord-notes chord)))
(lambda (x y) (cons x y))))
autoSplitChord =
#(define-music-function (stem-dir staff-names pitch chord)
((ly:dir? 0) (pair? '("up" . "down")) (ly:pitch?) ly:music?)
(_i "Split @var{chord} at optional @var{pitch}. The default of @var{pitch} is
@code{#f}, which is interpreted by the called procedure
@code{make-autosplit-chord} as @code{c'}.
The splitted chords are distributed to named staves, relying on optional
@var{staff-names}.
The optional @var{stem-dir}, determines the direction of the stems and whether
the chords may be connected by a cross-staff stem.
The default results in unconnected chords.
If the @code{Span_stem_engraver} is consisted, the chords may be connected by a
cross-staff stem.")
(let* ((skip (make-duration-of-length (ly:music-length chord)))
(devided-pitches (make-autosplit-chord chord pitch))
(upper-chord
(if (pair? (car devided-pitches))
(make-event-chord (car devided-pitches))
(make-skip-music skip)))
(lower-chord
(if (pair? (cdr devided-pitches))
(make-event-chord (cdr devided-pitches))
(make-skip-music skip))))
#{
<<
\context Staff = #(car staff-names)
\context Voice {
$(if (negative? stem-dir)
#{
\once \override Stem.cross-staff = #cross-staff-connect
\once \override Flag.style = #'no-flag
<>\noBeam
#})
$(if (not (zero? stem-dir))
#{ \once \override Stem.direction = #stem-dir #})
#upper-chord
}
\context Staff = #(cdr staff-names)
\context Voice {
$(if (positive? stem-dir)
#{
\once \override Stem.cross-staff = #cross-staff-connect
\once \override Flag.style = #'no-flag
<>\noBeam
#})
$(if (not (zero? stem-dir))
#{ \once \override Stem.direction = #stem-dir #})
#lower-chord
}
>>
#}))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\score {
\new StaffGroup
\with { \consists #Span_stem_engraver }
<<
\new Staff = "up" \with { instrumentName = "up" }
\new Voice = "foo" {
\key g \major
\clef "treble"
<>^"possible stems"
\autoSplitChord <f a d'' g''>4
\autoSplitChord #DOWN <f a d'' g''>
\autoSplitChord #UP <f a d'' g''>2
\bar "||"
<>^"various staves"
%% While other staves are specified, the stems direction must be set
%% as well.
\autoSplitChord #CENTER #'("up" . "middle") <f a d' g'>4
\autoSplitChord #DOWN #'("middle" . "down") <f a d'' g''>
%% If the chord is distributed in not descending order, \crossStaff
%% needs to be set manually. See below in: \new Staff = "down" [...]
\autoSplitChord #UP #'("down" . "middle") <f a d'' g''>2
\bar "||"
<>^"other split pitch"
%% While other split pitches are specified, the stems direction and
%% staff-names must be set as well.
\autoSplitChord #CENTER #'("up" . "down") a'' <f a d'' g''>4
\autoSplitChord #UP #'("up" . "down") e'' <f a d'' g''>
\autoSplitChord #DOWN #'("up" . "down") g <f a d'' g''>
\autoSplitChord #DOWN #'("up" . "down") e <f a d'' g''>
\bar "||"
}
\new Staff = "middle" \with { instrumentName = "middle" }
\new Voice = "bar"
\crossStaff {
\key g \major
\clef "bass"
s1*3
}
\new Staff = "down" \with { instrumentName = "down" }
\new Voice = "buzz" {
\key g \major
\clef "bass"
s1
s2
\clef "treble"
\crossStaff
s2
s2
\clef "bass"
s2
}
>>
\layout {
ragged-right = ##f
\override TextScript.staff-padding = 4
}
}
\new PianoStaff
\with { \consists #Span_stem_engraver }
<<
\new Staff = "up"
\new Voice = "foo" {
\key g \major
\autoSplitChord #UP <f a a' f'>2
r2
R1
s2
c'2
\autoSplitChord #1 <f a a' f'>8
f'8 8 8
s2
\autoSplitChord #-1 <g d''>2
}
\new Staff = "down"
\new Voice = "bar"
\crossStaff {
\key g \major
\clef bass
s1
c1
\autoSplitChord #DOWN <f a a' f'>2
c2
s8 f f f
\autoSplitChord #DOWN <f a a' f'>2
s2
}
>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TESTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pageBreak
Pippo = <c e g c' e'>1
PippoDue = \chordmode {c1:/g}
PippoTre = c1
PippoQuattro = {<c e g>}
\new PianoStaff
\with { \consists #Span_stem_engraver }
<<
\new Staff = "up"
{
\key c\major
%chord with stem up
\autoSplitChord #UP <f a a' f'>2 %works
%chord without stem
\autoSplitChord <g c' e'>4 %works
%chord with stem down
\autoSplitChord #DOWN <g c' e'> %works
%chord, whole note
\autoSplitChord <c g e' c''>1 %works
%chordmode
\autoSplitChord \chordmode {c:/g} %blank output
%chord entered in curly braces
\autoSplitChord {<c g e' c''>} %blank output
%more than one chord, in curly braces
\autoSplitChord {<c e g> <d f a>} %blank output
%single note
\autoSplitChord c %blank output
%single note in a chord
\autoSplitChord <c'> %works
%chord entered in polyphonic style
\autoSplitChord <<c\\e'\\g''\\g,>> %works
%polyphonic style, different durations
\autoSplitChord <<c1\\e'2\\g''\\g,>> %warning & strange output
%polyphonic style, with some curly braces
\autoSplitChord <<c1 \\ {e2 f}\\d'1>> %notes in curly braces are not printed
%polyphonic style, with curly braces
\autoSplitChord <<
{c4 d e f}
\\
{c' d' e' f'}
>> %blank output
%chord in a variable
\autoSplitChord \Pippo %works
%chord in a variable with chordmode
\autoSplitChord \PippoDue %blank output
%single note in a variable
\autoSplitChord \PippoTre %blank output
%chord in curly braces in a variable
\autoSplitChord \PippoQuattro %blank output
}
\new Staff = "down"
{
\key c\major
\clef bass
s1
}
>>
autoSplitChord test.pdf
Description: Adobe PDF document
