lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to define a macros for writing predefined chords of arbitrary le


From: Mojca Miklavec
Subject: Re: How to define a macros for writing predefined chords of arbitrary length?
Date: Wed, 1 Feb 2017 00:43:46 +0100

Dear Thomas,

Thanks a lot for the answer.

On 31 January 2017 at 00:55, Thomas Morley wrote:
> 2017-01-30 19:16 GMT+01:00 Mojca Miklavec:
>> Hi,
>>
>> I can easily use a macro to create chords of predefined lengths, say
>>
>>     chord_F = { <f a c'>4 }
>>
>> but the functionality is limited for what I want to achieve.
>>
>> On some instruments (like accordion) one gets that chord by pressing a
>> single button and I need some reasonable way to enter them without
>> messing everything up.
>>
>> (Some songs consist of only two different chords and I find it tedious
>> to keep entering <f a c'> <e g c'> over and over again, making lots of
>> mistakes, if I could assign that to just "F" and "C" or numbers 4 and
>> 2. \somelongwordF and \somelongwordC are still better than writing out
>> the full chord; the compiler would catch it if I make a spelling
>> mistake.)
>>
>> What I would like to be able to do is:
>>
>> - specify lengths
>>     \chord_F4 \chord_F2 or <\chord_F>4 <\chord_F>2
>>
>> - combine chords with other pitches (in theory perhaps with other
>> chords as well, but I never needed that so far)
>>     <f, \chord_F>8
>>
>>
>> To get things like
>>
>>     chord_F = { f a c' }
>>     melody = {
>>         f,8 <\chord_F>8 c8 <\chord_F>8 |
>>         <f, \chord_F>2
>>     }
>>
>> What options do I have to achieve the desired functionality? (I don't
>> care about the exact syntax as long as it would allow me to achieve
>> consistency.)
>>
>>
>> Thank you very much,
>>     Mojca
>>
>> (Please CC me.)
>
> How about:
>
> \version "2.19.52"
>
> chord =
> #(define-music-function (mus dur)(ly:music? ly:duration?)
>   (let ((evc-notes (extract-typed-music mus 'note-event)))
>     (for-each
>       (lambda (note-ev)
>         (ly:music-set-property! note-ev 'duration dur))
>       evc-notes)
>     (make-event-chord evc-notes)))
>
> chord_F = \chord <f a c'> \etc
> chord_Gm = \chord <g' bes' d''> \etc
>
>
> {
>     \set Score.skipBars = ##t
>     \chord_F16 \chord_F1 \chord_F32.. \chord_F\longa
>     \chord_Gm128 \chord_Gm2 \chord_Gm4
>     << f''8 \\ \repeat unfold 3 \chord_F16*2/3 >>
> }

I need more time (and skill) to understand the function definition,
but I will happily use it. Thank you very much, this helps a lot. It's
a tiny bit suboptimal that the durations are not optional, but I can
live with that.

> %% remark:
> %% n.b.: \chord_F4 <-- a duration is needed, the value doesn't matter
> chord_XY = \chord { fis'' \chord_F1 } \etc
>
> {
>     \chord_XY 64.
>     \chord { gis'' \transpose f f' \chord_F4 ees } 32
> }

Thank you. It's not so critical to be able to define new chords as the
fact that I'm able to use
    \chord { ... }
to combine predefined chords with something else. I tried using <>
earlier without success.

> The following I don't understand.

I tried to explain into some more details here:
    https://github.com/mojca/frajtonarca/tree/master/lilypond#basses

but I should probably add more graphics and I'll explain a bit more
below. An example of a real score is here:

https://github.com/mojca/frajtonarca/blob/master/tablature/avtorske/Mladi%20Dolenjci%20-%20Nisem%20pozabil.pdf

(replace pdf with ly to see the source)

>> PS: At some point in the future I would ideally like to be able to
>> prepare single input to get both of the following modes as output (but
>> that's already the next step):
>>
>>     \new Staff = "staff" <<
>>       \new Voice = "bass" {
>>         \clef bass
>>         \repeat unfold 3 { f,8 <f a c'> c, <f a c'> | } % push mode
>>         \repeat unfold 4 { g,8 <e g c'> c, <e g c'> | } % pull mode
>>         <f, f a c'>2 | % push mode
>>       }
>>     >>
>>
>>     \new FiguredBass {
>>       \figuremode {
>>         \repeat unfold 3 { <4>8 <3> <2> <3> | } % push mode
>>         \repeat unfold 4 { <2>8 <3> <4> <3> | } % pull mode
>>         <4 3>2 | % push mode
>>       }
>>     }

I like the way how the following example works (I learned a new trick just now):

basses = \chordmode { c1 g1 c1 }
<<
  \new ChordNames \chordmode {
    \basses
  }
  \chordmode {
    \basses
  }
>>

The user only has to input the melody once and lilypond will typeset
it in two different ways. I would like to do the same: write the
melody once and get it typeset in different ways.


Using your notation, here's the desired output (in "pull" direction):

ch_g = \chord g, \etc % button 2
ch_c = \chord c, \etc % button 4
ch_f = \chord f, \etc % button 6

% \chordmode { c/e, } probably wouldn't work here?
ch_C = \chord <e g c'> \etc % button 3
ch_F = \chord <f a c'> \etc % button 5

<<
  \time 3/4
  \new Staff {
    \clef bass
    \fixed c {
      \ch_c4 \ch_F4 \ch_F4 |
      \ch_f4 \ch_F4 \ch_F4 |
      \ch_g4 \ch_C4 \ch_C4 |
      \ch_c4 \ch_C4 \ch_C4 |
      \chord { \ch_c4 \ch_C4 } 2. |
    }
  }
  \new FiguredBass {
    \figuremode {
      <4>4 <5> <5> |
      <6>4 <5> <5> |
      <2>4 <3> <3> |
      <4>4 <3> <3> |
      <3 4>2. |
    }
  }
>>

The question is: could I somehow avoid having to write the contents of
figuremode manually? Both blocks represent exactly the same content
and I would like to be able to do some automatic conversion between
one and the other. (The example only uses a single playing direction.)


An alternative output (depending on preferences) could be the following:

<<
  \time 3/4
  \new Staff {
    \clef bass
    \fixed c {
      c, \chordmode { f, f, } |
      f, \chordmode { f, f, } |
      g, \chordmode { c/e, c/e, } |
      c, \chordmode { c/e, c/e, } |
    }
  }
  \new ChordNames {
    % ugly hack: these are not minor chords
    \set chordNameLowercaseMinor = ##t
    \chordmode {
      c f:m f:m |
      f f:m f:m |
      g c:m c:m |
      c c:m c:m |
    }
  }
>>

(Note that I never used \chordmode before and I just learned how it
could be used. \chordmode { f, } is still much better than writing the
whole chord out, but c/e is still "a bit weird" and in any case I
don't like the ugly hack of using "c:m" to get a lowercase letter c.)
I wasn't sure how to typset two chords at the same time. But the
question is whether it would theoretically be possible to enter single
input and get either of the representations above typset in both modes
automatically.

Thank you very much,
    Mojca



reply via email to

[Prev in Thread] Current Thread [Next in Thread]