Autor Thema: Variablen ohne Backslash?  (Gelesen 1815 mal)

stefanhuglfing

  • Member
Variablen ohne Backslash?
« am: Mittwoch, 26. März 2014, 06:23 »
Ich schreibe ein Stück für drei Singstimmen, bei dem die Sänger immer wieder die gleichen Akkorde singen, aber in anderen Rhytmen. Ich schreibe mit Hilfe von Variablen die Noten nur in den Sopran und Übertrage sie mit Copy und Paste in den Alt und Bass:

\version "2.18.0"

t = e
z = f
 
SopranNoten = 
 \relative c'
  {
    \t4 \z r2 \t4 \t \z2 \t2. \z8 r8
  } 

t = g
z = b
 
AltNoten = 
 \relative c' 
  {
   \t4 \z r2 \t4 \t \z2 \t2. \z8 r8
  }

t = c
z = g
 
MaennerNoten = 
 \relative c
  {
   \t4 \z r2 \t4 \t \z2 \t2. \z8 r8
  }
 

\score
 {
  <<
   
   \new ChoirStaff   
    <<     
     \new Staff 
      << 
       \new Voice = "first"
        {         
         \voiceOne
         \SopranNoten
        }     
 
       \new Voice = "second"
        {
         \voiceTwo 
         \AltNoten
        }       
      >>
   
     \new Staff
      <<     
       \new Voice
        {         
         \clef"F" 
         \MaennerNoten         
        } 
      >>
    >> 
  >>

  \layout { \context { \Staff } }
 }   

das finde ich praktisch. Nur stört mich, dass ich vor die Variablen immer einen Backslash schreiben muss.

Gibt es irgendwie eine (noch) schnellere Methode?

fugenkomponist

  • Member
Re: Variablen ohne Backslash?
« Antwort #1 am: Mittwoch, 26. März 2014, 09:29 »
Wenn du sowieso mit copy and paste arbeitest, warum schreibst du dann nicht einfach die Noten für den Sopran, kopierst sie in den Alt und ersetzt dann (nur) im Alt alle e durch g und alle f durch b?

stefanhuglfing

  • Member
Re: Variablen ohne Backslash?
« Antwort #2 am: Mittwoch, 26. März 2014, 09:36 »
mein Beispiel ist einfacher als das Stück, das ich wirklich schreiben möchte:

im richtigen Stück gibt es auch e's im Sopran, die im Alt durch andere Töne als c ersetzt werden müssen.

Ich kann noch ein ausführlicheres Beispiel nachliefern, aber im Moment bin ich unterwegs.

stefanhuglfing

  • Member
Re: Variablen ohne Backslash?
« Antwort #3 am: Mittwoch, 26. März 2014, 21:57 »
Hier kommt ein längeres Beispiel:

\version "2.18.0"

#(set-default-paper-size "a5")

h = b
j = a
k = g
l = c

t = c
z = b
u = a
i = g
o = fis
w = g
 
SopranNoten = 
 \relative c''
  {
   \h \breve \j4 \k \l \l \l2
   \l \breve \t4 \z \u \i \o \w2 \break
   \h \breve \j4 \k \l2
   \l4 \t \z \u \i \o \w2   
  } 

h = g
j = fis
k = e
l = e

t = fis
z = d
u = e
i = e
o = c
w = b
 
MezzoNoten = 
 \relative c''
  {
   \h \breve \j4 \k \l \l \l2
   \l \breve \t4 \z \u \i \o \w2 \break
   \h' \breve \j4 \k \l2
   \l4 \t \z \u \i \o \w2
  }

h = d
j = c
k = b
l = a

t = a
z = g
u = c
i = b
o = a
w = g
 
AltNoten = 
 \relative c'
  {
   \h \breve \j4 \k \l \l \l2
   \l \breve \t4 \z \u \i \o \w2 \break
   \h' \breve \j4 \k \l2
   \l4 \t \z \u \i \o \w2
  }
 

