* lily/score.cc (book_rendering): New method.
(default_rendering): Create Paper_book helper locally, dump
output.
* lily/my-lily-lexer.cc (the_key_tab): Add book.
* lily/parser.yy: Handle \book.
* lily/include/book.hh:
* lily/book.cc: New file.
+2004-04-10 Jan Nieuwenhuizen <janneke@gnu.org>
+
+ * lily/input-file-results.cc (do_one_file): Remove Paper_book hack.
+
+ * lily/score.cc (book_rendering): New method.
+ (default_rendering): Create Paper_book helper locally, dump
+ output.
+
+ * lily/my-lily-lexer.cc (the_key_tab): Add book.
+
+ * lily/parser.yy: Handle \book.
+
+ * lily/include/book.hh:
+ * lily/book.cc: New file.
+
2004-04-10 Han-Wen Nienhuys <hanwen@xs4all.nl>
* lily/text-item.cc (interpret_string): new file, select font with
--- /dev/null
+/*
+ book.cc -- implement Book
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#include <stdio.h>
+
+#include "ly-smobs.icc"
+
+#include "book.hh"
+#include "global-context.hh"
+#include "ly-module.hh"
+#include "input-file-results.hh"
+#include "main.hh"
+#include "music-iterator.hh"
+#include "music-output-def.hh"
+#include "music-output.hh"
+#include "music.hh"
+#include "paper-book.hh"
+#include "paper-def.hh"
+#include "score.hh"
+#include "warn.hh"
+
+Book::Book ()
+ : Input ()
+{
+ header_ = SCM_EOL;
+ smobify_self ();
+}
+
+#if 0
+Book::Book (Book const &src)
+ : Input (src)
+{
+ header_ = SCM_EOL;
+ smobify_self ();
+
+ int score_count = src.scores_.size ();
+ for (int i = 0; i < score_count; i++)
+ scores_.push (src.scores_[i]->clone ());
+
+#if 0
+ header_ = ly_make_anonymous_module ();
+ if (is_module (src.header_))
+ ly_import_module (header_, src.header_);
+#endif
+}
+#endif
+
+Book::~Book ()
+{
+}
+
+IMPLEMENT_SMOBS (Book);
+IMPLEMENT_DEFAULT_EQUAL_P (Book);
+
+SCM
+Book::mark_smob (SCM s)
+{
+ Book *book = (Book*) SCM_CELL_WORD_1 (s);
+ int score_count = book->scores_.size ();
+ for (int i = 0; i < score_count; i++)
+ scm_gc_mark (book->scores_[i]->self_scm ());
+ return book->header_;
+}
+
+int
+Book::print_smob (SCM, SCM p, scm_print_state*)
+{
+ scm_puts ("#<Book>", p);
+ return 1;
+}
+
+void
+Book::process (String outname, Music_output_def *default_def, SCM header)
+{
+ Paper_book *paper_book = new Paper_book ();
+ int score_count = scores_.size ();
+ for (int i = 0; i < score_count; i++)
+ {
+ Paper_def *paper = 0;
+ SCM systems = scores_[i]->book_rendering (outname, default_def, &paper);
+ if (systems != SCM_UNDEFINED)
+ {
+ if (paper)
+ paper_book->papers_.push (paper);
+ paper_book->scores_.push (systems);
+ paper_book->global_headers_.push (global_input_file->header_);
+ paper_book->headers_.push (scores_[i]->header_);
+ }
+ }
+ paper_book->output (outname);
+ scm_gc_unprotect_object (paper_book->self_scm ());
+}
--- /dev/null
+/*
+ book.hh -- declare Book
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#ifndef BOOK_HH
+#define BOOK_HH
+
+#include "input.hh"
+#include "lily-proto.hh"
+
+#include "parray.hh"
+#include "smobs.hh"
+
+class Book : public Input
+{
+ DECLARE_SMOBS (Book, foo);
+
+public:
+ SCM header_;
+ Link_array<Score> scores_;
+
+ Book ();
+ Book (Book const&);
+ void process (String outname, Music_output_def*, SCM header);
+};
+DECLARE_UNSMOB (Book,book);
+
+#endif /* BOOK_HH */
*/
-#ifndef TRANSLATOR_DEF_HH
-#define TRANSLATOR_DEF_HH
+#ifndef CONTEXT_DEF_HH
+#define CONTEXT_DEF_HH
#include "lily-proto.hh"
#include "smobs.hh"
void add_context_mod (SCM);
SCM default_child_context_name ();
SCM get_context_name () const;
- SCM get_accepted (SCM) const;
- SCM get_property_ops () const { return property_ops_; }
+ SCM get_accepted (SCM) const;
+ SCM get_property_ops () const { return property_ops_; }
SCM get_translator_names (SCM) const;
void set_acceptor (SCM accepts, bool add);
- Link_array<Context_def> path_to_acceptable_context (SCM type_string, Music_output_def* odef) const;
+ Link_array<Context_def> path_to_acceptable_context (SCM type_string,
+ Music_output_def*) const;
Context * instantiate (SCM extra_ops);
SCM to_alist () const;
- static SCM make_scm () ;
+ static SCM make_scm ();
+
+ SCM clone_scm () const;
+ void apply_default_property_operations (Context*);
- SCM clone_scm ()const;
- void apply_default_property_operations (Context *);
private:
- DECLARE_SMOBS (Context_def,foo);
+ DECLARE_SMOBS (Context_def, foo);
Context_def ();
Context_def (Context_def const&);
};
-DECLARE_UNSMOB(Context_def,context_def);
-
+DECLARE_UNSMOB (Context_def, context_def);
-#endif /* TRANSLATOR_DEF_HH */
+#endif /* CONTEXT_DEF_HH */
Array<String> target_strings_;
Protected_scm header_;
+ int book_count_;
int score_count_;
void do_deps (String);
class Beaming_info_list;
class Bezier;
class Bezier_bow;
+class Book;
class Break_algorithm;
class Change_iterator;
class Change_translator;
extern File_path global_path;
extern int score_count_global;
-extern Paper_book *paper_book;
-
#endif /* MAIN_HH */
(c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
-
-#ifndef Music_output_DEF_HH
-#define Music_output_DEF_HH
+#ifndef MUSIC_OUTPUT_DEF_HH
+#define MUSIC_OUTPUT_DEF_HH
#include "string.hh"
#include "lily-proto.hh"
DECLARE_SMOBS (Music_output_def,);
};
-DECLARE_UNSMOB(Music_output_def,music_output_def);
-#endif // Music_output_DEF_HH
+DECLARE_UNSMOB (Music_output_def, music_output_def);
+
+#endif /* MUSIC_OUTPUT_DEF_HH */
#ifndef SCORE_HH
#define SCORE_HH
-#include "input.hh"
#include "lily-proto.hh"
+#include "input.hh"
#include "parray.hh"
#include "smobs.hh"
+#include "virtual-methods.hh"
class Score : public Input
{
+ DECLARE_SMOBS (Score, foo);
+
public:
Link_array<Music_output_def> defs_;
SCM music_;
Score ();
Score (Score const&);
- DECLARE_SMOBS (Score,foo);
+ SCM book_rendering (String, Music_output_def*, Paper_def**);
};
-DECLARE_UNSMOB (Score,score);
-
+DECLARE_UNSMOB (Score, score);
SCM ly_run_translator (SCM, SCM);
SCM ly_render_output (SCM, SCM);
-void default_rendering (SCM,SCM,SCM,SCM);
+void default_rendering (SCM, SCM, SCM, SCM);
#endif /* SCORE_HH */
#include "scm-hash.hh"
#include "ly-module.hh"
-#include "paper-book.hh"
-
bool store_locations_global_b;
/*
ly_clear_anonymous_modules ();
}
-
-
Input_file_results* global_input_file;
-Input_file_results::Input_file_results (String init, String in_file, String out_file)
+Input_file_results::Input_file_results (String init,
+ String in_file, String out_file)
{
header_ = ly_make_anonymous_module ();
global_input_file = this;
+ book_count_ = 0;
score_count_ = 0;
sources_.set_path (&global_path);
-
progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
progress_indication ("\n");
exit_status_global = 1;
failed_files.push (in_file);
}
-
do_deps (out_file);
}
return;
}
- paper_book = new Paper_book ();;
Input_file_results inp_file (init, in_file, out_file);
- if (output_format_global == PAGE_LAYOUT)
- paper_book->output (out_file);
-
- scm_gc_unprotect_object (paper_book->self_scm ());
- paper_book = 0;
}
{"appoggiatura", APPOGGIATURA},
{"autochange", AUTOCHANGE},
{"bar", BAR},
+ {"book", BOOK},
{"breathe", BREATHE},
{"change", CHANGE},
{"chords", CHORDS},
/****************************************************************/
-/* Current global paper book. Gives default_rendering access from
- input-file-results. */
-Paper_book *paper_book;
-
Paper_book::Paper_book ()
{
copyright_ = SCM_EOL;
Paper_book::title (int i)
{
SCM user_title = ly_scheme_function ("user-title");
- SCM book_title = ly_scheme_function ("book-title");
- SCM score_title = ly_scheme_function ("score-title");
+ SCM book_title = ly_scheme_function ("book-title");
+ SCM score_title = ly_scheme_function ("score-title");
SCM field = (i == 0 ? ly_symbol2scm ("bookTitle")
: ly_symbol2scm ("scoreTitle"));
#include <stdio.h>
-#include "scm-option.hh"
+#include "book.hh"
#include "context-def.hh"
-#include "lily-guile.hh"
-#include "misc.hh"
-#include "my-lily-lexer.hh"
-#include "paper-def.hh"
-#include "midi-def.hh"
-#include "main.hh"
-#include "file-path.hh"
-#include "warn.hh"
#include "dimensions.hh"
-#include "my-lily-parser.hh"
-#include "score.hh"
+#include "event.hh"
+#include "file-path.hh"
#include "input-file-results.hh"
+#include "input-smob.hh"
#include "input.hh"
+#include "lily-guile.hh"
#include "lilypond-input-version.hh"
-#include "scm-hash.hh"
#include "ly-module.hh"
-#include "music-sequence.hh"
-#include "input-smob.hh"
-#include "event.hh"
-#include "text-item.hh"
+#include "main.hh"
+#include "midi-def.hh"
+#include "misc.hh"
#include "music-list.hh"
+#include "music-sequence.hh"
+#include "my-lily-lexer.hh"
+#include "my-lily-parser.hh"
#include "paper-book.hh"
+#include "paper-def.hh"
+#include "scm-hash.hh"
+#include "scm-option.hh"
+#include "score.hh"
+#include "text-item.hh"
+#include "warn.hh"
#define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
{
SCM simple = ly_scheme_function ("simple-markup");
if (is_symbol (encoding))
- {
return scm_list_3 (ly_scheme_function ("encoded-simple-markup"),
encoding, a);
- } else
- return scm_list_2 (simple, a);
-
- return markup;
+ return scm_list_2 (simple, a);
}
-
bool
is_duration (int t)
{
%union {
+ Book *book;
+ Music_output_def *outputdef;
+ SCM scm;
String *string;
- Music *music;
- Score *score;
- Music_output_def *outputdef;
- SCM scm;
- int i;
+ Music *music;
+ Score *score;
+ int i;
}
%{
%token APPLYOUTPUT
%token AUTOCHANGE
%token BAR
+%token BOOK
%token BREATHE
%token CHANGE
%token CHORDMODIFIERS
%token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH
%token FIGURE_SPACE
+%type <book> book_block book_body
%type <i> exclamations questions dots optional_rest
%type <i> bass_mod
%type <scm> grace_head
}
| add_quote {
}
+ | book_block {
+ Book *book = $1;
+ SCM header = THIS->input_file_->header_.to_SCM ();
+ Path outname = split_path (THIS->output_basename_);
+ int *c = &THIS->input_file_->book_count_;
+ if (*c)
+ outname.base += "-" + to_string (*c);
+ (*c)++;
+ Music_output_def *dp = unsmob_music_output_def
+ (THIS->lexer_->lookup_identifier ("$defaultpaper"));
+ book->process (outname.to_string (),
+ dp ? dp->clone () : new Paper_def, header);
+ scm_gc_unprotect_object (book->self_scm ());
+ }
| score_block {
Score *sc = $1;
-
- SCM head = is_module (sc->header_) ? sc->header_ : THIS->input_file_->header_.to_SCM ();
+ SCM head = is_module (sc->header_) ? sc->header_
+ : THIS->input_file_->header_.to_SCM ();
Path p = split_path (THIS->output_basename_);
int *c = &THIS->input_file_->score_count_;
if (*c)
- {
p.base += "-" + to_string (*c);
- }
(*c)++;
SCM outname = scm_makfrom0str (p.to_string ().to_str0());
for (int i = 0; i < sc->defs_.size (); i++)
- default_rendering (sc->music_, sc->defs_[i]->self_scm (), head, outname);
+ default_rendering (sc->music_,
+ sc->defs_[i]->self_scm (), head,
+ outname);
if (sc->defs_.is_empty ())
{
}
;
-/*
- SCORE
-*/
+book_block:
+ BOOK {
+ THIS->push_spot ();
+ }
+ /*cont*/ '{' book_body '}' {
+ THIS->pop_spot ();
+ $$ = $4;
+ }
+ ;
+
+book_body:
+ {
+ $$ = new Book;
+ $$->set_spot (THIS->here_input ());
+ }
+ | book_body score_block {
+ $$->scores_.push ($2);
+ scm_gc_unprotect_object ($2->self_scm ());
+ }
+ | book_body error {
+ }
+ ;
+
score_block:
SCORE {
THIS->push_spot ();
/*cont*/ '{' score_body '}' {
THIS->pop_spot ();
$$ = $4;
-
}
;
{
header_ = SCM_EOL;
music_ = SCM_EOL;
-
smobify_self ();
}
Score::~Score ()
{
-
}
-
-
-
IMPLEMENT_SMOBS (Score);
IMPLEMENT_DEFAULT_EQUAL_P (Score);
-
SCM
Score::mark_smob (SCM s)
{
- Score * sc = (Score*) SCM_CELL_WORD_1 (s);
-
+ Score *sc = (Score*) SCM_CELL_WORD_1 (s);
if (sc->header_)
scm_gc_mark (sc->header_);
for (int i = sc->defs_.size (); i--;)
scm_gc_mark (sc->defs_[i]->self_scm ());
-
return sc->music_;
}
: Input (s)
{
music_ = SCM_EOL;
+
+ // FIXME: SCM_EOL?
header_ = 0;
+
smobify_self ();
Music * m =unsmob_music (s.music_);
Music_output *output = g->get_output ();
if (systems != SCM_UNDEFINED)
{
+ Paper_book *paper_book = new Paper_book ();
Paper_score *ps = dynamic_cast<Paper_score*> (output);
-
paper_book->papers_.push (ps->paper_);
paper_book->scores_.push (systems);
paper_book->global_headers_.push (global_input_file->header_);
paper_book->headers_.push (header);
- if (output_format_global != PAGE_LAYOUT)
- paper_book->classic_output (ly_scm2string (outname));
+ paper_book->classic_output (ly_scm2string (outname));
+ scm_gc_unprotect_object (paper_book->self_scm ());
}
delete output;
}
}
+
+SCM
+Score::book_rendering (String outname, Music_output_def *default_def,
+ Paper_def **paper)
+{
+ 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++)
+ {
+ Music_output_def *def = outdef_count ? defs_[i] : default_def;
+ SCM context = ly_run_translator (music_, def->self_scm ());
+ if (Global_context *g = 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_;
+ }
+ }
+ }
+ return systems;
+}