Deutschsprachiges LilyPond-Forum

Allgemeine Fragen und Probleme => Fragen und Probleme aller Art => Thema gestartet von: flashgordonx am Donnerstag, 19. Mai 2022, 13:50

Titel: Karakterzahl in meinem Noten
Beitrag von: flashgordonx am Donnerstag, 19. Mai 2022, 13:50
Hallo Leute

Gibt es irgendeine Method, Kommando, mit dem man Karakter- Zeichenzahl der Note  (Note-,Pause- Dynamikzeichen etc.) zählen kann?

Besten Dank im Voraus. :)
Titel: Antw:Karakterzahl in meinem Noten
Beitrag von: flashgordonx am Samstag, 21. Mai 2022, 18:27
Hier ist die Lösung:

\version "2.22.2"

printStats =
#(define-music-function (music) (ly:music?)
   (let ((notes 0)
         (rests 0)
         (dynamics 0))
     (for-some-music
      (lambda (m)
        (cond
         ((music-is-of-type? m 'note-event)
          (set! notes (1+ notes)))
         ((or (music-is-of-type? m 'rest-event )
              (music-is-of-type? m 'multi-measure-rest-event))
          (set! rests (1+ rests)))
         ((music-is-of-type? m 'dynamic-event)
          (set! dynamics (1+ dynamics))))
        #f)
      music)
     (ly:message "Found ~a notes, ~a rests and ~a absolute dynamics" notes rests dynamics)
     music))

\printStats \relative c' { c'4\mf\< e r8 g4 b c1\ff }
Titel: Antw:Karakterzahl in meinem Noten
Beitrag von: Manuela am Sonntag, 22. Mai 2022, 11:38
Mein scheme ist wieder einmal eingerostet.

Ich habe versucht, die Werte in Form eines Markups auszugeben, ich kriege kein Ergebnis, aber auch keine Fehlermeldung

mus=\relative c' { c'4\mf\< e r8 g4 b c1\ff }

#(define-markup-command (notenzahl layout props music)
   (ly:music?)
   (interpret-markup
    layout
    (let ((notes 0)
          (rests 0)
          (dynamics 0))
      (for-some-music
       (lambda (m)
         (cond
          ((music-is-of-type? m 'note-event)
           (set! notes (1+ notes)))
          ((or (music-is-of-type? m 'rest-event )
               (music-is-of-type? m 'multi-measure-rest-event))
           (set! rests (1+ rests)))
          ((music-is-of-type? m 'dynamic-event)
           (set! dynamics (1+ dynamics))))
         #f)
       music)
      (number->string notes)
      music)
    props))

\markup \notenzahl \mus

Titel: Antw:Karakterzahl in meinem Noten
Beitrag von: harm6 am Montag, 23. Mai 2022, 10:00
Hallo Manuela,

also ich bekomme einen Fehler:
Zitatprogramming error: Object is not a markup.
continuing, cross fingers
This object should be a markup: (((line-width . 108.120472440945) (font-encoding . latin1) (baseline-skip . 3) (replacement-alist) (word-space . 0.6)))

Ursache ist das `props' an der falschen Stelle steht.
`layout' und `props' sind obligatorische Argumente in:
(interpret-markup layout props ...)

Ansonsten willst Du ja nicht die `music' ausgeben, sondern den konstruierten string. Der muß dann natürlich an letzter Stelle stehen. Also:
mus=\relative c' { c'4\mf\< e r8 g4 b c1\ff }

#(define-markup-command (notenzahl layout props music)
   (ly:music?)
   (interpret-markup
    layout
    props
    (let ((notes 0)
          (rests 0)
          (dynamics 0))
      (for-some-music
       (lambda (m)
         (cond
          ((music-is-of-type? m 'note-event)
           (set! notes (1+ notes)))
          ((or (music-is-of-type? m 'rest-event )
               (music-is-of-type? m 'multi-measure-rest-event))
           (set! rests (1+ rests)))
          ((music-is-of-type? m 'dynamic-event)
           (set! dynamics (1+ dynamics))))
         #f)
       music)
      (number->string notes))))

\markup \notenzahl \mus

HTH,
  Harm
Titel: Antw:Karakterzahl in meinem Noten
Beitrag von: flashgordonx am Freitag, 27. Mai 2022, 22:57
Hallo Leute
Ich habe ein neuen Schnipsel bekommen. Diese kann alle Zeichen-Art (Noten, Artikulation, breathe etc.) zählen. :)

\version "2.22.2"

#(use-modules (ice-9 match))

statDefinitions =
#'(
   ;; notes
   ("notes" note-event)
   ;; rests (including multi-measure rests)
   ("rests" rest-event multi-measure-rest-event)
   ;; dynamics: absolute dynamics (like \p), dynamic spans (like \cresc)
   ("dynamics" dynamic-event span-dynamic-event)
   ;; articulations: \staccato, \prall, \fermata, ...
   ("articulations" articulation-event)
   ;; \breathe
   ("breath marks" breathing-event)
   ;; basically count everything
   ("events" event)
   )

printStats =
#(define-music-function (music) (ly:music?)
   (for-each
    (match-lambda
     ((desc . classes)
      (let ((count 0))
        (for-some-music
         (lambda (m)
           (if (any (lambda (c)
                      (music-is-of-type? m c))
                    classes)
               (set! count (1+ count)))
           #f)
         music)
        (ly:message "| Found ~a ~a" count desc))))
    statDefinitions)
   music)
                 

\printStats \relative c' { c'4-.\mf\< e-. r8 \breathe g4-. b-. c1\ff\fermata }