denemo-devel
[Top][All Lists]
Advanced

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

Re: [Denemo-devel] Bookpart scripts


From: Richard Shann
Subject: Re: [Denemo-devel] Bookpart scripts
Date: Sun, 15 May 2016 09:30:57 +0100

On Sat, 2016-05-14 at 22:18 +0200, Andreas Schneider wrote:
> Thank you. The corresponding piece to close the { from StartBookpart is
> EndBookpart (see code below). Do you think those two should be coupled
> in some way?

yes. There are several approaches you could take. The simplest would be
to use a single tag, "BookPart" say, for both the start and end. (I'm
assuming that these are always disjoint, that is you can have 

{ .... }{...}...
but not
{.. { ...}} ...

for example.

In this case you would test if there was a bookpart start on the current
movement with

(if (d-DirectiveGet-movementcontrol-prefix "BookPart")


and you would test if there was a bookpart end with


(if (d-DirectiveGet-movementcontrol-postfix "BookPart")


and, of course, there may be both. (This works because of Scheme's
concept of true and false).

The other thing you would use is

(d-GoToPosition movement-number)

which takes the cursor to the movement 1, 2 ... you give.

The command "BookPart" would then ask for the end movement number and
install the start and end movementcontrol directives. thus:

(d-PushPosition) ;;;saves the current cursor position
(d-DirectivePut-movementcontrol-prefix tag bookpartstart)
(d-GoToPosition end-movement-number)
(d-DirectivePut-movementcontrol-postfix tag bookpartend)
(d-PopPosition)

The tricky bit comes with toggling this off again. It would be possible
to store the end movement number in the scheme data field, but that's
perhaps not worth doing since we can step forward one movement at a time
and find it:

(while (and (d-NextMovement) (not (d-DirectiveGet-movementcontrol-postfix 
tag))))

and then either remove the postfix (if there is also a prefix, ie start book 
part)
or delete it altogether:

        (if (d-DirectiveGet-movementcontrol-postfix tag)
                (if (d-DirectiveGet-movementcontrol-prefix tag) 
                                (d-DirectivePut-movementcontrol-postfix tag "")
                                (d-DirectiveDelete-movementcontrol tag))
                (d-WarningDialog (_ "No book part end")))

I'm not sure how much Scheme you know, so ask if this is not enough guidance...
(This is just typed out here off the top of my head, so watch for typos!)

Richard




> 
> Andreas
> 
> 
> ;;;EndBookpart
> (let ((tag "EndBookpart"))
>   (if (d-Directive-movementcontrol? tag)
>   (begin
>     (disp (string-append "Deleting directive " tag "."))
>     (d-DirectiveDelete-movementcontrol tag))
>   (begin
>     ;; or create it if it doesn't exist
>     (disp (string-append "Creating directive " tag "."))
>     (d-DirectivePut-movementcontrol-override tag (logior
> DENEMO_OVERRIDE_GRAPHIC DENEMO_OVERRIDE_TAGEDIT))
>     (d-DirectivePut-movementcontrol-postfix tag "\n} %end of bookpart\n")
>     (d-SetSaved #f))))
> 
> 
> Am 14.05.2016 um 21:09 schrieb Richard Shann:
> > Here I take out the scheme-escape and the eval-string and this will be
> > ok I think (for eval-string to work you would have to have saved the
> > string with " " around it, so that guile would evaluate it and get a
> > string. That is, what you pass to eval-string should be what you would
> > type at a guile prompt to get it to read the data type you want it to
> > get, in this case what you would want is for it to read the data and
> > evaluate it to result in a string). I think this will be ok (it is on
> > Debian, I can check out that Windows is ok with it).
> > 
> > On its own it is a dangerous command since it doesn't place the } after
> > the last movement in the bookpart, so the LilyPond becomes
> > un-typesettable. If I understand correctly what you want I think you
> > will need to ask for the Movement number where the book part should end
> > and then set the } on that (you would need to go to that movement set
> > the } in place and then return the cursor to the where you started
> > d-PushPosition and d-PopPosition for that).
> > 
> > Richard
> > oh - and I've moved the ))) into the conventional places for a piece of
> > Scheme code.
> > 
> > ;;;StartBookpart
> > (let ((tag "StartBookpart")(thetitle ""))
> >   (d-DirectivePut-movementcontrol-override tag (logior
> > DENEMO_OVERRIDE_GRAPHIC DENEMO_OVERRIDE_TAGEDIT))
> >   (disp "checking previous bookpart title ...")
> >   (if (d-Directive-movementcontrol? tag)
> >     (set! thetitle (d-DirectiveGet-movementcontrol-data tag)))
> >   (set! thetitle (d-GetUserInputWithSnippets (_ "Start Bookpart")(_
> > "Give chapter title::") thetitle))
> >   (if thetitle
> >       (begin
> >         (set! thetitle (car thetitle))
> >         (if (zero? (string-length thetitle)) ;; if empty title string 
> > =>delete the directive
> >                 (begin
> >                   (disp (string-append "Deleting directive " tag "."))
> >                   (d-DirectiveDelete-movementcontrol tag)
> >                   (d-SetSaved #f))
> >                 (begin
> >                   (disp thetitle)
> >                   (d-DirectivePut-movementcontrol-data tag  thetitle)
> >                   (d-DirectivePut-movementcontrol-prefix tag (string-append 
> > "\\bookpart { %start of bookpart\n  \\header {\n    title = \\markup { "
> >                                     thetitle " }\n  }\n"))
> >           (d-SetSaved #f))))
> >         (d-InfoDialog "Cancelled")))
> > 
> 





reply via email to

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