Allgemein > Fragen zu Funktionen

Irgendetwas systematisch an Noten automatisch schreiben

<< < (2/3) > >>

Hilflos-im-Code:

--- Zitat von: Manuela am Donnerstag,  5. Januar 2017, 09:04 ---
--- Zitat von: Hilflos-im-Code am Donnerstag,  5. Januar 2017, 08:38 ---Deine Antwort habe ich soeben entdeckt.

--- Ende Zitat ---

Wirst du nicht automatisch per Mail benachrichtigt? Oder schaut du so selten in dein Postfach?  ;)

--- Ende Zitat ---
Ich schalte bei jedem Forum die Benachrichtigungsfunktion ab, damit ich meine wirklich wichtigen Mails nicht übersehe.

Hilflos-im-Code:
Ich wollte die ANgabe von den Notenwerten flexibler machen. Daraus wurde


--- Code: ---\version "2.19.52"

#(define pitch-markup-list
;; An alist assigning markups to certain integers, which will be used later
;; as reference for the pitch-names
;; TODO add the missing eps-markups
`(
  (0 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: c-eps]"))
  (1 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: d-eps]"))
  (2 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: e-eps]"))
  (3 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: f-eps]"))
  (4 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: g-eps]"))
  (5 . ,(markup #:halign 0 #:epsfile X 10 "Affe.eps"))
  (6 . ,(markup #:halign 0 #:epsfile X 10 "Hase.eps"))))


#(define notenwerteliste-list
;; Analog zur pitch-markup-list
`(
  (0 . ,(markup #:fontsize -8 #:halign 0 "Ganze"))
  (1 . ,(markup #:fontsize -8 #:halign 0 "punktierte Halbe"))
  (2 . ,(markup #:fontsize -8 #:halign 0 "Halbe"))
  (3 . ,(markup #:fontsize -8 #:halign 0 "punktierte Viertel"))
  (4 . ,(markup #:fontsize -8 #:halign 0 "Viertel"))
  (5 . ,(markup #:halign 0 #:halign 0 "Achtel"))
  ))


%Grenze

#(define ((chord-name->my-german-markup-text-alteration) pitch lowercase?)
"Print real german names."
;; Remark: currently ases is printed, may be discussable...
   (define (pitch-alteration-semitones pitch)
    (inexact->exact (round (* (ly:pitch-alteration pitch) 2))))

   (define (conditional-string-downcase str condition)
    (if condition
        (string-downcase str)
        str))

   (let* ((name (ly:pitch-notename pitch))
          (alt-semitones  (pitch-alteration-semitones pitch))
          ;; The following condition is weird. Though, we let them in to ease
          ;; comporability with the original.
          (n-a (cond ((member (cons name alt-semitones) `((6 . -1) (6 . -1)))
                      (cons 7 alt-semitones))
                     (else (cons name alt-semitones)))))
    (make-concat-markup
     (list
      (make-simple-markup
       (conditional-string-downcase
        (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a))
       lowercase?))
      (let ((alteration (/ (cdr n-a) 2)))
        (cond
           ((and (= alteration FLAT) (= (car n-a) 7))
             (make-simple-markup ""))
           ((and (= alteration FLAT) (or (= (car n-a) 5) (= (car n-a) 2) ))
             (make-simple-markup "s"))
           ((= alteration FLAT) (make-simple-markup "es"))
           ((and (= alteration DOUBLE-FLAT) (or (= (car n-a) 5)(= (car n-a) 2)))
             (make-simple-markup "ses"))
           ((= alteration DOUBLE-FLAT)
             (make-simple-markup "eses"))
           ((= alteration SHARP)
             (make-simple-markup "is"))
           ((= alteration DOUBLE-SHARP)
             (make-simple-markup "isis"))
           (else empty-markup)))))))




%Grenze

#(define-markup-command (arc layout props angle)(number?)
  #:properties ((radius 1.5)
                (font-size 1)
                (double-radius-x-ext #t))
  "Print a circle-segment relying on @var{angle} in degrees.
The radius may be adjusted by overriding the @code{radius}-property.
The dimensions of the resulting stencil are set properly.
If @var{double-radius-x-ext} is set @code{#t}, (the default) the dimensions are
always from @code{(- radius)} to @code{radius} in Y-axis."
  (let* ((scaled-radius (* radius font-size))
         (top radius)
         (bottom
           (if double-radius-x-ext
               (- scaled-radius)
               (cond ((<= angle 90) 0)
                     ((> angle 180) (- scaled-radius))
                     (else
                       (* (cos (degrees->radians angle)) scaled-radius)))))
         (left
           (cond ((>= angle 270) (- scaled-radius))
                  ((> angle 180)
                   (* (sin (degrees->radians angle)) scaled-radius))
                  (else 0)))
         (right
           (cond ((> angle 90) scaled-radius)
                 (else
                   (* (sin (degrees->radians angle)) scaled-radius)))))
  (ly:make-stencil
   (list 'embedded-ps
         (format #f "
gsave currentpoint translate
0.1 setlinewidth
0 0 ~a 90 ~a arcn % Bogen 90 Grad
fill
grestore
"
scaled-radius
(- 90 angle)))
   (cons left right)
   (cons bottom top))))



%Grenze Hier werden die Kreise erzeugt

addTextScript =
#(define-music-function (music)(ly:music?)
"Adds markups to note-heads.
- a circle-segment above
    (relying on and representing the duration of a note-head
- an eps below
    (called with the note-name from @code{pitch-markup-list}"
  (music-map
    (lambda (mus)
      (if (music-is-of-type? mus 'note-event)
       
       (let* ((dur-frac (ly:moment-main (ly:music-length mus)))
               (pitch (ly:music-property mus 'pitch))
               (pitch-name (ly:pitch-notename pitch)))
          (ly:music-set-property! mus 'articulations
            (append
              (list
                (make-music
                  'TextScriptEvent
                  'direction DOWN
                  'text
                  (assoc-get pitch-name pitch-markup-list))
                (make-music
                  'TextScriptEvent
                  'direction UP
                  'text
                   (assoc-get dur-frac notenwerteliste-list))))
              (ly:music-property mus 'articulations)))
          mus)
        mus))
      music)
  music)

%Grenze



printGermanNoteNames =
#(define-music-function (solve?)(boolean?)
#{
\override NoteName.stencil =
#(lambda (grob)
  (let ((pitch (ly:prob-property (ly:grob-property grob 'cause) 'pitch)))
    (grob-interpret-markup
      grob
      (if solve?
          ((chord-name->my-german-markup-text-alteration) pitch #t)
          (markup #:with-dimensions-from "XXX" "...")))))
#})

exercise =
#(define-music-function (solve? music)(boolean? ly:music?)
#{
<<
  \new Staff
  \with { instrumentName = #(if solve? "Aufösung " "Aufgabe ") }
  {
    #(if solve?
         #{ \unHideNotes #}
         #{ \hideNotes #})
    \addTextScript $music
  }

  \new NoteNames
    \with {
      %\override VerticalAxisGroup.nonstaff-relatedstaff-spacing.padding = 4
      \printGermanNoteNames $solve?
    }
    $music
>>
#})

%grenze


\language "deutsch"

\paper { score-system-spacing.padding = 6 }

\layout {
  \override TextScript.parent-alignment-X = #CENTER
  \override TextScript.staff-padding = 4.5
  \override TextScript.font-size = 2
  \textLengthOn
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

mus = {
  \cadenzaOn
  c'4 d'2 e'4. f'8 g'16 a'2. h'1 c''8.
  \bar "|."
}

%% exercise:
\exercise ##f \mus

%% solved:
\exercise ##t \mus

--- Ende Code ---


Was natürlich nicht geht, weil ich einfach analog kopiert habe.

Geht das überhaupt mit


--- Code: --- 'TextScriptEvent
                  'direction UP
                  'text
                   (assoc-get dur-frac notenwerteliste-list)
--- Ende Code ---

Was gibt dur-frac aus? Und was müsste ich statt der Ziffern am Zeilenanfang in notenwerteliste-list eintragen?

 
--- Code: ---#(define notenwerteliste-list
;; Analog zur pitch-markup-list
`(
  (0 . ,(markup #:fontsize -8 #:halign 0 "Ganze"))
  (1 . ,(markup #:fontsize -8 #:halign 0 "punktierte Halbe"))
  (2 . ,(markup #:fontsize -8 #:halign 0 "Halbe"))
  (3 . ,(markup #:fontsize -8 #:halign 0 "punktierte Viertel"))
  (4 . ,(markup #:fontsize -8 #:halign 0 "Viertel"))
  (5 . ,(markup #:halign 0 #:halign 0 "Achtel"))
  ))


--- Ende Code ---

harm6:

--- Zitat ---Was gibt dur-frac aus? Und was müsste ich statt der Ziffern am Zeilenanfang in notenwerteliste-list eintragen?
--- Ende Zitat ---

Die (lokale) Definition:
  (dur-frac (ly:moment-main (ly:music-length mus)))

Um hier Aufschluss zu bekommen setze display-Funktionen in einem minimal ein:


--- Code: ---mus = { c''2. }
\displayMusic \mus
#(write-me "\nly:music-length: " (ly:music-length mus))
#(write-me "ly:moment-main:  " (ly:moment-main (ly:music-length mus)))

--- Ende Code ---

=>

--- Zitat von: terminal ---(make-music
  'SequentialMusic
  'elements
  (list (make-music
          'NoteEvent
          'duration
          (ly:make-duration 1 1)
          'pitch
          (ly:make-pitch 1 0))))


ly:music-length: #<Mom 3/4>
ly:moment-main:  3/4

--- Ende Zitat ---

Also:
ly:music-length gibt die Länge des musikalischen Arguments (hier die von (ly:make-duration 1 1)) als moment zurück. ly:moment-main extrahiert dann für gewöhnlich den numerischen Wert.

Aber aufgepasst, ly:music-length akzeptiert natürlich auch zusammengesetzte Ausdrücke, deshalb ist die Anwendung in der Funktion auf einzelne note-events begrenzt.


--- Zitat ---Und was müsste ich statt der Ziffern am Zeilenanfang in notenwerteliste-list eintragen?
--- Ende Zitat ---
Den Bruch, der dann referenziert werden kann:


--- Code: ---\version "2.19.52"

#(define pitch-markup-list
;; An alist assigning markups to certain integers, which will be used later
;; as reference for the pitch-names
;; TODO add the missing eps-markups
`(
  (0 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: c-eps]"))
  (1 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: d-eps]"))
  (2 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: e-eps]"))
  (3 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: f-eps]"))
  (4 . ,(markup #:fontsize -8 #:halign 0 "[dummy für: g-eps]"))
  (5 . ,(markup #:halign 0 #:epsfile X 10 "Affe.eps"))
  (6 . ,(markup #:halign 0 #:epsfile X 10 "Hase.eps"))))


#(define notenwerteliste-list
;; Analog zur pitch-markup-list
`(
  (1    . ,(markup #:fontsize -8 #:halign 0 "Ganze"))
  (3/4  . ,(markup #:fontsize -8 #:halign 0 "punktierte Halbe"))
  (1/2  . ,(markup #:fontsize -8 #:halign 0 "Halbe"))
  (3/8  . ,(markup #:fontsize -8 #:halign 0 "punktierte Viertel"))
  (1/4  . ,(markup #:fontsize -8 #:halign 0 "Viertel"))
  (1/8  . ,(markup #:fontsize -8 #:halign 0 "Achtel"))
  (1/16 . ,(markup #:fontsize -8 #:halign 0 "Sechzehntel"))
  (3/16 . ,(markup #:fontsize -8 #:halign 0 "punktierte Achtel"))
  ))


%Grenze

#(define ((chord-name->my-german-markup-text-alteration) pitch lowercase?)
"Print real german names."
;; Remark: currently ases is printed, may be discussable...
   (define (pitch-alteration-semitones pitch)
    (inexact->exact (round (* (ly:pitch-alteration pitch) 2))))

   (define (conditional-string-downcase str condition)
    (if condition
        (string-downcase str)
        str))

   (let* ((name (ly:pitch-notename pitch))
          (alt-semitones  (pitch-alteration-semitones pitch))
          ;; The following condition is weird. Though, we let them in to ease
          ;; comporability with the original.
          (n-a (cond ((member (cons name alt-semitones) `((6 . -1) (6 . -1)))
                      (cons 7 alt-semitones))
                     (else (cons name alt-semitones)))))
    (make-concat-markup
     (list
      (make-simple-markup
       (conditional-string-downcase
        (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a))
       lowercase?))
      (let ((alteration (/ (cdr n-a) 2)))
        (cond
           ((and (= alteration FLAT) (= (car n-a) 7))
             (make-simple-markup ""))
           ((and (= alteration FLAT) (or (= (car n-a) 5) (= (car n-a) 2) ))
             (make-simple-markup "s"))
           ((= alteration FLAT) (make-simple-markup "es"))
           ((and (= alteration DOUBLE-FLAT) (or (= (car n-a) 5)(= (car n-a) 2)))
             (make-simple-markup "ses"))
           ((= alteration DOUBLE-FLAT)
             (make-simple-markup "eses"))
           ((= alteration SHARP)
             (make-simple-markup "is"))
           ((= alteration DOUBLE-SHARP)
             (make-simple-markup "isis"))
           (else empty-markup)))))))




%Grenze

#(define-markup-command (arc layout props angle)(number?)
  #:properties ((radius 1.5)
                (font-size 1)
                (double-radius-x-ext #t))
  "Print a circle-segment relying on @var{angle} in degrees.
The radius may be adjusted by overriding the @code{radius}-property.
The dimensions of the resulting stencil are set properly.
If @var{double-radius-x-ext} is set @code{#t}, (the default) the dimensions are
always from @code{(- radius)} to @code{radius} in Y-axis."
  (let* ((scaled-radius (* radius font-size))
         (top radius)
         (bottom
           (if double-radius-x-ext
               (- scaled-radius)
               (cond ((<= angle 90) 0)
                     ((> angle 180) (- scaled-radius))
                     (else
                       (* (cos (degrees->radians angle)) scaled-radius)))))
         (left
           (cond ((>= angle 270) (- scaled-radius))
                  ((> angle 180)
                   (* (sin (degrees->radians angle)) scaled-radius))
                  (else 0)))
         (right
           (cond ((> angle 90) scaled-radius)
                 (else
                   (* (sin (degrees->radians angle)) scaled-radius)))))
  (ly:make-stencil
   (list 'embedded-ps
         (format #f "
gsave currentpoint translate
0.1 setlinewidth
0 0 ~a 90 ~a arcn % Bogen 90 Grad
fill
grestore
"
scaled-radius
(- 90 angle)))
   (cons left right)
   (cons bottom top))))



%Grenze Hier werden die Kreise erzeugt

addTextScript =
#(define-music-function (music)(ly:music?)
"Adds markups to note-heads.
- a circle-segment above
    (relying on and representing the duration of a note-head
- an eps below
    (called with the note-name from @code{pitch-markup-list}"
  (music-map
    (lambda (mus)
      (if (music-is-of-type? mus 'note-event)
       
       (let* ((dur-frac (ly:moment-main (ly:music-length mus)))
              (pitch (ly:music-property mus 'pitch))
              (pitch-name (ly:pitch-notename pitch)))
          (ly:music-set-property! mus 'articulations
            (append
              (list
                ;; print eps
                (make-music
                  'TextScriptEvent
                  'direction DOWN
                  'text
                  (assoc-get pitch-name pitch-markup-list))
                ;; print text
                (make-music
                  'TextScriptEvent
                  'direction UP
                  'text
                   (assoc-get dur-frac notenwerteliste-list))
                ;; print the circles
                (make-music
                  'TextScriptEvent
                  'direction UP
                  'text
                  #{
                    \markup
                      \with-color #'(0.6 0.6 0.6)
                      \arc #(* 360.0 dur-frac)
                  #})
                   )
              (ly:music-property mus 'articulations)))
          mus)
        mus))
      music)
  music)

%Grenze



printGermanNoteNames =
#(define-music-function (solve?)(boolean?)
#{
\override NoteName.stencil =
#(lambda (grob)
  (let ((pitch (ly:prob-property (ly:grob-property grob 'cause) 'pitch)))
    (grob-interpret-markup
      grob
      (if solve?
          ((chord-name->my-german-markup-text-alteration) pitch #t)
          (markup #:with-dimensions-from "XXX" "...")))))
#})

exercise =
#(define-music-function (solve? music)(boolean? ly:music?)
#{
<<
  \new Staff
  \with { instrumentName = #(if solve? "Aufösung " "Aufgabe ") }
  {
    #(if solve?
         #{ \unHideNotes #}
         #{ \hideNotes #})
    \addTextScript $music
  }

  \new NoteNames
    \with {
      %\override VerticalAxisGroup.nonstaff-relatedstaff-spacing.padding = 4
      \printGermanNoteNames $solve?
    }
    $music
>>
#})

%grenze


\language "deutsch"

\paper { score-system-spacing.padding = 6 }

\layout {
  \override TextScript.parent-alignment-X = #CENTER
  \override TextScript.staff-padding = 2.5
  \override TextScript.font-size = 2
  \textLengthOn
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

mus = {
  \cadenzaOn
  c'4 d'2 e'4. f'8 g'16 a'2. h'1 c''8.
  \bar "|."
}

%% exercise:
\exercise ##f \mus

%% solved:
\exercise ##t \mus

--- Ende Code ---

HTH,
  Harm

EDIT Kopierfehler korrigiert



Hilflos-im-Code:
Vielen Dank.


--- Code: --- (ly:make-pitch 0 5 1/2)
--- Ende Code ---

hat mich auf die Idee gebracht, das Problem zu lösen, dass bei deinem Code Oktaven und Vorzeichen unterschlagen werden. Bei der Referenzierung


--- Code: ---#(define pitch-markup-list
;; An alist assigning markups to certain integers, which will be used later
;; as reference for the pitch-names
;; TODO add the missing eps-markups
`(
    (0 5 1/2 . ,(markup #:halign 0 "Das falsche Ais eingestrichen"))
  (0 6 -1/2 . ,(markup #:halign 0 "Ein gestrichener Bube"))
  ))


--- Ende Code ---

bekomme ich noch keine Fehlermeldung.

Aber was ich wie bei  (assoc-get pitch-name pitch-markup-list) für pitch-name einsetzen muss, habe ich noch nicht herausgefunden. Letztendlich würde dann ein Script einstehen, was für jedes Instrument einsetzbar wäre, ohne dass man die Gebräuche im Anfängerunterricht kennen muss.

Hilflos-im-Code:
Ich habe jetzt zwei Stunden rumprobiert, komme aber auf keinen grünen Zweig. Bei meiner Suche, die Syntax zu verstehen bin ich unter https://archiv.lilypondforum.de/index.php?topic=1712.0
auf

--- Code: ---\version "2.18.0"

%% nicer output
#(use-modules (ice-9 pretty-print))

%% Define the language, if you want, needs to be a string:
which-language = "deutsch"

#(define which-language
;; tests whether 'which-language' is defined already and if 'which-language' is
;; part of 'language-pitch-names', see define-note-names.scm
;; if not, use 'default-language' (netherlands), see declarations-init.ly
 (if (defined? 'which-language)
     (let ((possible-languages (map car language-pitch-names)))
       ;(write possible-languages)
       (if (member (string->symbol which-language) possible-languages)
           which-language
           (ly:error "specified language, \"~a\", does not exist"
                     which-language)))
     default-language))
 
\language \which-language

#(define used-notenames
;; returns a subset of 'language-pitch-names', specified by which-language.
;; key and value are exchanged
;; i.e. the alist is from type '((pitch . name) ... )
  (map
    (lambda (e) (reverse-interval e))
    (assoc-get
      (string->symbol which-language)
          language-pitch-names)))

%#(pretty-print used-notenames)
 
display-note-names =
#(define-music-function (parser loction music)(ly:music?)
"
 Returns the unchanged music, writing the absolute notenames in terminal.
"
    (music-map
       (lambda (mus)
         (if (music-is-of-type? mus 'note-event)
             (begin
               (let* ((pitch (ly:music-property mus 'pitch))
                      (pitch-octaves (ly:pitch-octave pitch))
                      (pitch-notename (ly:pitch-notename pitch))
                      (pitch-alteration (ly:pitch-alteration pitch))
                      ;; create a pitch with alteration, name and
                      ;; octave set to -1
                      ;; this ensures the possibility to look it up in
                      ;; 'used-notenames'
                      (p (ly:make-pitch -1 pitch-notename pitch-alteration))
                      (pitch-name-strg
                         (symbol->string (assoc-get p used-notenames)))
                      ;; recreate the octave-notation
                      (octave-sign
                        (cond ((< pitch-octaves 0)
                               (string-concatenate
                                 (make-list (1- (abs pitch-octaves)) ",")))
                              ((= pitch-octaves 0) "'")
                              ((> pitch-octaves 0)
                               (string-concatenate
                                 (make-list (1+ (abs pitch-octaves)) "'")))))
                      (absolute-pitch-name
                        (string-append pitch-name-strg octave-sign)))
               (newline)
               (write pitch)
               (format #t "\t~a" absolute-pitch-name)
               mus))
             mus))
       music)
 
  music)
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\display-note-names
\relative c' {
c, cis d dis e f fis g gis a ais h c
cis d dis e f fis g gis a ais h c
cis d dis e f fis g gis a ais h c
h b a as g ges f e es d des c
\transpose c cis <c e g>
}
--- Ende Code ---
gestoßen und habe mir daran meine geistige Nase blutig geschlagen, wie ich pitch-name durch display-note-names in
--- Code: ---(assoc-get pitch-name pitch-markup-list)
--- Ende Code ---
ersetze.

Navigation

[0] Themen-Index

[#] Nächste Seite

[*] Vorherige Sete

Zur normalen Ansicht wechseln