lilypond-user
[Top][All Lists]
Advanced

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

Re: End of file event


From: Urs Liska
Subject: Re: End of file event
Date: Thu, 22 Feb 2018 08:23:48 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

Hi Maurits,


Am 22.02.2018 um 07:44 schrieb Maurits Lamers:
Hi, 

Thanks for your suggestion! Do I understand from your reply that you don't think there is a dynamic option, ie without adjusting the lilypond code being processed? 

To clarify the context a bit: what I am doing is reviewing homework by students. This means that I am running my reviewer script (lilypond file with embedded guile with event listeners) as a side-load script through the -dinclude-settings option on the lilypond code files they provided.
It is of course possible to preprocess the input files by appending such a scheme call (automatically). If I can have a dynamic option (such as listening to an event), I would rather like to have that option as it reduces the amount of things that can go wrong during processing.

I don't fully see how you're doing things, but would it be possible that instead of loading your "review code" through -dinclude-settings you could compile your own .ly file and *include* your students' code into that? If so, something along these lines could work:

\version ...
\include "my-review-lib.ily"

\book {
  \include "students-file.ly"
}

\writeStatistics

I have a function loadFile that may even let you specify the file to include through the command line:

% put this in your lib
loadFile =
#(define-void-function (target)(string?)
   (if (file-exists? target)
       (begin
        (let ((parser (ly:parser-clone)))
          (ly:parser-parse-string parser "\\language \"nederlands\"")
          (ly:parser-parse-string parser
            (format "\\include \"~a\""
              target)))
        (format #t "File ~q successfully loaded" target))
       (format #t "File ~a not found" target)))

\book {
  \loadFile #(ly:get-option 'filename)
}

Note that this doesn't respect the include path.

BTW this use-case sounds pretty interesting, it might be nice to share your thoughts about this when you got it to work.

HTH
Urs


cheers

Maurits


Hi Maurits,


Am 21.02.2018 um 20:52 schrieb Maurits Lamers:
Hi all,

I would like to execute some (embedded scheme) code at the end of an input file, that is after the last score block.

My current problem is that I am parsing score blocks, but some of the input is given as a single score block and the content in other files is put in many score blocks.
During my processing of this content I gather some statistics, and I would like to write them out to a file at the end of the file. In the current solution, I am running the export at the end of the finalize event on a score block, which of course causes the writing of the data to happen at the end of the parsing of every score block.

What would be the best way to only write out the statistics at the end of the file?

Can you somehow create an explicit \book{ } block?
Code after a book block will be executed after the PDF has been completely written, i.e. really after the score has been processed completely. But if you don't write that explicit \book block LilyPond will automatically wrap the whole document in one.

\version "2.19.80"

\book {
  \score {
    \new Staff { c' }
  }
}

#(ly:message "I'm executed after compilation")

You'll see from the log that the message is printed only after the PDF file has been finished.

HTH
Urs


Thanks in advance!

Maurits
_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user





_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user



reply via email to

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