lilypond-user
[Top][All Lists]
Advanced

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

Re: template for a "simple" theory exercise randomizer


From: Aaron Hill
Subject: Re: template for a "simple" theory exercise randomizer
Date: Sun, 31 Jul 2022 12:48:09 -0700

On 2022-07-31 12:00 pm, Kieren MacMillan wrote:
Thanks for any help you can give!

Here is something I threw together quickly... Hope it offers some inspiration:

%%%%
\version "2.22.0"

createExercise =
#(define-scheme-function
  (clef key root)
  (symbol? ly:pitch? ly:pitch?)
  #{
    \markup \score {
      \new Staff {
        \omit Score.TimeSignature
        \clef #(symbol->string clef)
        \key $key \major
        $root 1
        \bar "||"
      }
    }
  #})

randomElement =
#(define-scheme-function
  (list-of-elements) (list?)
  (list-ref list-of-elements
    (random (length list-of-elements))))

clefs = treble,bass

keys = #(music-pitches #{
  c des d ees e f fis g aes a bes b
#})

scaleDegreesFor =
#(define-scheme-function
  (key) (ly:pitch?)
  (music-pitches (ly:music-transpose
    #{ { c d e f g a } #} key)))

\markup \wordwrap { #@(map
 (lambda args
  (let*
    ((clef #{ \randomElement \clefs #})
     (key #{ \randomElement \keys #})
     (root #{ \randomElement \scaleDegreesFor #key #}))
   (if (eq? clef 'treble)
       (set! root (ly:pitch-transpose root #{ c'' #})))
    #{ \createExercise #clef #key #root #}))
 (iota 24))
}
%%%%

NOTE: I omitted scale degree seven intentionally to focus only on major or minor triads.


-- Aaron Hill

Attachment: exercise.cropped.png
Description: PNG image


reply via email to

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