lilypond-user
[Top][All Lists]
Advanced

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

Re: How to include a file just once?


From: Tim McNamara
Subject: Re: How to include a file just once?
Date: Thu, 21 Jan 2010 12:34:22 -0600


On Jan 21, 2010, at 11:47 AM, Michael J. O'Donnell wrote:

Is there a standard way to make sure that a file full of LilyPond style definitions is included just once, no matter how many times it is mentioned?

I searched the Web site, mail archives, and /usr/shar/lilypond for
"include once" and "include guard", to no avail. With the C
preprocessor, there is a standard trick for setting and testing a
variable to disable all but the first attempt to include a header file.
Some languages have an "include-once" command.

I am putting together a large choral score from bookparts for each
number in the work. I like to be able to produce either a single number, or the whole score. The natural approach is to include style definitions in each of the files that I might set, including the file to format the whole score and the files to format individual numbers. Files to format
individual numbers also include the style definitions.

I find that repeated inclusion of the same definitions leads quickly to
a segmentation fault.

I can either add one more level of indirection, with one more file per
number. Or, I can do some Scheme hacking, with a global variable to set
showing inclusion (tricky, because the variable needs to be testable
reliably even when it has never been set explicitly).

But, I'd prefer to use a well-known standard method, if it exists.

Without seeing your code, it's hard to tell what the problem is. When using \include to have a set of definitions, it is only necessary to do this once per .ly file. I put them up high in the file (pop-chords.ly is a chord exceptions file to prettify the way Lilypond writes jazz chords; paren-2.ly is a definition to be able to parenthesize optional chord names):

\version "2.12.2"

#(ly:set-option 'delete-intermediate-files #t)

\paper {
    indent = 0.0
    ragged-last = ##f

}

\header {
  title = "Recycling Day"
  subtitle = "Concert Pitch"
  composer = "McNamara"
  meter = "Up-Tempo Swing or Bebop"
  copyright = "Tim McNamara, All Rights Reserved"
}

\include "../../pop-chords.ly"
\include "../../paren-2.ly"



*********************************
Any bookparts would only contain what is below this line, so the \include command would not be repeated:
*********************************

harmonies = \chordmode {

Chords go here

}

melody = \relative c' {
\override Staff.TimeSignature #'style = #'()
\time 4/4
\clef treble
\key c \major

Melody goes here

}

\score {
  <<

    \new ChordNames {
      \set chordChanges = ##t
      \harmonies
    }
    \new Staff \melody
  >>

}





reply via email to

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