lilypond-user
[Top][All Lists]
Advanced

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

Re: Output to single PDF and multiple MIDI files


From: Thomas Morley
Subject: Re: Output to single PDF and multiple MIDI files
Date: Fri, 21 Jul 2017 12:04:44 +0200

2017-07-20 23:40 GMT+02:00 Jérôme Plût <address@hidden>:
> I am typesetting a multi-movement work. I want the paper output to be
> in a single file (say work.pdf) and the MIDI output to be in separate
> files (work-1.pdf, work-2.pdf). Is there a simple and local way to do
> this?


Hi Jérôme,

you've got some nice code already.
Here my own approach, trying to automate it even more:

\version "2.19.64"

#(define (string-list? x)
  (and (list? x) (every string? x)))

putOut =
#(define-void-function (restrict-ls suffixes scores)
  ((number-list? '()) (string-list? '()) list?)
"Puts out a book with all scores from @var{scores} and seperate midis for each
score of @var{scores}.

@var{restrict-ls} and @var{suffixes} are optional arguments.
If @var{restrict-ls} is set, a subset of @var{scores} is processed, the naming
of the midis will be consistent, i.e. if first and third score are processed,
midis are named filename-1.midi and filename-3.midi
If @var{suffixes} is set, use it for midi-naming, otherwise midis are named:
filename-1.midi, filename-2.midi, etc.
Note, if @var{suffixes} is set, @var{restrict-ls} needs to be set as well.
"
  (let* ((file-name (ly:parser-output-name))
         ;; Provides defaults if 'suffixes'-variable is not set.
         (suffixes
           (if (null? suffixes)
               (map number->string (iota (length scores) -1 -1))
               suffixes))
         ;; cherry-pick the desired scores or choose all if
         ;; 'restrict-ls'-variable is not set.
         (restrist-list-proc
           (lambda (lst)
             (if (null? restrict-ls)
                 lst
                 (map
                   (lambda (arg)
                     (if (> (1+ arg) (length lst))
                         (ly:error
                           "You tried to get a not existing score or suffix.")
                         (list-ref lst arg)))
                   restrict-ls)))))
    ;; put out a book (usually a pdf) with all scores returned by
    ;; 'restrist-list-proc'
    (ly:book-process
       (apply
         ly:make-book
         $defaultpaper
         $defaultheader
         (restrist-list-proc (reverse scores)))
       $defaultpaper
       $defaultlayout
       file-name)
    ;; put out midis in separate files.
    (for-each
      (lambda (bk bookSuffix)
        (ly:book-process bk $defaultpaper $defaultmidi
          (format #f "~a~a" (ly:parser-output-name) bookSuffix)))
        (map
          (lambda (score)
            (ly:make-book
              $defaultpaper
              $defaultheader
              score))
          (restrist-list-proc scores))
       (restrist-list-proc suffixes))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define variables
one = \relative { c'4 c c c }
two = \relative { c'4 d e f }
three = \relative { d'4 d' d' d' }

%% Define of scores
scoreI = \score { \one \header { opus = "opus 1" } }
scoreII = \score { \two \header { piece = "2. piece" } }
scoreIII = \score { \three \header { piece = "3. piece" } }

%% Put them in a list
scoreList =
#(list
  scoreI
  scoreII
  scoreIII
  )


%% Create the output
%% Examples

%% book-header, example
\header { title = "TITLE" }

%% book-layout, example
\layout {
  \context {
    \Voice
    \override NoteHead.color = #grey
  }
}

%% book-paper, example
\paper { indent = 0 }

%% book-midi, example
\midi {
  \tempo 4=200
}

%% Ofcourse different settings for layout/midi could be done while defining
%% scores above

%% 1
%{
%% Put out all, midis are named starting with filename-1.midi
\putOut \scoreList
%}

%% 2
%%{
%% Put out first and third score and the relevant midis
%% NB list-ref needs number 0 to catch the first argument of a list, etc
%% midis are named: filename-1.midi, filename-3.midi
\putOut #'(0 2) \scoreList
%}

%% 3
%{
%% Put out second and third score and the relevant midis
%% midis are named: filename-bar.midi, filename-buzz.midi
\putOut
  #'(1 2)
  #'("-foo" "-bar" "-buzz")
  \scoreList
%}


Cheers,
  Harm



reply via email to

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