\score
 {
  <<
   
   \new ChoirStaff   
    <<     
     \new Staff 
      << 
       \new Voice = "first"
        {         
         \voiceOne
         \SopranNoten
        }     
 
       \new Voice = "second"
        {
         \voiceTwo 
         \MezzoNoten
        }       
      >>
   
     \new Staff
      <<     
       \new Voice
        {         
         \AltNoten         
        } 
      >>
    >> 
  >>

  \layout { \context { \Staff  \remove "Bar_engraver" line-width = #11115 } }
 }   


Das mit den Backslash-Zeichen bringe ich schon hin. Aber die Phrasen sind eigentlich noch länger; da gehen mir die Buchstaben aus. Das ganze finde ich irgendwie nicht zufriedenstellend.  Ich wünsche mir eigentlich eine elegante Lösung. Aber dafür mache ich ein neues Thema auf.

infranator

  • Member
Re: Variablen ohne Backslash?
« Antwort #4 am: Mittwoch, 26. März 2014, 22:34 »
Hi,

vielleicht ist ja eine der beiden Snippets aus dem LSR was für dich.
http://lsr.di.unimi.it/LSR/Search?q=extractNote

Mit extractNote könnte das z.B. so funktionieren:
\version "2.18.0"
#(set-default-paper-size "a5")



#(define-macro (add! lst elt)
   "Add element `elt to the list `lst."
   `(set! ,lst (append ,lst (list ,elt))))

#(define (noteEvent? music)
   (eq? (ly:music-property music 'name) 'NoteEvent))

#(define (no-duration? music)
   (not (ly:duration? (ly:music-property music 'duration))))

#(define (expand-q-chords music); for q chords : see chord-repetition-init.ly
   (expand-repeat-chords! (list 'rhythmic-event) music))

%%%%%%%%%%%%%%%%%%%%%%%%%%  extractNote  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#(define tagNotExtractNote (gensym))
#(use-modules (ice-9 receive)) %% for the use of receive
#(define (chord->note chord n . args)
   "Return the note n of one chord, keeping articulations.
Other numbers can be specified in args"
   (receive (notes others)
     (partition noteEvent? (ly:music-property chord 'elements))
     (if (null? notes)
         chord
         (let* ((len (length notes))
                (res (filter-map
                      (lambda(i)
                        (and (integer? i)
                             (<= i len)
                             (> i 0)
                             (list-ref notes (1- i)))) ; list-ref is zero-based
                      (cons n args)))
                (one-note (cond
                           ((null? res) (list-ref notes (1- len)))
                           ((null? (cdr res))(car res))
                           (else #f))))
           (if one-note
               (begin
                (ly:music-set-property! one-note 'articulations
                  (append (ly:music-property one-note 'articulations) others))
                one-note)
               (make-event-chord (append res others)))))))

#(define (extract-note music n . args)
   "Extract the note n of each chords in music, keeping articulations.
If other numbers are given in args, the function returns a chord build with all
matching notes. If no note matches, returns the last note of the chord."
   (map-some-music
    (lambda (evt)
      (cond
       ((eq? 'EventChord (ly:music-property evt 'name))
        (let ((tags (ly:music-property evt 'tags)))
          (if (memq tagNotExtractNote tags)
              (ly:music-set-property! evt 'tags ; only remove the tag
                (delq tagNotExtractNote tags))
              (set! evt (apply chord->note evt n args)))
          evt))
       (else (and (ly:music-property evt 'duration #f) evt))))
    (expand-q-chords music)))


%% TO DO : add a parameter optional pred?
extractNote = #(define-music-function (parser location n music )
                 (number? ly:music?)
                 (extract-note music n))



musik = {
  #(set-accidental-style 'forget)

  \cadenzaOn
  <b' g' d'>\breve
  <a' fis' c'>4 <g' e' b> <c'' e' a> q q2 q\breve
  <c'' fis' a>4 <b' d' g> <a' e' c'>
  <g' e' b> <fis' c' a> <g' b g>2
  \bar ""
  \break
  <b' g' d'>\breve
  <a' fis' c'>4 <g' e' b> <c'' e' a>2 q4
  <c'' fis' a> <b' d' g> <a' e' c'>
  <g' e' b> <fis' c' a> <g' b g>2
}


\score
{
  <<
   
    \new ChoirStaff   
    <<     
      \new Staff 
      << 
        \new Voice = "first"
        {         
          \voiceOne
          \extractNote 1 \musik
        }     
 
        \new Voice = "second"
        {
          \voiceTwo 
          \extractNote 2 \musik
        }       
      >>
   
      \new Staff
      <<     
        \new Voice
        {         
          \extractNote 3 \musik
        } 
      >>
    >> 
  >>
}   


stefanhuglfing

  • Member
Re: Variablen ohne Backslash?
« Antwort #5 am: Mittwoch, 26. März 2014, 22:42 »
nein das geht leider an meinem Ziel vorbei. Ich möchte Tipparbeit sparen indem ich ausnütze, dass immer wieder fast das gleiche vorkommt. Aber in deinem Beispiel muss man ja jede Note eintippen.