too.
+2004-05-28 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ * lily/parser.yy (output_def): push scope of parent_ Output_def
+ too.
+
2004-05-28 Jan Nieuwenhuizen <janneke@gnu.org>
* scm/output-gnome.scm: Update info.
2004-05-28 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/book-paper-def.cc: collapse Book_output_def to Output_def.
+
+ * scm/lily.scm (ly:modules-lookup): handle empty list, and more
+ than 1 module.
+
+ * lily/include/ly-module.hh (ly_use_module): rename is_module to
+ ly_c_module_p.
+
+ * scm/page-layout.scm (default-book-title): move Scheme titling
+ functions to here.
+
+ * lily/parser.yy (book_paper_block): remove scope too.
+
* ly/engraver-init.ly (EasyNotation): remove OrchestralScoreContext
* lily/rest.cc: add direction to rest properties.
\include "deutsch.ly"
#(set-global-staff-size 16)
+
\version "2.3.2"
\header {
/*
- book-paper-def.cc -- implement Book_output_def
+ book-paper-def.cc -- implement Output_def
source file of the GNU LilyPond music typesetter
#include "ly-module.hh"
#include "output-def.hh"
#include "dimensions.hh"
-#include "book-paper-def.hh"
#include "ly-smobs.icc"
#include "font-metric.hh"
#include "virtual-font-metric.hh"
#include "scaled-font-metric.hh"
-Book_output_def::Book_output_def ()
-{
- output_scale_ = 1.0;
- scaled_fonts_ = SCM_EOL;
- scaled_fonts_ = scm_c_make_hash_table (11);
-}
-
Real
-Book_output_def::output_scale () const
-{
- return output_scale_;
-}
-
-Book_output_def::Book_output_def (Book_output_def const & src)
- : Output_def (src)
+output_scale (Output_def * od)
{
- output_scale_ = src.output_scale_;
- scaled_fonts_ = SCM_EOL;
- scaled_fonts_ = scm_c_make_hash_table (11); // copying is not done with live defs. hopefully.
+ return ly_scm2double (od->lookup_variable (ly_symbol2scm ("outputscale")));
}
-void
-Book_output_def::derived_mark ()
-{
- scm_gc_mark (scaled_fonts_);
-}
-
-
-
+/*
+ TODO: should add nesting for Output_def here too.
+ */
Font_metric*
-Book_output_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name)
+find_scaled_font (Output_def * mod,
+ Font_metric *f, Real m, SCM input_enc_name)
{
+ if (mod->parent_)
+ {
+ return find_scaled_font (mod->parent_,
+ f, m, input_enc_name);
+ }
+
Real lookup_mag = m;
if (!dynamic_cast<Virtual_font_metric*> (f))
- lookup_mag /= output_scale ();
+ lookup_mag /= output_scale (mod);
+
+ SCM font_table = mod->lookup_variable (ly_symbol2scm ("scaled-fonts"));
+ if (scm_hash_table_p (font_table) != SCM_BOOL_T)
+ {
+ font_table = scm_c_make_hash_table (11);
+ mod->set_variable (ly_symbol2scm ("scaled-fonts"), font_table);
+ }
+
- SCM sizes = scm_hashq_ref (scaled_fonts_, f->self_scm (), SCM_BOOL_F);
+ SCM sizes = scm_hashq_ref (font_table, f->self_scm (), SCM_BOOL_F);
if (sizes != SCM_BOOL_F)
{
SCM met = scm_assoc (scm_make_real (lookup_mag), sizes);
SCM *t = &lst;
for (SCM s = vf->get_font_list (); ly_c_pair_p (s); s = ly_cdr (s))
{
- Font_metric *scaled = find_scaled_font (unsmob_metrics (ly_car (s)),
+ Font_metric *scaled = find_scaled_font (mod,
+ unsmob_metrics (ly_car (s)),
m, input_enc_name);
*t = scm_cons (scaled->self_scm (), SCM_EOL);
t = SCM_CDRLOC (*t);
{
if (!ly_c_symbol_p (input_enc_name))
{
- SCM var = ly_module_lookup (scope_, ly_symbol2scm ("inputencoding"));
+ SCM var = ly_module_lookup (mod->scope_, ly_symbol2scm ("inputencoding"));
if (var != SCM_BOOL_F)
input_enc_name = scm_variable_ref (var);
if (!ly_c_symbol_p (input_enc_name))
sizes = scm_acons (scm_make_real (lookup_mag), val, sizes);
scm_gc_unprotect_object (val);
- scm_hashq_set_x (scaled_fonts_, f->self_scm (), sizes);
+ scm_hashq_set_x (font_table, f->self_scm (), sizes);
return unsmob_metrics (val);
}
+/*
+ TODO: this is a nasty interface. During formatting,
+ the Output_def should be scaled to the output_scale_
+ specified in the toplevel Output_def.
+ */
Output_def*
-Book_output_def::scale_paper (Output_def *pd) const
+scale_output_def (Output_def * o, Real amount)
{
SCM proc = ly_scheme_function ("scale-paper");
- SCM new_pap = scm_call_2 (proc, pd->self_scm (), self_scm ());
-
+ SCM new_pap = scm_call_2 (proc, o->self_scm (),
+ scm_double2num (amount));
scm_gc_protect_object (new_pap);
- Output_def *p = unsmob_output_def (new_pap);
-
- p->parent_ = (Output_def*) this;
- return p;
-}
-
-LY_DEFINE (ly_make_bookpaper, "ly:make-bookpaper",
- 1, 0, 0,
- (SCM size),
- "Make a paperbook, for staff space SIZE, which is in INTERNAL_UNIT.")
-{
- Book_output_def *bp = new Book_output_def ;
-
- SCM_ASSERT_TYPE (ly_c_number_p (size), size,
- SCM_ARG1, __FUNCTION__, "number");
-
- bp->output_scale_ = (ly_scm2double (size)) MM;
-
- return scm_gc_unprotect_object (bp->self_scm ());
-}
-
-Book_output_def *
-unsmob_book_output_def (SCM bp)
-{
- return dynamic_cast<Book_output_def*> (unsmob_output_def (bp));
+ return unsmob_output_def (new_pap);
}
LY_DEFINE (ly_bookpaper_fonts, "ly:bookpaper-fonts",
(SCM bp),
"Return fonts scaled up BP")
{
- Book_output_def *b = unsmob_book_output_def (bp);
+ Output_def *b = unsmob_output_def (bp);
+
+ SCM font_table = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper");
- SCM func = ly_scheme_function ("hash-table->alist");
-
SCM ell = SCM_EOL;
- for (SCM s = scm_call_1 (func, b->scaled_fonts_); ly_c_pair_p (s);
- s = ly_cdr (s))
+ if (scm_hash_table_p (font_table) == SCM_BOOL_T)
{
- SCM entry = ly_car (s);
- for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t))
- {
- Font_metric *fm = unsmob_metrics (ly_cdar (t));
+ SCM func = ly_scheme_function ("hash-table->alist");
- if (dynamic_cast<Modified_font_metric*> (fm))
- ell = scm_cons (fm->self_scm (), ell);
+ for (SCM s = scm_call_1 (func, font_table); ly_c_pair_p (s);
+ s = ly_cdr (s))
+ {
+ SCM entry = ly_car (s);
+ for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t))
+ {
+ Font_metric *fm = unsmob_metrics (ly_cdar (t));
+
+ if (dynamic_cast<Modified_font_metric*> (fm))
+ ell = scm_cons (fm->self_scm (), ell);
+ }
}
}
return ell;
}
-
-
-LY_DEFINE (ly_bookpaper_outputscale, "ly:bookpaper-outputscale",
- 1, 0, 0,
- (SCM bp),
- "Get outputscale for BP.")
-{
- Book_output_def *b = unsmob_book_output_def (bp);
- SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper");
- return scm_make_real (b->output_scale_);
-}
-
-
-
-LY_DEFINE (ly_book_output_def_scope, "ly:bookpaper-def-scope",
- 1, 0,0, (SCM def),
- "Get the variable scope inside @var{def}.")
-{
- Book_output_def *op = unsmob_book_output_def (def);
- SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
- return op->scope_;
-}
#include <stdio.h>
-#include "book-paper-def.hh"
+
#include "ly-smobs.icc"
#include "stencil.hh"
#include "book.hh"
Book::process (String outname, Output_def *default_def, SCM header)
{
Paper_book *paper_book = new Paper_book ();
- paper_book->bookpaper_ = bookpaper_;
+
+
+ Real scale = ly_scm2double (bookpaper_->c_variable ("outputscale"));
+
+ Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale);
+
+ paper_book->bookpaper_ = scaled_bookdef;
int score_count = scores_.size ();
for (int i = 0; i < score_count; i++)
{
- Output_def *paper = 0;
SCM systems = scores_[i]->book_rendering (outname,
- bookpaper_,
- default_def, &paper);
+ paper_book->bookpaper_,
+ default_def);
if (systems != SCM_UNDEFINED)
{
Score_lines sc;
- sc.paper_ = paper;
sc.lines_ = systems;
sc.header_ = header;
paper_book->score_lines_.push (sc);
}
}
+
paper_book->output (outname);
+
+ scm_gc_unprotect_object (paper_book->bookpaper_->self_scm ());
scm_gc_unprotect_object (paper_book->self_scm ());
}
Book::to_stencil (Output_def *default_def, SCM header)
{
Paper_book *paper_book = new Paper_book ();
- paper_book->bookpaper_ = bookpaper_;
+ Real scale = ly_scm2double (bookpaper_->c_variable ("outputscale"));
+
+ Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale);
+
+ paper_book->bookpaper_ = scaled_bookdef;
+
int score_count = scores_.size ();
for (int i = 0; i < score_count; i++)
{
- Output_def *paper = 0;
SCM systems = scores_[i]->book_rendering ("<markup>",
bookpaper_,
- default_def,
- &paper);
+ default_def);
+
if (systems != SCM_UNDEFINED)
{
Score_lines sc;
- sc.paper_ = paper;
sc.lines_ = systems;
sc.header_ =header;
progress_indication (_f ("paper output to `%s'...", "<markup>"));
return (unsmob_page (ly_car (pages)))->to_stencil ().smobbed_copy ();
}
+
+ scm_gc_unprotect_object (paper_book->bookpaper_->self_scm ());
+
return SCM_EOL;
}
#include <math.h>
-#include "book-paper-def.hh"
+
#include "all-font-metrics.hh"
#include "output-def.hh"
#include "font-interface.hh"
}
Font_metric *fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector, i)));
- return dynamic_cast<Book_output_def*> (paper->parent_)
- // ugh.
- ->find_scaled_font (fm, requested / size, input_encoding_name);
+ return
+ find_scaled_font (paper, fm, requested / size, input_encoding_name);
}
Font_metric * fm = all_fonts_global->find_font (ly_scm2string (name));
- return dynamic_cast<Book_output_def*> (paper->parent_)
- ->find_scaled_font (fm, rmag, encoding_name);
+ return find_scaled_font (paper, fm, rmag, encoding_name);
}
else if (scm_instance_p (name))
{
/*
- book-paper-def.hh -- declare Book_output_def
+ book-paper-def.hh -- declare Output_def
source file of the GNU LilyPond music typesetter
#include "lily-proto.hh"
#include "output-def.hh"
-class Book_output_def : public Output_def
+class Output_def : public Output_def
{
public:
- VIRTUAL_COPY_CONSTRUCTOR (Output_def, Book_output_def);
- Book_output_def (Book_output_def const &);
- SCM scaled_fonts_;
- Real output_scale_;
- Real output_scale () const;
+ VIRTUAL_COPY_CONSTRUCTOR (Output_def, Output_def);
+ Output_def (Output_def const &);
- Book_output_def ();
+ Output_def ();
virtual void derived_mark ();
- Font_metric *find_scaled_font (Font_metric *f, Real m, SCM input_enc_name);
- Output_def *scale_paper (Output_def *pd) const;
};
-Book_output_def *unsmob_book_output_def (SCM bp);
-
#endif /* BOOK_PAPER_DEF_HH */
public:
SCM header_;
- Book_output_def *bookpaper_;
+ Output_def *bookpaper_;
Link_array<Score> scores_;
Book ();
class Bezier;
class Bezier_bow;
class Book;
-class Book_output_def;
+class Output_def;
class Break_algorithm;
class Change_iterator;
class Change_translator;
void ly_import_module (SCM dest, SCM src);
SCM ly_module_to_alist (SCM mod);
SCM ly_module_lookup (SCM module, SCM sym);
-SCM ly_modules_lookup (SCM modules, SCM sym);
+SCM ly_modules_lookup (SCM modules, SCM sym, SCM);
SCM ly_module_symbols (SCM mod);
void ly_reexport_module (SCM mod);
-inline bool is_module (SCM x) { return SCM_MODULEP(x); }
+inline bool ly_c_module_p (SCM x) { return SCM_MODULEP(x); }
void ly_clear_anonymous_modules ();
SCM ly_use_module (SCM mod, SCM used);
Output_def *get_paper (My_lily_parser *parser);
Output_def *get_midi (My_lily_parser *parser);
-Book_output_def *get_bookpaper (My_lily_parser *parser);
+Output_def *get_bookpaper (My_lily_parser *parser);
#endif /* MY_LILY_PARSER_HH */
DECLARE_UNSMOB (Output_def, output_def);
+
+Font_metric *find_scaled_font (Output_def * od,
+ Font_metric *f, Real m, SCM input_enc_name);
+Output_def *scale_output_def (Output_def *def, Real scale);
+Real output_scale (Output_def*);
+
#endif /* MUSIC_OUTPUT_DEF_HH */
public:
Output_def *paper_; // todo: make private?
- Book_output_def * bookpaper () const;
+ Output_def * bookpaper () const;
static int page_count_;
static Real MIN_COVERAGE_;
int number_;
{
SCM lines_;
SCM header_;
- SCM global_header_;
- Output_def *paper_;
Score_lines () ;
void gc_mark ();
- SCM scopes ();
};
class Paper_book
Real height_;
SCM copyright_;
SCM tagline_;
+ SCM global_header_;
public:
Array<Score_lines> score_lines_;
- Book_output_def *bookpaper_;
-
+ Output_def *bookpaper_;
+
Paper_book ();
SCM lines ();
SCM pages ();
- SCM scopes (int);
Stencil title (int);
void classic_output (String);
void init ();
Score ();
Score (Score const&);
- SCM book_rendering (String, Book_output_def*, Output_def*, Output_def**);
+ SCM book_rendering (String, Output_def*, Output_def*);
};
DECLARE_UNSMOB (Score, score);
return scm_cons (scm_cons (key, scm_variable_ref (val)), result);
}
-SCM
-ly_module_to_alist (SCM mod)
+LY_DEFINE(ly_module_to_alist, "ly:module->alist",
+ 1,0,0, (SCM mod),
+ "Dump the contents of module @var{mod} as an alist.")
{
SCM_VALIDATE_MODULE (1, mod);
-
-
SCM obarr= SCM_MODULE_OBARRAY (mod);
return scm_internal_hash_fold ((Hash_cl_func) &entry_to_alist, NULL, SCM_EOL, obarr);
Lookup SYM in a list of modules, which do not have to be related.
Return the first instance.
*/
-SCM
-ly_modules_lookup (SCM modules, SCM sym)
+LY_DEFINE(ly_modules_lookup, "ly:modules-lookup",
+ 2, 1, 0,
+ (SCM modules, SCM sym, SCM def),
+ "Lookup @var{sym} in the list @var{modules}, returning the "
+ "first occurence. If not found, return @var{default}, or @code{#f}.")
{
- for (SCM s = ly_car (modules); SCM_MODULEP (s); s = ly_cdr (s))
+ for (SCM s = modules; SCM_MODULEP (s); s = ly_cdr (s))
{
- SCM v = scm_sym2var (sym, scm_module_lookup_closure (s), SCM_UNDEFINED);
- if (v != SCM_UNDEFINED)
- return v;
+ SCM mod = ly_car (s);
+ SCM v = scm_sym2var (sym, scm_module_lookup_closure (mod), SCM_UNDEFINED);
+ if (SCM_VARIABLEP(v) && SCM_VARIABLE_REF(v) != SCM_UNDEFINED)
+ return SCM_VARIABLE_REF(v);
}
- return SCM_UNDEFINED;
-}
+ if (def != SCM_UNDEFINED)
+ return def;
+ else
+ return SCM_BOOL_F;
+}
void
ly_export (SCM module, SCM namelist)
+++ /dev/null
-/*
- music-output-def.cc -- implement Output_def
-
- source file of the GNU LilyPond music typesetter
-
- (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-#include "book-paper-def.hh"
-#include "context-def.hh"
-#include "file-path.hh"
-#include "global-context.hh"
-#include "lily-guile.hh"
-#include "ly-module.hh"
-#include "main.hh"
-#include "output-def.hh"
-#include "output-def.hh"
-#include "scm-hash.hh"
-#include "warn.hh"
-
-#include "ly-smobs.icc"
-
-Output_def::Output_def ()
-{
- scope_ = SCM_EOL;
- parent_ = 0;
- smobify_self ();
-
- scope_ = ly_make_anonymous_module (false);
-}
-
-Output_def::~Output_def ()
-{
-}
-
-Output_def::Output_def (Output_def const &s)
-{
- scope_ = SCM_EOL;
- parent_ = 0;
- smobify_self ();
-
- scope_= ly_make_anonymous_module (false);
- if (is_module (s.scope_))
- ly_import_module (scope_, s.scope_);
-}
-
-
-IMPLEMENT_SMOBS (Output_def);
-IMPLEMENT_DEFAULT_EQUAL_P (Output_def);
-
-
-SCM
-Output_def::mark_smob (SCM m)
-{
- Output_def * mo = (Output_def*) SCM_CELL_WORD_1 (m);
-
- /*
- FIXME: why is this necessary?
- all bookpaper_ should be protected by themselves.
- */
- if (mo->parent_)
- scm_gc_mark (mo->parent_->self_scm ());
-
-
- mo->derived_mark ();
- return mo->scope_;
-}
-
-void
-Output_def::derived_mark () {}
-
-void
-assign_context_def (Output_def * m, SCM transdef)
-{
- Context_def *tp = unsmob_context_def (transdef);
- assert (tp);
-
- if (tp)
- {
- SCM sym = tp->get_context_name ();
- scm_module_define (m->scope_, sym, transdef);
- }
-}
-
-/*
- find the translator for NAME. NAME must be a symbol.
-*/
-SCM
-find_context_def (Output_def const *m, SCM name)
-{
- Context_def *cd = unsmob_context_def (m->lookup_variable (name));
- return cd ? cd->self_scm () : SCM_EOL;
-}
-
-int
-Output_def::print_smob (SCM s, SCM p, scm_print_state *)
-{
- Output_def * def = unsmob_output_def (s);
- scm_puts ("#< ", p);
- scm_puts (classname (def), p);
-
- (void)def;
- scm_puts (">", p);
- return 1;
-}
-
-Real
-Output_def::get_dimension (SCM s) const
-{
- SCM val = lookup_variable (s);
- return ly_scm2double (val);
-}
-
-
-SCM
-Output_def::lookup_variable (SCM sym) const
-{
- SCM var = ly_module_lookup (scope_, sym);
- if (SCM_VARIABLEP (var))
- return SCM_VARIABLE_REF (var);
-
- if (parent_)
- return parent_->lookup_variable (sym);
-
- return SCM_EOL;
-}
-
-SCM
-Output_def::c_variable (String s) const
-{
- return lookup_variable (ly_symbol2scm (s.to_str0 ()));
-}
-
-void
-Output_def::set_variable (SCM sym, SCM val)
-{
- scm_module_define (scope_, sym, val);
-}
-
-LY_DEFINE (ly_paper_lookup, "ly:output-def-lookup",
- 2, 0, 0, (SCM pap, SCM sym),
- "Lookup @var{sym} in @var{pap}. "
- "Return the value or @code{'()} if undefined.")
-{
- Output_def *op = unsmob_output_def (pap);
- SCM_ASSERT_TYPE (op, pap, SCM_ARG1, __FUNCTION__, "Output_def");
- SCM_ASSERT_TYPE (ly_c_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
-
- return op->lookup_variable (sym);
-}
-
-LY_DEFINE (ly_output_def_scope, "ly:output-def-scope",
- 1, 0,0, (SCM def),
- "Get the variable scope inside @var{def}.")
-{
- Output_def *op = unsmob_output_def (def);
- SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
- return op->scope_;
-}
-
-
-LY_DEFINE (ly_output_def_parent, "ly:output-def-parent",
- 1, 0, 0, (SCM def),
- "Get the parent output-def of @var{def}.")
-{
- Output_def *op = unsmob_output_def (def);
- SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
- return op->parent_ ? op->parent_->self_scm () : SCM_EOL;
-}
-
-
-LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
- 1, 0, 0, (SCM def),
- "Clone @var{def}.")
-{
- Output_def *op = unsmob_output_def (def);
- SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
- SCM s = op->clone ()->self_scm ();
- scm_gc_unprotect_object (s);
- return s;
-}
-
-LY_DEFINE(ly_output_description, "ly:output-description",
- 1,0,0,
- (SCM output_def),
- "Return the description of translators in @var{output-def}.")
-{
- Output_def *id = unsmob_output_def (output_def);
-
- SCM al =ly_module_to_alist (id->scope_);
-
- SCM l = SCM_EOL;
- for (SCM s = al ; ly_c_pair_p (s); s = ly_cdr (s))
- {
- Context_def * td = unsmob_context_def (ly_cdar (s));
- SCM key = ly_caar (s);
- if (td && key == td->get_context_name ())
- {
-
- l = scm_cons (scm_cons (key, td->to_alist ()), l);
- }
- }
- return l;
-}
-
-
-
-#include "interval.hh"
-
-/* FIXME. This is broken until we have a generic way of
- putting lists inside the \paper block. */
-Interval
-line_dimensions_int (Output_def *def, int n)
-{
- Real lw = def->get_dimension (ly_symbol2scm ("linewidth"));
- Real ind = n ? 0.0 : def->get_dimension (ly_symbol2scm ("indent"));
-
- return Interval (ind, lw);
-}
-
-LY_DEFINE (ly_paper_def_p, "ly:paper-def?",
- 1, 0, 0, (SCM def),
- "Is @var{def} a paper definition?")
-{
- return ly_bool2scm (unsmob_output_def (def));
-}
*/
#include "book.hh"
-#include "book-paper-def.hh"
+
#include "file-name.hh"
#include "file-path.hh"
#include "lily-version.hh"
Output_def *paper = unsmob_output_def (id);
paper = paper ? paper->clone () : new Output_def;
paper->set_variable (ly_symbol2scm ("is-paper"), SCM_BOOL_T);
+
+ paper->parent_ =unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultbookpaper"));
return paper;
}
}
-Book_output_def*
+Output_def*
get_bookpaper (My_lily_parser *parser)
{
SCM id = parser->lexer_->lookup_identifier ("$defaultbookpaper");
- Book_output_def *paper = unsmob_book_output_def (id);
+ Output_def *paper = unsmob_output_def (id);
- paper = paper ? dynamic_cast<Book_output_def*> (paper->clone ()) : new Book_output_def;
+ paper = paper ? dynamic_cast<Output_def*> (paper->clone ()) : new Output_def;
paper->set_variable (ly_symbol2scm ("is-bookpaper"), SCM_BOOL_T);
return paper;
}
SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser");
SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score");
- SCM header = is_module (score->header_) ? score->header_
+ SCM header = ly_c_module_p (score->header_) ? score->header_
: parser->header_.to_SCM ();
File_name outname (parser->output_basename_);
(*c)++;
SCM os = scm_makfrom0str (outname.to_string ().to_str0 ());
+ SCM bookpaper = get_bookpaper (parser)->self_scm ();
for (int i = 0; i < score->defs_.size (); i++)
default_rendering (score->music_, score->defs_[i]->self_scm (),
- get_bookpaper (parser)->self_scm (),
+ bookpaper,
header, os);
if (score->defs_.is_empty ())
{
My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
Book *book = unsmob_book (book_smob);
- Book_output_def *bp = unsmob_book_output_def (parser->lexer_->lookup_identifier ("$defaultbookpaper"));
+ Output_def *bp = unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultbookpaper"));
SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond parser");
SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book");
if (*c)
outname.base_ += "-" + to_string (*c);
(*c)++;
+
Output_def *paper = get_paper (parser);
+
book->process (outname.to_string (), paper, header);
+
scm_gc_unprotect_object (paper->self_scm ());
return SCM_UNDEFINED;
}
--- /dev/null
+/*
+ music-output-def.cc -- implement Output_def
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+
+#include "context-def.hh"
+#include "file-path.hh"
+#include "global-context.hh"
+#include "lily-guile.hh"
+#include "ly-module.hh"
+#include "main.hh"
+#include "output-def.hh"
+#include "output-def.hh"
+#include "scm-hash.hh"
+#include "warn.hh"
+
+#include "ly-smobs.icc"
+
+Output_def::Output_def ()
+{
+ scope_ = SCM_EOL;
+ parent_ = 0;
+ smobify_self ();
+
+ scope_ = ly_make_anonymous_module (false);
+}
+
+Output_def::~Output_def ()
+{
+}
+
+Output_def::Output_def (Output_def const &s)
+{
+ scope_ = SCM_EOL;
+ parent_ = 0;
+ smobify_self ();
+
+ input_origin_ = s.input_origin_;
+ scope_= ly_make_anonymous_module (false);
+ if (ly_c_module_p (s.scope_))
+ ly_import_module (scope_, s.scope_);
+}
+
+
+IMPLEMENT_SMOBS (Output_def);
+IMPLEMENT_DEFAULT_EQUAL_P (Output_def);
+
+
+SCM
+Output_def::mark_smob (SCM m)
+{
+ Output_def * mo = (Output_def*) SCM_CELL_WORD_1 (m);
+
+ /*
+ FIXME: why is this necessary?
+ all bookpaper_ should be protected by themselves.
+ */
+ if (mo->parent_)
+ scm_gc_mark (mo->parent_->self_scm ());
+
+
+ mo->derived_mark ();
+ return mo->scope_;
+}
+
+void
+Output_def::derived_mark () {}
+
+void
+assign_context_def (Output_def * m, SCM transdef)
+{
+ Context_def *tp = unsmob_context_def (transdef);
+ assert (tp);
+
+ if (tp)
+ {
+ SCM sym = tp->get_context_name ();
+ scm_module_define (m->scope_, sym, transdef);
+ }
+}
+
+/*
+ find the translator for NAME. NAME must be a symbol.
+*/
+SCM
+find_context_def (Output_def const *m, SCM name)
+{
+ Context_def *cd = unsmob_context_def (m->lookup_variable (name));
+ return cd ? cd->self_scm () : SCM_EOL;
+}
+
+int
+Output_def::print_smob (SCM s, SCM p, scm_print_state *)
+{
+ Output_def * def = unsmob_output_def (s);
+ scm_puts ("#< ", p);
+ scm_puts (classname (def), p);
+
+ (void)def;
+ scm_puts (">", p);
+ return 1;
+}
+
+Real
+Output_def::get_dimension (SCM s) const
+{
+ SCM val = lookup_variable (s);
+ return ly_scm2double (val);
+}
+
+
+SCM
+Output_def::lookup_variable (SCM sym) const
+{
+ SCM var = ly_module_lookup (scope_, sym);
+ if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF(var) != SCM_UNDEFINED)
+ return SCM_VARIABLE_REF (var);
+
+ if (parent_)
+ return parent_->lookup_variable (sym);
+
+ return SCM_EOL;
+}
+
+SCM
+Output_def::c_variable (String s) const
+{
+ return lookup_variable (ly_symbol2scm (s.to_str0 ()));
+}
+
+void
+Output_def::set_variable (SCM sym, SCM val)
+{
+ scm_module_define (scope_, sym, val);
+}
+
+LY_DEFINE (ly_paper_lookup, "ly:output-def-lookup",
+ 2, 0, 0, (SCM pap, SCM sym),
+ "Lookup @var{sym} in @var{pap}. "
+ "Return the value or @code{'()} if undefined.")
+{
+ Output_def *op = unsmob_output_def (pap);
+ SCM_ASSERT_TYPE (op, pap, SCM_ARG1, __FUNCTION__, "Output_def");
+ SCM_ASSERT_TYPE (ly_c_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
+
+ return op->lookup_variable (sym);
+}
+
+LY_DEFINE (ly_output_def_scope, "ly:output-def-scope",
+ 1, 0,0, (SCM def),
+ "Get the variable scope inside @var{def}.")
+{
+ Output_def *op = unsmob_output_def (def);
+ SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
+ return op->scope_;
+}
+
+
+LY_DEFINE (ly_output_def_parent, "ly:output-def-parent",
+ 1, 0, 0, (SCM def),
+ "Get the parent output-def of @var{def}.")
+{
+ Output_def *op = unsmob_output_def (def);
+ SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
+ return op->parent_ ? op->parent_->self_scm () : SCM_EOL;
+}
+
+
+LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
+ 1, 0, 0, (SCM def),
+ "Clone @var{def}.")
+{
+ Output_def *op = unsmob_output_def (def);
+ SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
+ SCM s = op->clone ()->self_scm ();
+ scm_gc_unprotect_object (s);
+ return s;
+}
+
+LY_DEFINE(ly_output_description, "ly:output-description",
+ 1,0,0,
+ (SCM output_def),
+ "Return the description of translators in @var{output-def}.")
+{
+ Output_def *id = unsmob_output_def (output_def);
+
+ SCM al =ly_module_to_alist (id->scope_);
+
+ SCM l = SCM_EOL;
+ for (SCM s = al ; ly_c_pair_p (s); s = ly_cdr (s))
+ {
+ Context_def * td = unsmob_context_def (ly_cdar (s));
+ SCM key = ly_caar (s);
+ if (td && key == td->get_context_name ())
+ {
+
+ l = scm_cons (scm_cons (key, td->to_alist ()), l);
+ }
+ }
+ return l;
+}
+
+
+
+#include "interval.hh"
+
+/* FIXME. This is broken until we have a generic way of
+ putting lists inside the \paper block. */
+Interval
+line_dimensions_int (Output_def *def, int n)
+{
+ Real lw = def->get_dimension (ly_symbol2scm ("linewidth"));
+ Real ind = n ? 0.0 : def->get_dimension (ly_symbol2scm ("indent"));
+
+ return Interval (ind, lw);
+}
+
+LY_DEFINE (ly_paper_def_p, "ly:paper-def?",
+ 1, 0, 0, (SCM def),
+ "Is @var{def} a paper definition?")
+{
+ return ly_bool2scm (unsmob_output_def (def));
+}
+
+
+
+LY_DEFINE (ly_bookpaper_outputscale, "ly:bookpaper-outputscale",
+ 1, 0, 0,
+ (SCM bp),
+ "Get outputscale for BP.")
+{
+ Output_def *b = unsmob_output_def (bp);
+ SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper");
+ return scm_make_real (output_scale (b));
+}
+
+
+
+LY_DEFINE (ly_make_output_def, "ly:make-output-def",
+ 0, 0, 0, (),
+ "Make a output def.")
+{
+ Output_def *bp = new Output_def ;
+ return scm_gc_unprotect_object (bp->self_scm ());
+}
+
#include "paper-line.hh"
#include "stencil.hh"
#include "warn.hh"
-#include "book-paper-def.hh"
+
int Page::page_count_ = 0;
Real Page::MIN_COVERAGE_ = 0.66;
-Book_output_def *
-Page::bookpaper () const
-{
- return dynamic_cast<Book_output_def*> ( paper_->parent_);
-}
-
Page::Page (Output_def *paper, int number)
{
copyright_ = SCM_EOL;
if (p->paper_)
{
scm_gc_mark (p->paper_->self_scm ());
- if (p->bookpaper ())
- {
- scm_gc_mark (p->bookpaper ()->self_scm ());
- }
}
scm_gc_mark (p->copyright_);
#include "paper-score.hh"
#include "stencil.hh"
#include "warn.hh"
-#include "book-paper-def.hh"
+
// JUNKME
SCM
{
copyright_ = SCM_EOL;
tagline_ = SCM_EOL;
+ global_header_ = SCM_EOL;
+
bookpaper_ = 0;
smobify_self ();
}
scm_gc_mark (b->copyright_);
if (b->bookpaper_)
scm_gc_mark (b->bookpaper_->self_scm ());
-
+ scm_gc_mark (b->global_header_);
return b->tagline_;
}
return 1;
}
+
+/*
+ TODO: there is too much code dup, and the interface is not
+ clear. FIXME.
+ */
+
void
Paper_book::output (String outname)
{
/* Generate all stencils to trigger font loads. */
SCM pages = this->pages ();
- Output_def *paper = score_lines_[0].paper_;
Paper_outputter *out = get_paper_outputter (outname);
int page_count = scm_ilength (pages);
- out->output_header (paper->parent_, scopes (0), page_count, false);
+ out->output_header (bookpaper_, global_header_, page_count, false);
for (SCM s = pages; s != SCM_EOL; s = ly_cdr (s))
{
progress_indication ("\n");
}
-SCM
-Paper_book::scopes (int i)
-{
- return score_lines_[i].scopes ();
-}
-
Stencil
Paper_book::title (int i)
: ly_symbol2scm ("scoreTitle"));
Stencil title;
- SCM scopes = this->scopes (i);
- SCM s = ly_modules_lookup (scopes, field);
- if (s != SCM_UNDEFINED && scm_variable_bound_p (s) == SCM_BOOL_T)
+
+ // ugh code dup
+ SCM scopes = SCM_EOL;
+ if (ly_c_module_p (global_header_))
+ scopes = scm_cons (global_header_, scopes);
+
+ if (ly_c_module_p (score_lines_[i].header_))
+ scopes = scm_cons (score_lines_[i].header_, scopes);
+ //end ugh
+
+ SCM s = ly_modules_lookup (scopes, field, SCM_BOOL_F);
+ if (s != SCM_BOOL_F)
title = *unsmob_stencil (scm_call_2 (user_title,
- score_lines_[0].paper_->self_scm (),
- scm_variable_ref (s)));
+ bookpaper_->self_scm (),
+ s));
else
title = *unsmob_stencil (scm_call_2 (i == 0 ? book_title : score_title,
- score_lines_[0].paper_->self_scm (),
- scopes));
+ bookpaper_->self_scm (),
+ scopes));
if (!title.is_empty ())
title.align_to (Y_AXIS, UP);
void
Paper_book::classic_output (String outname)
{
- int count = score_lines_.size ();
Paper_outputter *out = get_paper_outputter (outname);
- Output_def * p = score_lines_.top ().paper_;
+ Output_def * p = bookpaper_;
while (p && p->parent_)
p = p->parent_;
+
+ // ugh code dup
+ SCM scopes = SCM_EOL;
+ if (ly_c_module_p (global_header_))
+ scopes = scm_cons (global_header_, scopes);
+
+ if (ly_c_module_p (score_lines_[0].header_))
+ scopes = scm_cons (score_lines_[0].header_, scopes);
+ //end ugh
- out->output_header (p, scopes (count - 1), 0, true);
+ out->output_header (p, global_header_, 0, true);
SCM top_lines = score_lines_.top ().lines_;
Paper_line *first = unsmob_paper_line (scm_vector_ref (top_lines,
}
}
- Output_def *paper = score_lines_[0].paper_;
- SCM scopes = this->scopes (0);
+ Output_def *paper = bookpaper_;
+
+ SCM scopes = SCM_EOL;
+ if (ly_c_module_p (global_header_))
+ scopes = scm_cons (global_header_, scopes);
SCM make_tagline = paper->c_variable ("make-tagline");
tagline_ = scm_call_2 (make_tagline, paper->self_scm (), scopes);
{
init ();
Page::page_count_ = 0;
- Output_def *paper = score_lines_[0].paper_;
+
+ Output_def *paper = bookpaper_;
Page *page = new Page (paper, 1);
Real text_height = page->text_height ();
Score_lines::Score_lines ()
{
lines_ = SCM_EOL;
- global_header_ = SCM_EOL;
header_ = SCM_EOL;
- paper_ = 0;
}
void
Score_lines::gc_mark ()
{
scm_gc_mark (lines_);
- scm_gc_mark (global_header_);
scm_gc_mark (header_);
- if (paper_)
- scm_gc_mark (paper_->self_scm ());
}
-
-SCM
-Score_lines::scopes ()
-{
- SCM scopes = SCM_EOL;
- if (header_)
- scopes = scm_cons (header_, scopes);
- if (SCM_MODULEP(global_header_)
- && global_header_ != header_)
- scopes = scm_cons (global_header_, scopes);
-
- return scopes;
-}
Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
{
is_title_ = is_title;
+ number_ = 0;
penalty_ = penalty;
smobify_self ();
Paper_line *p = (Paper_line*) ly_cdr (smob);
scm_puts ("#<", port);
scm_puts (classname (p), port);
+ scm_puts (" ", port);
scm_puts (to_string (p->number_).to_str0 (), port);
if (p->is_title ())
scm_puts (" t", port);
#include <math.h>
#include <time.h>
-#include "book-paper-def.hh"
+
#include "array.hh"
#include "dimensions.hh"
#include "font-metric.hh"
#include "book.hh"
-#include "book-paper-def.hh"
+
#include "context-def.hh"
#include "dimensions.hh"
#include "event.hh"
%union {
Book *book;
- Book_output_def *bookpaper;
Output_def *outputdef;
SCM scm;
String *string;
%type <scm> markup markup_line markup_list markup_list_body full_markup
%type <book> book_block book_body
-%type <bookpaper> book_paper_head book_paper_block book_paper_body
+%type <outputdef> book_paper_head book_paper_block book_paper_body
%type <i> exclamations questions dots optional_rest
%type <i> bass_mod
}
| output_def {
SCM id = SCM_EOL;
+ Output_def * od = $1;
+
if ($1->c_variable ("is-paper") == SCM_BOOL_T)
id = ly_symbol2scm ("$defaultpaper");
else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
id = ly_symbol2scm ("$defaultmidi");
- else if ($1->c_variable ("is-book-paper") == SCM_BOOL_T)
+ else if ($1->c_variable ("is-bookpaper") == SCM_BOOL_T)
id = ly_symbol2scm ("$defaultbookpaper");
- THIS->lexer_->set_identifier (id, $1->self_scm ());
- scm_gc_unprotect_object ($1->self_scm ());
+ THIS->lexer_->set_identifier (id, od->self_scm ());
+ scm_gc_unprotect_object (od->self_scm ());
}
| book_paper_block {
THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultbookpaper"), $1->self_scm ());
book_paper_block:
book_paper_body '}' {
$$ = $1;
+ THIS->lexer_->remove_scope ();
}
;
book_paper_head:
BOOKPAPER '{' {
$$ = get_bookpaper (THIS);
+ $$->input_origin_ = THIS->here_input ();
THIS->lexer_->add_scope ($$->scope_);
}
;
{
$$ = new Book;
$$->set_spot (THIS->here_input ());
- $$->bookpaper_ = dynamic_cast<Book_output_def*> (unsmob_book_output_def (THIS->lexer_->lookup_identifier ("$defaultbookpaper"))->clone ());
+ $$->bookpaper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultbookpaper"))->clone ());
scm_gc_unprotect_object ($$->bookpaper_->self_scm ());
}
| book_body book_paper_block {
output_def:
music_output_def_body '}' {
$$ = $1;
+ if ($1->parent_)
+ THIS->lexer_->remove_scope ();
+
THIS->lexer_->remove_scope ();
THIS->lexer_->pop_state ();
}
| PAPER {
Output_def* p = get_paper (THIS);
+ if (p->parent_)
+ THIS->lexer_->add_scope (p->parent_->scope_);
THIS->lexer_->add_scope (p->scope_);
$$ = p;
music_output_def_body:
music_output_def_head '{' {
$$ = $1;
- $$->input_origin_. set_spot (THIS->here_input ());
+ $$->input_origin_.set_spot (THIS->here_input ());
THIS->lexer_->push_initial_state ();
}
| music_output_def_head '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
#include <stdio.h>
#include "book.hh"
-#include "book-paper-def.hh"
+
#include "cpu-timer.hh"
#include "global-context.hh"
#include "ly-module.hh"
defs_.push (s.defs_[i]->clone ());
header_ = ly_make_anonymous_module (false);
- if (is_module (s.header_))
+ if (ly_c_module_p (s.header_))
ly_import_module (header_, s.header_);
}
SCM book_outputdef,
SCM header, SCM outname)
{
- Book_output_def *bpd = unsmob_book_output_def (book_outputdef);
- if (bpd && unsmob_output_def (outdef))
- /* FIXME: memory leak */
- outdef = bpd->scale_paper (unsmob_output_def (outdef))->self_scm ();
+ SCM scaled_def = outdef;
+ SCM scaled_bookdef = book_outputdef;
+
+ Output_def *bpd = unsmob_output_def (book_outputdef);
+
+ /*
+ ugh.
+ */
+ if (bpd->c_variable ("is-bookpaper") == SCM_BOOL_T)
+ {
+ Real scale = ly_scm2double (bpd->c_variable ("outputscale"));
+
+ Output_def * def = scale_output_def (unsmob_output_def (outdef), scale);
+ scaled_def = def->self_scm ();
+
+ scaled_bookdef = scale_output_def (bpd, scale)->self_scm ();
+ unsmob_output_def (scaled_def)->parent_ = unsmob_output_def (scaled_bookdef);
+
+ scm_gc_unprotect_object (scaled_bookdef);
+ scm_gc_unprotect_object (scaled_def);
+ }
- SCM context = ly_run_translator (music, outdef);
+ SCM context = ly_run_translator (music, scaled_def);
if (Global_context *g = dynamic_cast<Global_context*>
(unsmob_context (context)))
if (systems != SCM_UNDEFINED)
{
Paper_book *paper_book = new Paper_book ();
- Paper_score *ps = dynamic_cast<Paper_score*> (output);
+ paper_book->bookpaper_ = unsmob_output_def (scaled_bookdef);
+
Score_lines sc;
- sc.paper_ = ps->paper_;
sc.lines_ = systems;
sc.header_ = header;
}
delete output;
}
+
+ scm_remember_upto_here_1 (scaled_def);
+ scm_remember_upto_here_1 (scaled_bookdef);
}
-
+
+/*
+ PAPERBOOK should be scaled already.
+ */
SCM
Score::book_rendering (String outname,
- Book_output_def* paperbook,
- Output_def *default_def,
- Output_def **paper)
+ Output_def *paperbook,
+ Output_def *default_def)
{
+ SCM scaled_bookdef = SCM_EOL;
+ Real scale = 1.0;
+
+ if (paperbook && paperbook->c_variable ("is-bookpaper") == SCM_BOOL_T)
+ {
+ scale = ly_scm2double (paperbook->c_variable ("outputscale"));
+ }
+
SCM out = scm_makfrom0str (outname.to_str0 ());
SCM systems = SCM_EOL;
int outdef_count = defs_.size ();
for (int i = 0; !i || i < outdef_count; i++)
{
Output_def *def = outdef_count ? defs_[i] : default_def;
- if (Output_def * pd = dynamic_cast<Output_def*> (def))
+ SCM scaled= SCM_EOL;
+ if (def->c_variable ("is-paper") == SCM_BOOL_T)
{
- def = paperbook->scale_paper (pd);
+ def = scale_output_def (def, scale);
+ def->parent_ = paperbook;
+ scaled = def->self_scm ();
+ scm_gc_unprotect_object (scaled);
}
if (!(no_paper_global_b && dynamic_cast<Output_def*> (def)))
{
SCM context = ly_run_translator (music_, def->self_scm ());
- if (Global_context *g = dynamic_cast<Global_context*>
- (unsmob_context (context)))
+ if (dynamic_cast<Global_context*> (unsmob_context (context)))
{
SCM s = ly_format_output (context, out);
if (s != SCM_UNDEFINED)
{
systems = s;
- /* Ugh. */
- Music_output *output = g->get_output ();
- if (Paper_score *ps = dynamic_cast<Paper_score*> (output))
- *paper = ps->paper_;
}
}
}
+
+ scm_remember_upto_here_1 (scaled);
}
+
+ scm_remember_upto_here_1 (scaled_bookdef);
return systems;
}
\version "2.3.2"
\bookpaper {
-#(define-public is-bookpaper #t)
-
-#(define-public (book-title paper scopes)
- "Generate book title from header strings."
-
- (define (get sym)
- (let ((x (ly:modules-lookup scopes sym)))
- (if (and x (not (unspecified? x))) x "")))
-
- (let ((props (page-properties paper)))
+ unit = #(ly:unit)
+ mm = 1.0
+ in = 25.4
+ pt = #(/ in 72.27)
+ cm = #(* 10 mm)
+
+ inputencoding = #"TeX"
- (interpret-markup
- paper props
- (markup
- #:column
- (#:override '(baseline-skip . 4)
- #:column
- (#:fill-line
- (#:normalsize (get 'dedication))
- #:fill-line
- (#:huge #:bigger #:bigger #:bigger #:bigger #:bold (get 'title))
- #:override '(baseline-skip . 3)
- #:column
- (#:fill-line
- (#:large #:bigger #:bigger #:bold (get 'subtitle))
- #:fill-line (#:bigger #:bigger #:bold (get 'subsubtitle)))
- #:override '(baseline-skip . 5)
- #:column ("")
- #:override '(baseline-skip . 2.5)
- #:column
- (#:fill-line
- (#:bigger (get 'poet) #:large #:bigger #:caps (get 'composer))
- #:fill-line (#:bigger (get 'texttranslator) #:bigger (get 'opus))
- #:fill-line
- (#:bigger (get 'meter) #:bigger (get 'arranger))
- ""
- #:fill-line (#:large #:bigger (get 'instrument))
- " "
- #:fill-line (#:large #:bigger #:caps (get 'piece) ""))))))))
+ %
+ % 20pt staff, 5 pt = 1.75 mm
+ %
-#(define-public (user-title paper markup)
- "Generate book title from header markup."
- (if (markup? markup)
- (let ((props (page-properties paper))
- (baseline-skip (chain-assoc-get 'baseline-skip props 2)) )
- (stack-lines DOWN 0 BASELINE-SKIP
- (list (interpret-markup paper props markup))))))
+ outputscale = #1.7573
+
+ #(define-public score-title default-score-title)
+ #(define-public user-title default-user-title)
+ #(define-public book-title default-book-title)
-#(define-public (score-title paper scopes)
- "Generate score title from header strings."
-
- (define (get sym)
- (let ((x (ly:modules-lookup scopes sym)))
- (if (and x (not (unspecified? x))) x "")))
-
- (let ((props (page-properties paper)))
+ %
+ % ugh. hard coded?
+ %
- (interpret-markup
- paper props
- (markup
- #:column
- (#:override '(baseline-skip . 4)
- #:column
- (#:fill-line
- ("" (get 'opus))
- #:fill-line (#:large #:bigger #:caps (get 'piece) "")))))))
+ #(paper-set-staff-size (* 20.0 pt))
papersize = "a4"
+ #(define font-defaults
+ '((font-encoding . fetaMusic)))
+
+ #(define text-font-defaults
+ '((font-encoding . latin1)
+ (baseline-skip . 2)
+ (word-space . 0.6)))
+
+ #(define page-breaking ly:ragged-page-breaks)
+ %%#(define page-breaking ly:optimal-page-breaks)
+
+ #(define page-to-stencil ly:page-header-lines-footer-stencil)
+
+ #(define make-header plain-header)
+ #(define make-footer plain-footer)
+ %%#(define make-footer empty-markup)
+ #(define make-tagline TAGLINE-or-tagline-from-header)
+ #(define make-copyright copyright-from-header)
+
}
% ugh
\include "midi-init.ly"
+\include "book-paper-defaults.ly"
-% Do units first; must be done before any units are specified.
\paper {
- unit = #(ly:unit)
- mm = 1.0
- in = 25.4
+ mm = #(ly:output-def-lookup $defaultbookpaper 'mm)
+ unit = #(ly:output-def-lookup $defaultbookpaper 'unit)
+
+ in = #(* 25.4 mm)
pt = #(/ in 72.27)
cm = #(* 10 mm)
-
- inputencoding = #"TeX"
- raggedright = ##f
- raggedlast = ##f
- packed = ##f
- #(define $is-paper #t)
-
- #(define font-defaults
- '((font-encoding . fetaMusic)))
-
- #(define text-font-defaults
- '((font-encoding . latin1)
- (baseline-skip . 2)
- (word-space . 0.6)))
-
- #(define page-breaking ly:ragged-page-breaks)
- %%#(define page-breaking ly:optimal-page-breaks)
-
- #(define page-to-stencil ly:page-header-lines-footer-stencil)
-
- #(define make-header plain-header)
- #(define make-footer plain-footer)
- %%#(define make-footer empty-markup)
- #(define make-tagline TAGLINE-or-tagline-from-header)
- #(define make-copyright copyright-from-header)
-
\include "engraver-init.ly"
}
-%
-% 20pt staff, 5 pt = 1.75 mm
-%
-
-#(define-public $defaultbookpaper (ly:make-bookpaper 1.7573))
-
-\include "book-paper-defaults.ly"
#(set-default-paper-size "a4")
-%{
-
-; note:
-; you can add fonts manually in the paper block by issuing
-#(set! fonts (append ...myfonts... fonts))
+%{
-for the format of myfonts, see font.scm
+%% these would supercede defaults in \bookpaper.
+% let's comment this out for now.
-%}
paperEleven = \paper {
#(paper-set-staff-size (* 11.0 pt))
\paper { \paperTwenty }
+%}
+
partCombineListener = \paper {
\context {
\Voice
\grobdescriptions #all-grob-descriptions
}
-%
-% setup for Request->Element conversion. Guru-only
-%
-
\context {
\type "Engraver_group_engraver"
\name Staff
verticalExtent = ##f
localKeySignature = #'()
createSpacing = ##t
+
% explicitly set instrument, so we don't get
% weird effects when doing instrument names for
% piano staves
(define-public default-toplevel-score-handler print-score-as-book)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; Unassorted utility functions.
-
-
-;; modules
-(define-public (ly:modules-lookup modules sym)
- "DOCME."
- (let ((v (module-variable (car modules) sym)))
- (if (and v (variable-bound? v) (variable-ref v))
- (variable-ref v)
- (if (module? (cdr modules)) (ly:modules-lookup (cdr modules) sym)))))
-
;;;;;;;;;;;;;;;;
; alist
"define-grobs.scm"
"define-grob-interfaces.scm"
"page-layout.scm"
+
"paper.scm"
; last:
(number->string (exact->inexact
(ly:bookpaper-outputscale bookpaper))))
(tex-string-def "lilypondpapersize" 'papersize
- (eval 'papersize (ly:bookpaper-def-scope bookpaper)))
+ (eval 'papersize (ly:output-def-scope bookpaper)))
+
(apply string-append
(map (lambda (x) (font-load-command bookpaper x))
(ly:bookpaper-fonts bookpaper)
- )))
- )
+ ))))
+
(define (unknown)
"%\n\\unknown\n")
;; TODO: if solution is bad return no breaks and revert to
;; ragged bottom
(list->vector breaks)))
+
+
+
+;;;;;;;;;;;;;;;;;;
+; titling.
+(define-public (default-book-title paper scopes)
+ "Generate book title from header strings."
+
+ (define (get sym)
+ (let ((x (ly:modules-lookup scopes sym)))
+ (if (and x (not (unspecified? x))) x "")))
+
+ (let ((props (page-properties paper)))
+
+ (interpret-markup
+ paper props
+ (markup
+ #:column
+ (#:override '(baseline-skip . 4)
+ #:column
+ (#:fill-line
+ (#:normalsize (get 'dedication))
+ #:fill-line
+ (#:huge #:bigger #:bigger #:bigger #:bigger #:bold (get 'title))
+ #:override '(baseline-skip . 3)
+ #:column
+ (#:fill-line
+ (#:large #:bigger #:bigger #:bold (get 'subtitle))
+ #:fill-line (#:bigger #:bigger #:bold (get 'subsubtitle)))
+ #:override '(baseline-skip . 5)
+ #:column ("")
+ #:override '(baseline-skip . 2.5)
+ #:column
+ (#:fill-line
+ (#:bigger (get 'poet) #:large #:bigger #:caps (get 'composer))
+ #:fill-line (#:bigger (get 'texttranslator) #:bigger (get 'opus))
+ #:fill-line
+ (#:bigger (get 'meter) #:bigger (get 'arranger))
+ ""
+ #:fill-line (#:large #:bigger (get 'instrument))
+ " "
+ #:fill-line (#:large #:bigger #:caps (get 'piece) ""))))))))
+
+(define-public (default-user-title paper markup)
+ "Generate book title from header markup."
+ (if (markup? markup)
+ (let ((props (page-properties paper))
+ (baseline-skip (chain-assoc-get 'baseline-skip props 2)) )
+ (stack-lines DOWN 0 BASELINE-SKIP
+ (list (interpret-markup paper props markup))))))
+
+(define-public (default-score-title paper scopes)
+ "Generate score title from header strings."
+
+ (define (get sym)
+ (let ((x (ly:modules-lookup scopes sym)))
+ (if (and x (not (unspecified? x))) x "")))
+
+ (let ((props (page-properties paper)))
+
+ (interpret-markup
+ paper props
+ (markup
+ #:column
+ (#:override '(baseline-skip . 4)
+ #:column
+ (#:fill-line
+ ("" (get 'opus))
+ #:fill-line (#:large #:bigger #:caps (get 'piece) "")))))))
(ss (/ sz 4))
(pt (eval 'pt m))
(mm (eval 'mm m)))
-
+
+ (module-define! m 'outputscale ss)
(module-define! m 'fonts (make-cmr-tree (/ sz (* 20 pt))))
(module-define! m 'staffheight sz)
(module-define! m 'staff-space ss)
(module-define! m 'staffspace ss)
-
;; !! synchronize with feta-params.mf
(module-define! m 'linethickness (+ (* 0.3 pt) (* 0.04 ss)))
(module-define! m 'ledgerlinethickness (+ (* 0.5 pt) (/ ss 10)))
(define-public (set-global-staff-size sz)
"Set the default staff size, where SZ is thought to be in PT."
(let* ((old-mod (current-module))
- (pap (eval '$defaultpaper old-mod))
- (is-paper? (module-defined? old-mod '$defaultpaper))
-
+ (pap (eval '$defaultbookpaper old-mod))
+ (in-paper? (or (module-defined? old-mod 'is-bookpaper)
+ (module-defined? old-mod 'is-paper)))
- ;; Huh? Why is it necessary to clone object?
+ ; maybe not necessary.
+ ; but let's be paranoid. Maybe someone still refers to the
+ ; old one.
(new-paper (ly:output-def-clone pap))
+
(new-scope (ly:output-def-scope new-paper)))
- (if (not is-paper?)
+
+ (if in-paper?
(ly:warn "Not in toplevel scope"))
(set-current-module new-scope)
(paper-set-staff-size (* sz (eval 'pt new-scope)))
(set-current-module old-mod)
- (module-define! old-mod '$defaultpaper new-paper)))
+ (module-define! old-mod '$defaultbookpaper new-paper)))
(define paper-alist
'(("a6" . (cons (* 105 mm) (* 148.95 mm)))
(define (internal-set-paper-size module name)
(let* ((entry (assoc name paper-alist))
- (is-paper? (module-defined? module '$is-paper))
+ (is-bookpaper? (module-defined? module 'is-bookpaper))
(mm (eval 'mm module)))
(cond
- ((not is-paper?)
+ ((not is-bookpaper?)
(ly:warning "This is not a \\paper {} object:")
(display module))
((pair? entry)
))
(define-public (set-default-paper-size name)
- (internal-set-paper-size (ly:output-def-scope (eval '$defaultpaper (current-module)))
+ (internal-set-paper-size (ly:output-def-scope (eval '$defaultbookpaper (current-module)))
name))
(define-public (set-paper-size name)
- (if (module-defined? (current-module) '$is-paper)
+ (if (module-defined? (current-module) 'is-paper)
(internal-set-paper-size (current-module) name)
;;; TODO: should raise (generic) exception with throw, and catch
;;; that in parse-scm.cc
(ly:warn "Must use #(set-paper-size .. ) within \\paper { ... }")))
-(define-public (scale-paper pap bookpap)
+(define-public (scale-paper pap scale)
(let*
- ((scale (ly:bookpaper-outputscale bookpap))
- (new-pap (ly:output-def-clone pap))
+ ((new-pap (ly:output-def-clone pap))
(dim-vars (ly:output-def-lookup pap 'dimension-variables))
(scope (ly:output-def-scope new-pap)))
(for-each
(lambda (v)
- (module-define! scope v
- (/ (ly:output-def-lookup pap v) scale)))
+ (define val (ly:output-def-lookup pap v))
+ (if (number? val)
+ (module-define! scope v
+ (/ val scale))
+
+ ;; spurious warnings, eg. for hsize, vsize.
+; (ly:warn (format "not a number, ~S = ~S " v val))
+ ))
dim-vars)