help-source-highlight
[Top][All Lists]
Advanced

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

Re: [Help-source-highlight] regexp for scheme blocks in lilypond languag


From: Federico Bruni
Subject: Re: [Help-source-highlight] regexp for scheme blocks in lilypond language
Date: Wed, 18 Jan 2012 23:55:02 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111222 Thunderbird/9.0.1

Il 18/01/2012 10:01, Lorenzo Bettini ha scritto:
On 18/01/2012 09:54, Federico Bruni wrote:
Hi,

lilypond files can contain blocks of scheme code in several ways.
The main challenge is handling conflicts between single and multiline
and especially blocks where the number of parentheses cannot be known in
advance (there's a way to match balanced parentheses?).

Hi

very quick answer: you can match balanced parenthesis using 'nested'
(see the documentation);


Thanks, this should be the direction, but it's not so easy.
First, the doc says:

"Note that, in order for a delimited language element to be nested, its starting and ending elements must be different"

I may be wrong, but I would add: they also have to be specular.
In my case delimiters are not specular.
Start delimiter: #(
End delimiter: )

I can't consider just parenthesis for two reasons:

- I want to highlight # as well
- ( and ) have also a different meaning (slurs) in lilypond synthax and must be highlighted differently

So this doesn't work:
scheme_block delim "(" ")" multiline nested

I wrote this but it doesn't work correctly:

scheme_block delim '(?<!#)\(' '\)' multiline nested

The most external () block is omitted and slurs higlighting is broken (see file attached).

What do you recommend to do?

Thanks,
Federico
\version "2.14.2"
% Scheme big block: currently commented out because lilypond.lang
% can't handle it.
#(define (naturalize-pitch p)
   (let ((o (ly:pitch-octave p))
         (a (* 4 (ly:pitch-alteration p)))
         ;; alteration, a, in quarter tone steps,
         ;; for historical reasons
         (n (ly:pitch-notename p)))
     (cond
      ((and (> a 1) (or (eq? n 6) (eq? n 2)))
       (set! a (- a 2))
       (set! n (+ n 1)))
      ((and (< a -1) (or (eq? n 0) (eq? n 3)))
       (set! a (+ a 2))
       (set! n (- n 1))))
     (cond
      ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
      ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
     (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
     (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
     (ly:make-pitch o n (/ a 4))))
%}
\header {
  title = "Maple Leaf Rag"
  composer = "Scott Joplin"
  piece = "Tempo di marcia"
}

\paper {
  top-margin = 15
  bottom-margin = 10
  system-system-spacing #'padding = #8
  score-system-spacing =
    #'((basic-distance . 12)
       (minimum-distance . 6)
       (padding . 1)
       (stretchability . 12))
}

top =  \relative c' {
 \override TextScript   #'padding = #2
 
 \key as \major
 \time 2/4
 \clef treble
 \partial 8
 r8 \f |
 \repeat volta 2 {
  r16 as' <es' es,> as, c <es es,>8 g,16 |
  <es' es,>16 g, bes <es es,> ~ <es es,>4 |
  r16 as, <es' es,> as, c <es es,>8 g,16 |
  <es' es,>16 g, bes <es es,> ~ <es es,>8 r16 <es es,> |
  r16 as, ces <fes fes,> r16 <es es,> r16 <es es,> |
  r16 as, ces <fes fes,> r16 <es es,> r8 |
  \change Staff = "down"
   \stemUp r16^\p as,,,-( ces as'-) r as-( ces as'-) \stemNeutral |
  \change Staff = "up"
  r16 as-( ces as'-) r as-( ces as'-) |
  }
}

bottom =  \relative c {
 \key as \major
 \time 2/4
 \clef bass
 \partial 8
 <es es,>8 |
 \repeat volta 2 {
  <as as,> <c as es> <c as es> <a a,> |
  <bes bes,> <des g, es> <des g, es> <es, es,> |
  <as as,> <c as es> <c as es> <a a,> |
  <bes bes,> <des g, es> <des g, es> <es, es,> |
  <fes fes,>4 <es es,>8 <es es,> |
  <fes fes,>4 <es es,>8 r |
  \stemDown as,, r as' r \stemNeutral |
  as' r as' r \clef treble |
  }
}

\score {
  \context PianoStaff <<
  \context Staff = "up"
   \applyMusic #unfold-repeats \top 
  \context Staff = "down"
   \applyMusic #unfold-repeats \bottom
 >>
 
  \midi {
    \context {
      \Score tempoWholesPerMinute = #(ly:make-moment 120 4)
    }
    \context {
      \Voice
      \remove Dynamic_performer
    }
  }
  \layout{}
}

reply via email to

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