[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: creating chords like F/A(D/F#) with \chordmode { }
From: |
Thomas Morley |
Subject: |
Re: creating chords like F/A(D/F#) with \chordmode { } |
Date: |
Sun, 13 Mar 2016 01:32:45 +0100 |
2016-03-12 18:30 GMT+01:00 Klaus Blum <address@hidden>:
> It looks like the goal is to create alternative chords in a different key,
> e.g for a guitar with a capo on the 3rd fret.
>
> A function to put chordnames into parentheses (better than \parenthesize)
> can be found here:
> http://www.lilypondforum.de/index.php?action=profile;area=showposts;u=54
>
> Here is what I would try:
>
> % -----------------------------------------------------------------------
> \version "2.19.25"
>
> #(define (parenthesis-ignatzek-chord-names in-pitches bass inversion
> context)
> (markup #:line ( "(" (ignatzek-chord-names in-pitches bass inversion
> context) ")" )))
>
> klamm = #(define-music-function (parser location griffe) (ly:music?)
> #{
> \set chordNameFunction = #parenthesis-ignatzek-chord-names
> $griffe
> \set chordNameFunction = #ignatzek-chord-names
> #})
>
>
> \score {
> <<
> \new ChordNames \chordmode {
> c2 c/e f g
> }
> \new ChordNames \transpose c a \chordmode {
> \klamm { c2 c/e f g }
> }
> \new Staff \relative c'' {
> c2 c a4 c b2
> }
> >>
> }
>
> \score {
> <<
> \new ChordNames \chordmode {
> c16 \klamm a4.. c16/e \klamm a4../cis f16 \klamm d4.. g16 \klamm e4..
> }
> \new Staff \relative c'' {
> c2 c a4 c b2
> }
> >>
> }
> % -----------------------------------------------------------------------
>
> Cheers,
> Klaus
Here my own approach.
The function always needs two music-expressions, supposed to be
event-chords, as arguments.
This may be an advantage or disadvantage depending on the use-case.
Furthermore there are some TODOs. Thoroughly testing is recommended ...
\version "2.19.36"
#(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
#})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
m =
\chordmode {
\altChords c1 e:m7/e
\altChords c1 e:m9/dis
\altChords c1 e:m11/d
\break
\altChords c1 e:m7/des
\altChords c1 e:m7/c
\altChords bes2 g
\altChords f/a d/fis
}
<<
\new ChordNames \m
\new Staff \m
>>
Cheers,
Harm