Piero,

here's a new patch with randomization for the right side.
Again, it's a work in progress. 

In fact, there are 3 functions here.


1) use \rightTearFixed if you want the same tear-pattern
   consistently; set the pattern at the top of the file:
   rightTearFixedLengths = #'(0 1 3 4 2)

2) use \rightTearCustom if you want the set the tear-
   pattern on a case-to-case basis: 
   \rightTearCustom #'(0 1 2 3 4)

3) use \rightTearRandom to let the function come up with
   random tear-patterns on its own.

each of these can be abbreviated: \rTF, \rTC, \rTR.

Later I'll see if I can come up with a left-sided 
solution. Interestingly, a "double-sided" tear (with 
music on the left *and* right) would probably be easier
to implement. Let me know if you have any questions or
comments/suggestions. 

- Mark


      

<<attachment: torn-staves_3.png>>

\version "2.12.0"

rightTearWidth = #1
rightTearFixedLengths = #'(0 1 3 4 2)

rightTearGeneric =
  #(define-music-function (parser location lengths) (list?)
  #{
    #(define (x-ext n)
      (cons (* (list-ref $lengths n) (/ rightTearWidth 4)) rightTearWidth))
    #(define y-ext '(1.5 . 2.5))

    \once \override Staff.BarLine #'stencil = #ly:text-interface::print
    \once \override Staff.BarLine #'text = \markup
      \override #'(baseline-skip . 0) \with-color #white
      \column {
        \filled-box #(x-ext 0) #y-ext #0
        \filled-box #(x-ext 1) #y-ext #0
        \filled-box #(x-ext 2) #y-ext #0
        \filled-box #(x-ext 3) #y-ext #0
        \filled-box #(x-ext 4) #y-ext #0
      }
    \once \override Staff.BarLine #'layer = #1
    \once \override Staff.BarLine #'X-extent = #(cons 0 (- rightTearWidth 0.1))
    \break
  #} )

rightTearFixed =
  #(define-music-function (parser location) ()
  #{ \rightTearGeneric \rightTearFixedLengths #} )

rightTearCustom =
  #(define-music-function (parser location lengths) (list?)
  #{ \rightTearGeneric #$lengths #} )

rightTearRandom =
  #(define-music-function (parser location) ()
  #{ 
    \rightTearGeneric
      #(let loop ((unused '(0 1 2 3 4))
                  (lengths '()))
        (if (= (length lengths) 5)
            lengths
            (let* ((x (random (length unused)))
                   (y (- (length unused) x))
                   (z (list-ref unused x)))
             (loop (append (reverse (list-tail (reverse unused) y))
                           (list-tail unused (+ x 1)))
                   (append lengths `(,z))))))
  #} )

rTF = #rightTearFixed
rTC = #rightTearCustom
rTR = #rightTearRandom

\score {
  \relative {
    g'4 d' b d \rightTearFixed
    g,4 d' b d \rightTearCustom #'(0 1 2 3 4)
    g,4 d' b d \rightTearRandom

    %%using abbreviated forms:
    g,4 d' b d \rTF
    g,4 d' b d \rTC #'(0 1 2 3 4)
    g,4 d' b d \rTR
  }
  \layout {
    indent = #0
    ragged-right = ##t
  }
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to