lilypond-user
[Top][All Lists]
Advanced

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

Re: improving Janek's \dynamic function (for combo dynamics)


From: Thomas Morley
Subject: Re: improving Janek's \dynamic function (for combo dynamics)
Date: Sun, 27 Aug 2017 21:46:24 +0200

2017-08-27 11:56 GMT+02:00 David Kastrup <address@hidden>:

> I was more thinking along the lines of
>
> #(define-markup-command (dyn-test layout props strg) (markup?)
>   (define (fixstring arg)
>      (let ((res (fold-matches "\\{[^{}*\\}" arg '(0)
>              (lambda (m prev) ...
>   (define (fixtree arg)
>     (cond ((pair? arg) (cons (fixtree (car arg)) (fixtree (cdr arg))))
>           ((string? arg (fixstring arg)))
>           (else arg)))
>
> Uh, well, you get the drift.

I never really understood all the fold-xxx-procedures and I didn't
find much usage-examples for fold-matches apart from the trivial one
in the guile-manual.
Also, I'm not really familiar with reg-exp.
So, I'm afraid I'd need some further guidance.

That said, your reg-exp above, "\\{[^{}*\\}", seems not be valid. I
used: "\\{[^{}*]\\}" not sure whether it's really correct, tho'.

For now I did:

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

#(define (others number-pairs strg)
 (define (helper l1 l2)
   (if (null? (cdr l1))
       (reverse l2)
       (helper
         (cdr l1)
         (cons (cons (1+ (cdr (first l1))) (1- (car (second l1)))) l2))))
 (if (number-pair-list? number-pairs)
     (let* ((res (helper number-pairs '())))
       (append
         (cons
           (cons 0 (1- (car (first number-pairs))))
           res)
         (list (cons (1+ (cdr (last number-pairs))) (string-length strg)))))
     '()))

#(define (xy reg-exp strg)
 (let* ((possible-dyns
          (reverse
            (fold-matches reg-exp strg '()
                          (lambda (match prev)
                            (let* ((res-1 (vector-ref match 1))
                                   (res-2 (cons res-1 prev)))
                            res-2)))))
        (end-between-last
          (others possible-dyns strg)))
   (list
     "the following lists of pairs could be used to get substrings from strg"
     'possible-dynamics
     possible-dyns
     'others
     end-between-last)))

#(newline)
#(pretty-print
  (xy "\\{[^{}*]\\}" "poco {f}, but {p} sub. ma non troppo"))



displaying:


("the following lists of pairs could be used to get substrings from strg"
 possible-dynamics
 ((5 . 8) (14 . 17))
 others
 ((0 . 4) (9 . 13) (18 . 36)))

Is this the route to continue?


Cheers,
  Harm



reply via email to

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