Afegir funcions especials de lilypond
This commit is contained in:
84
folkugat_web/assets/templates/lilypond/lib.ly
Normal file
84
folkugat_web/assets/templates/lilypond/lib.ly
Normal file
@@ -0,0 +1,84 @@
|
||||
% -------------------------------------------------------------------------
|
||||
% Extra custom functions
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
% Alternative chords
|
||||
|
||||
#(define (pitches-bass-inversion-context-list music context)
|
||||
"Creates a list containing relevant pitches, bass, inversion and context to
|
||||
serve as argument for `ignatzek-chord-names', derived from @var{music}
|
||||
"
|
||||
(let* (;; work on a copy of `music', warranting not to change it
|
||||
(m-add (ly:music-deep-copy music))
|
||||
(ev-notes-orig (event-chord-notes m-add))
|
||||
;; if chord is an inversion some pitches are below root, in this case
|
||||
;; 'octavation-property is set.
|
||||
;; reset pitch of them
|
||||
;; TODO this is an ugly hack, find better method
|
||||
(ev-notes
|
||||
(map
|
||||
(lambda (m)
|
||||
(if (and (not (null? (ly:music-property m 'octavation)))
|
||||
(= (ly:music-property m 'octavation) -1))
|
||||
(begin
|
||||
(ly:music-set-property! m 'pitch
|
||||
(ly:pitch-transpose
|
||||
(ly:music-property m 'pitch)
|
||||
(ly:make-pitch 1 0 0)))
|
||||
m)
|
||||
m))
|
||||
ev-notes-orig))
|
||||
;; sort the ptches ascending as expected by `ignatzek-chord-names'
|
||||
(ev-pitches
|
||||
(sort
|
||||
(map (lambda (m) (ly:music-property m 'pitch)) ev-notes)
|
||||
ly:pitch<?))
|
||||
;; get bass
|
||||
(bass-note
|
||||
(filter
|
||||
(lambda (m)
|
||||
(not (null? (ly:music-property m 'bass))))
|
||||
ev-notes))
|
||||
(bass-pitch
|
||||
(if (not (null? bass-note))
|
||||
(ly:music-property (car bass-note) 'pitch)
|
||||
'()))
|
||||
;; get inversion
|
||||
(inversion-note
|
||||
(filter
|
||||
(lambda (m)
|
||||
(not (null? (ly:music-property m 'inversion))))
|
||||
ev-notes))
|
||||
(inversion-pitch
|
||||
(if (not (null? inversion-note))
|
||||
(ly:music-property (car inversion-note) 'pitch)
|
||||
'()))
|
||||
;; TODO why is this needed?
|
||||
(in-pitches
|
||||
(if (null? inversion-pitch)
|
||||
(delq bass-pitch ev-pitches)
|
||||
ev-pitches)))
|
||||
|
||||
(list in-pitches bass-pitch inversion-pitch context)))
|
||||
|
||||
altChords =
|
||||
#(define-music-function (m1 m2)(ly:music? ly:music?)
|
||||
"Return the default ChordName of @var{m1}, with an added parenthesized ChordName
|
||||
derived from @var{m2}"
|
||||
#{
|
||||
\applyOutput ChordNames.ChordName
|
||||
#(lambda (g ctx p)
|
||||
(let ((main-text (ly:grob-property g 'text))
|
||||
(alt-text
|
||||
(apply
|
||||
ignatzek-chord-names
|
||||
(pitches-bass-inversion-context-list m2 ctx))))
|
||||
(ly:grob-set-property! g 'text
|
||||
#{
|
||||
\markup
|
||||
{ $main-text \hspace #0.4 \fontsize #-3 \parenthesize $alt-text }
|
||||
#})))
|
||||
$m1
|
||||
#})
|
||||
|
||||
% -------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user