From 77d7ea56b0c903e994726b38c81ce5afdb585481 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 19 Apr 2004 13:40:48 +0000 Subject: [PATCH] * input/regression/newaddlyrics.ly: New file. * Documentation/topdocs/NEWS.texi: Update. * lily/parser.yy (new_lyrics): Return SCM list of lyric musics. (Music_list): Allow embedded scm. * lily/score.cc (ly:score-bookify): New function. * lily/music.cc (ly:music-scorify): Idem. * lily/my-lily-parser.cc (ly:parser-print-book): Idem. (ly:parser-print-score): Idem. * scm/lily.scm (default-toplevel-book-handler): Idem. (default-toplevel-music-handler): Idem. (default-toplevel-score-handler): Idem. * ly/declarations-init.ly: Set default toplevel handlers. * lily/parser.yy (book_block, score_block, toplevel_music): Use them. * scripts/lilypond-book.py (PREAMBLE_LY): Select classic score printer for score at toplevel. --- ChangeLog | 27 ++++++ Documentation/topdocs/NEWS.texi | 47 +++++++++++ Documentation/user/notation.itely | 2 +- Documentation/user/tutorial.itely | 2 +- input/regression/newaddlyrics.ly | 39 +++++++++ lily/include/my-lily-parser.hh | 6 +- lily/lexer.ll | 4 +- lily/music.cc | 48 ++++++++--- lily/my-lily-parser.cc | 70 +++++++++++----- lily/parser.yy | 134 ++++++++++-------------------- lily/score.cc | 38 ++++++--- lily/source-file.cc | 12 +-- ly/declarations-init.ly | 2 + ly/init.ly | 1 + scm/lily.scm | 24 +++++- scm/music-functions.scm | 8 +- scripts/lilypond-book.py | 1 + 17 files changed, 309 insertions(+), 156 deletions(-) create mode 100644 input/regression/newaddlyrics.ly diff --git a/ChangeLog b/ChangeLog index 8d94ba6e51..a12a6654d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2004-04-19 Jan Nieuwenhuizen + + * input/regression/newaddlyrics.ly: New file. + + * Documentation/topdocs/NEWS.texi: Update. + + * lily/parser.yy (new_lyrics): Return SCM list of lyric musics. + (Music_list): Allow embedded scm. + + * lily/score.cc (ly:score-bookify): New function. + + * lily/music.cc (ly:music-scorify): Idem. + + * lily/my-lily-parser.cc (ly:parser-print-book): Idem. + (ly:parser-print-score): Idem. + + * scm/lily.scm (default-toplevel-book-handler): Idem. + (default-toplevel-music-handler): Idem. + (default-toplevel-score-handler): Idem. + + * ly/declarations-init.ly: Set default toplevel handlers. + + * lily/parser.yy (book_block, score_block, toplevel_music): Use them. + + * scripts/lilypond-book.py (PREAMBLE_LY): Select classic score + printer for score at toplevel. + 2004-04-18 Jan Nieuwenhuizen * lily/parser.yy (NEWLYRICS): Switch to LYRICS mode for lyrics. diff --git a/Documentation/topdocs/NEWS.texi b/Documentation/topdocs/NEWS.texi index bb1a5db452..6f9b0db3d0 100644 --- a/Documentation/topdocs/NEWS.texi +++ b/Documentation/topdocs/NEWS.texi @@ -8,6 +8,53 @@ @itemize @bullet +@c FIXME: un-geekify +@item Music lists are allowed at toplevel, and are handled by +@code{default-toplevel-music-handler}. Similarly, a @code{score} block +at toplevel is handled by @code{default-toplevel-score-handler} an a +@code{book} at toplevel is handled by @code{default-toplevel-book-handler}. + +These default handlers have the following effect. A Music list at +toplevel is encapsulated in a @code{score} block, and a @code{score} +block at toplevel is encapsulated in a @code{book} block. A +@code{book} block at toplevel generates printed output. + +@example +\header @{ title = "The Title" @} +\notes @{ a b c @} +@end example + +is the same as + +@example +\header @{ title = "The Title" @} +\book @{ + \score @{ + \notes @{ a b c @} + @} +@} +@end example + +@item Start pitch for @code{relative} music is optional for music lists. +The default value is one octave below middle C. + +@c update-me? formal definition of newaddlyrics, once it works +@item Combining lyrics with music can be @code{newaddlyrics} + +@example +<< + \relative @{ + \clef bass + d2 d c4 bes a2 \break + c2 c d4 f g2 + @} + \newlyrics @{ + My first Li -- ly song, + Not much can go wrong! + @} +>> +@end example + @item The parser is encapsulated in a Scheme function @code{ly:parse-file}, so the following fragment processes two files diff --git a/Documentation/user/notation.itely b/Documentation/user/notation.itely index 48227e93c0..7907f01a09 100644 --- a/Documentation/user/notation.itely +++ b/Documentation/user/notation.itely @@ -3595,7 +3595,7 @@ Stanza numbers can be added by setting @code{stanza}, e.g. << \context Voice = duet { \time 3/4 g2 e4 a2 f4 g2. } - \lyrics \lyricsto "duet" \new Lyrics { + \lyricsto "duet" \new Lyrics \lyrics { \set stanza = "1. " Hi, my name is Bert. } >> diff --git a/Documentation/user/tutorial.itely b/Documentation/user/tutorial.itely index 4cc564878b..fbf723586f 100644 --- a/Documentation/user/tutorial.itely +++ b/Documentation/user/tutorial.itely @@ -1091,7 +1091,7 @@ Twin -- kle twin -- kle \time 2/4 f4 f c' c } - \new Lyrics \lyrics \lyricsto "bla" { Twin -- kle twin -- kle } + \new Lyrics \lyricsto "bla" \lyrics { Twin -- kle twin -- kle } >> } @end lilypond diff --git a/input/regression/newaddlyrics.ly b/input/regression/newaddlyrics.ly new file mode 100644 index 0000000000..daef387aef --- /dev/null +++ b/input/regression/newaddlyrics.ly @@ -0,0 +1,39 @@ +\header { + texidoc = "newlyrics -- multiple stanzas broken as yet." +} + +%% Testing newlyrics +%%\new PianoStaff << +<< + \new Staff \relative { + d'2 d c4 bes a2 \break + c2 c d4 f g2 + } + \newlyrics << + { + My first Li -- ly song, + Not much can go wrong! + } + { + My se -- cond ly verse + Not much can go wrong! + } + >> + \new Staff \relative { + \clef bass + d2 d c4 bes a2 \break + c2 c d4 f g2 + } + \newlyrics << + { + MY FIRST LI -- LY SONG, + NOT MUCH CAN GO WRONG! + } + { + MY SE -- COND LY VERSE + NOT MUCH CAN GO WRONG! + } + >> +>> + +\version "2.3.0" diff --git a/lily/include/my-lily-parser.hh b/lily/include/my-lily-parser.hh index eadac03ccd..58afacb257 100644 --- a/lily/include/my-lily-parser.hh +++ b/lily/include/my-lily-parser.hh @@ -72,6 +72,10 @@ DECLARE_UNSMOB (My_lily_parser, my_lily_parser); SCM ly_parse_file (SCM); SCM ly_parse_string (SCM); -SCM ly_parser_add_book_and_score (SCM, SCM); +// SCM ly_parser_add_book_and_score (SCM, SCM); +SCM ly_parser_print_book (SCM, SCM); +SCM ly_parser_print_score (SCM, SCM); +SCM ly_parser_bookify (SCM, SCM); +SCM ly_parser_scorify (SCM, SCM); #endif /* MY_LILY_PARSER_HH */ diff --git a/lily/lexer.ll b/lily/lexer.ll index aa44ebf2f6..8b25deb071 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -313,10 +313,10 @@ HYPHEN -- } { \<\< { - return LESSLESS; + return DOUBLE_ANGLE_OPEN; } \>\> { - return MOREMORE; + return DOUBLE_ANGLE_CLOSE; } } { diff --git a/lily/music.cc b/lily/music.cc index 4c58b9c757..21356b6745 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -6,14 +6,14 @@ (c) 1997--2004 Han-Wen Nienhuys */ -#include "main.hh" #include "input-smob.hh" -#include "music.hh" -#include "music-list.hh" -#include "warn.hh" -#include "pitch.hh" #include "ly-smobs.icc" #include "main.hh" +#include "music-list.hh" +#include "music.hh" +#include "pitch.hh" +#include "score.hh" +#include "warn.hh" bool @@ -215,6 +215,18 @@ Music::origin () const return ip ? ip : & dummy_input_global; } + +Music* +make_music_by_name (SCM sym) +{ + SCM make_music_proc = ly_scheme_function ("make-music"); + SCM rv = scm_call_1 (make_music_proc, sym); + + /* UGH. */ + scm_gc_protect_object (rv); + return unsmob_music (rv); +} + LY_DEFINE (ly_music_length, "ly:music-length", 1, 0, 0, (SCM mus), "Get the length of music expression @var{mus}, and return as a @code{Moment} object.") @@ -359,14 +371,24 @@ LY_DEFINE (ly_music_compress, "ly:music-compress", return sc->self_scm (); } -Music* -make_music_by_name (SCM sym) -{ - SCM make_music_proc = ly_scheme_function ("make-music"); - SCM rv = scm_call_1 (make_music_proc, sym); - /* UGH. */ - scm_gc_protect_object (rv); - return unsmob_music (rv); +LY_DEFINE (ly_music_scorify, "ly:music-scorify", + 1, 0, 0, + (SCM music), + "Return MUSIC encapsulated in SCORE.") +{ +#if 0 + SCM_ASSERT_TYPE (ly_c_music_p (music), music, SCM_ARG1, __FUNCTION__, "music"); +#endif + Score *score = new Score; + + /* URG? */ + SCM check_funcs = ly_scheme_function ("toplevel-music-functions"); + for (; ly_c_pair_p (check_funcs); check_funcs = ly_cdr (check_funcs)) + music = scm_call_1 (ly_car (check_funcs), music); + + score->music_ = music; + scm_gc_unprotect_object (score->self_scm ()); + return score->self_scm (); } diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index e0820239f7..47cbade68e 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -100,8 +100,6 @@ My_lily_parser::parse_string (String ly_code) lexer_ = new My_lily_lexer (sources_); lexer_->main_input_name_ = ""; lexer_->main_input_b_ = true; - SCM nn = lexer_->lookup_identifier ("pitchnames"); - lexer_->push_note_state (alist_to_hashq (nn)); set_yydebug (0); lexer_->new_input (lexer_->main_input_name_, ly_code, sources_); @@ -313,27 +311,60 @@ LY_DEFINE (ly_parse_string, "ly:parse-string", return SCM_UNSPECIFIED; } +static Music_output_def* +get_paper (My_lily_parser *parser) +{ + SCM id = parser->lexer_->lookup_identifier ("$defaultpaper"); + Music_output_def *paper = unsmob_music_output_def (id); + return paper ? paper->clone () : new Paper_def; +} -LY_DEFINE (ly_parser_add_book_and_score, "ly:parser-add-book-and-score", +LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", 2, 0, 0, - (SCM purple, SCM music), - "Handle the toplevel-music MUSIC by adding BOOK and SCORE.") + (SCM parser_smob, SCM score_smob), + "Print score, i.e., the classic way.") { #if 0 SCM_ASSERT_TYPE (ly_c_parser_p (parser), music, SCM_ARG1, __FUNCTION__, "parser"); SCM_ASSERT_TYPE (ly_c_music_p (music), music, SCM_ARG1, __FUNCTION__, "music"); #endif - My_lily_parser *parser = unsmob_my_lily_parser (purple); - Score *score = new Score; + My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); + Score *score = unsmob_score (score_smob); + + SCM header = is_module (score->header_) ? score->header_ + : parser->header_.to_SCM (); - /* URG? */ - SCM check_funcs = ly_scheme_function ("toplevel-music-functions"); - for (; ly_c_pair_p (check_funcs); check_funcs = ly_cdr (check_funcs)) - music = scm_call_1 (ly_car (check_funcs), music); - score->music_ = music; - Book *book = new Book; - book->scores_.push (score); - scm_gc_unprotect_object (score->self_scm ()); + Path outname = split_path (parser->output_basename_); + int *c = &parser->book_count_; + if (*c) + outname.base += "-" + to_string (*c); + (*c)++; + + SCM os = scm_makfrom0str (outname.to_string ().to_str0 ()); + for (int i = 0; i < score->defs_.size (); i++) + default_rendering (score->music_, score->defs_[i]->self_scm (), header, + os); + + if (score->defs_.is_empty ()) + { + Music_output_def *paper = get_paper (parser); + default_rendering (score->music_, paper->self_scm (), header, os); + scm_gc_unprotect_object (paper->self_scm ()); + } + return SCM_UNDEFINED; +} + +LY_DEFINE (ly_parser_print_book, "ly:parser-print-book", + 2, 0, 0, + (SCM parser_smob, SCM book_smob), + "Print book.") +{ +#if 0 + SCM_ASSERT_TYPE (ly_c_parser_p (parser_smob), parser_smob, SCM_ARG1, __FUNCTION__, "parser_smob"); + SCM_ASSERT_TYPE (ly_c_music_p (book_smob), book_smob, SCM_ARG1, __FUNCTION__, "book_smob"); +#endif + My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); + Book *book = unsmob_book (book_smob); SCM header = parser->header_; Path outname = split_path (parser->output_basename_); @@ -341,11 +372,8 @@ LY_DEFINE (ly_parser_add_book_and_score, "ly:parser-add-book-and-score", if (*c) outname.base += "-" + to_string (*c); (*c)++; - My_lily_lexer *lexer = parser->lexer_; - Music_output_def *dp - = unsmob_music_output_def (lexer->lookup_identifier ("$defaultpaper")); - book->process (outname.to_string (), - dp ? dp->clone () : new Paper_def, header); - scm_gc_unprotect_object (book->self_scm ()); + Music_output_def *paper = get_paper (parser); + book->process (outname.to_string (), paper, header); + scm_gc_unprotect_object (paper->self_scm ()); return SCM_UNDEFINED; } diff --git a/lily/parser.yy b/lily/parser.yy index 56ca971ea6..1930b93aa5 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -81,14 +81,6 @@ tag_music (Music *m, SCM tag, Input ip) m->set_property ("tags", tags); } -Music_output_def* -get_paper (My_lily_parser *parser) -{ - SCM id = parser->lexer_->lookup_identifier ("$defaultpaper"); - Music_output_def *paper = unsmob_music_output_def (id); - return paper ? paper->clone () : new Paper_def; -} - bool is_regular_identifier (SCM id) { @@ -265,8 +257,8 @@ or %token CHANGE %token CHORDMODIFIERS %token CHORDS -%token LESSLESS -%token MOREMORE +%token DOUBLE_ANGLE_OPEN +%token DOUBLE_ANGLE_CLOSE %token CLEF %token COMMANDSPANREQUEST %token CONSISTS @@ -330,15 +322,6 @@ or %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH %token FIGURE_SPACE -%type book_block book_body -%type exclamations questions dots optional_rest -%type bass_mod -%type grace_head -%type oct_check -%type context_mod_list -%type lyric_element -%type bass_number br_bass_figure bass_figure figure_list figure_spec -%type new_lyrics %token DIGIT %token NOTENAME_PITCH %token TONICNAME_PITCH @@ -374,6 +357,15 @@ or %token MARKUP_IDENTIFIER MARKUP_HEAD_LIST0 %type markup markup_line markup_list markup_list_body full_markup +%type book_block book_body +%type exclamations questions dots optional_rest +%type bass_mod +%type grace_head +%type oct_check +%type context_mod_list +%type lyric_element +%type bass_number br_bass_figure bass_figure figure_list figure_spec +%type new_lyrics %type output_def %type lilypond_header lilypond_header_body %type open_event close_event @@ -450,59 +442,28 @@ toplevel_expression: lilypond_header { THIS->header_ = $1; } - | toplevel_music { - Music_output_def *paper = get_paper (THIS); - SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler"); - if (proc == SCM_UNDEFINED) - proc = ly_scheme_function ("ly:parser-add-book-and-score"); - scm_call_2 (proc, THIS->self_scm (), $1->self_scm ()); - scm_gc_unprotect_object (paper->self_scm ()); - } | add_quote { } | book_block { Book *book = $1; - SCM header = THIS->header_; - Path outname = split_path (THIS->output_basename_); - int *c = &THIS->book_count_; - if (*c) - outname.base += "-" + to_string (*c); - (*c)++; - Music_output_def *paper = get_paper (THIS); - book->process (outname.to_string (), paper, header); + SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler"); + scm_call_2 (proc, THIS->self_scm (), book->self_scm ()); scm_gc_unprotect_object (book->self_scm ()); - scm_gc_unprotect_object (paper->self_scm ()); } | score_block { - /* TODO: implicit book, depending on --no-book/--no-page-layout - option? */ Score *score = $1; - SCM head = is_module (score->header_) ? score->header_ - : THIS->header_.to_SCM (); - - Path p = split_path (THIS->output_basename_); - int *c = &THIS->score_count_; - if (*c) - p.base += "-" + to_string (*c); - - (*c)++; - SCM outname = scm_makfrom0str (p.to_string ().to_str0()); - - for (int i = 0; i < score->defs_.size (); i++) - default_rendering (score->music_, - score->defs_[i]->self_scm (), head, - outname); - - if (score->defs_.is_empty ()) - { - Music_output_def *paper = get_paper (THIS); - default_rendering (score->music_, paper->self_scm (), head, - outname); - scm_gc_unprotect_object (paper->self_scm ()); - } + + SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler"); + scm_call_2 (proc, THIS->self_scm (), score->self_scm ()); scm_gc_unprotect_object (score->self_scm ()); } + | toplevel_music { + Music *music = $1; + SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler"); + scm_call_2 (proc, THIS->self_scm (), music->self_scm ()); + scm_gc_unprotect_object (music->self_scm ()); + } | output_def { SCM id = SCM_EOL; if (dynamic_cast ($1)) @@ -814,6 +775,8 @@ Music_list: scm_set_car_x (s, c); /* set first cons */ scm_set_cdr_x (s, c); /* remember last cell */ } + | Music_list embedded_scm { + } | Music_list error { } ; @@ -1052,8 +1015,8 @@ basic music objects too, since the meaning is different. $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3); } | NEWCONTEXT string optional_context_mod Music { - $$ = context_spec_music ($2, get_next_unique_context (), - $4, $3); + $$ = context_spec_music ($2, get_next_unique_context (), $4, + $3); } | TIMES { @@ -1186,20 +1149,17 @@ new_lyrics: \repeat \alternative */ THIS->lexer_->pop_state (); #if 0 - $$ = $3; -#else Music *music = MY_MAKE_MUSIC ("SimultaneousMusic"); music->set_property ("elements", scm_list_1 ($3->self_scm ())); $$ = music; +#else + $$ = scm_cons ($3->self_scm (), SCM_EOL); #endif } | new_lyrics NEWLYRICS { THIS->lexer_->push_lyric_state (); } Grouped_music_list { THIS->lexer_->pop_state (); - Music *music = MY_MAKE_MUSIC ("SimultaneousMusic"); - music->set_property ("elements", scm_cons ($4->self_scm (), - $1->get_property ("elements"))); - $$ = music; + $$ = scm_cons ($4->self_scm (), $1); } ; @@ -1214,35 +1174,30 @@ re_rhythmed_music: } | Grouped_music_list new_lyrics { - /* TODO: loop over simultaneous lyric musics? */ + /* FIXME: should find out uniqueXXX name from music */ + SCM name = $1->get_property ("context-id"); + //if (name == SCM_EOL) + if (!ly_c_string_p (name)) + name = scm_makfrom0str (""); - Music *music = $2; - SCM name = scm_makfrom0str (""); SCM context = scm_makfrom0str ("Lyrics"); Music *all = MY_MAKE_MUSIC ("SimultaneousMusic"); -#if 0 // simple only - Music *combined = make_lyric_combine_music (name, music); - Music *csm = context_spec_music (context, SCM_UNDEFINED, - combined, SCM_EOL); - all->set_property ("elements", scm_listify ($1->self_scm (), - csm->self_scm (), SCM_UNDEFINED)); -#else + SCM lst = SCM_EOL; - for (SCM s = music->get_property ("elements"); ly_c_pair_p (s); - s = ly_cdr (s)) + for (SCM s = $2; ly_c_pair_p (s); s = ly_cdr (s)) { + Music *music = unsmob_music (ly_car (s)); Music *com = make_lyric_combine_music (name, music); Music *csm = context_spec_music (context, - SCM_UNDEFINED, com, SCM_EOL); - //lst = ly_snoc (csm->self_scm (), lst); + get_next_unique_context (), com, SCM_EOL); lst = scm_cons (csm->self_scm (), lst); } -#endif + /* FIXME: only first lyric music is accepted, + the rest is junked */ all->set_property ("elements", scm_cons ($1->self_scm (), lst)); $$ = all; scm_gc_unprotect_object ($1->self_scm ()); - scm_gc_unprotect_object ($2->self_scm ()); } | LYRICSTO string Music { Music *music = $3; @@ -1426,10 +1381,10 @@ chord_open: '<' chord_close: '>' ; -simul_open: LESSLESS +simul_open: DOUBLE_ANGLE_OPEN ; -simul_close: MOREMORE +simul_close: DOUBLE_ANGLE_CLOSE ; chord_body: @@ -2658,15 +2613,12 @@ context_spec_music (SCM type, SCM id, Music *m, SCM ops) return csm; } - SCM get_next_unique_context () { static int new_context_count; - char s[1024]; - snprintf (s, 1024, "uniqueContext%d", new_context_count ++); - + snprintf (s, 1024, "uniqueContext%d", new_context_count++); return scm_makfrom0str (s); } diff --git a/lily/score.cc b/lily/score.cc index e793931efb..7a82662dd9 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -8,23 +8,22 @@ #include +#include "book.hh" +#include "cpu-timer.hh" +#include "global-context.hh" +#include "ly-module.hh" #include "ly-smobs.icc" - -#include "score.hh" -#include "warn.hh" +#include "main.hh" +#include "music-iterator.hh" #include "music-output-def.hh" #include "music-output.hh" -#include "music-iterator.hh" #include "music.hh" -#include "global-context.hh" -#include "scm-hash.hh" -#include "cpu-timer.hh" -#include "main.hh" -#include "paper-def.hh" -#include "ly-module.hh" #include "paper-book.hh" +#include "paper-def.hh" #include "paper-score.hh" - +#include "scm-hash.hh" +#include "score.hh" +#include "warn.hh" /* TODO: junkme. @@ -209,3 +208,20 @@ Score::book_rendering (String outname, Music_output_def *default_def, } return systems; } + +LY_DEFINE (ly_score_bookify, "ly:score-bookify", + 1, 0, 0, + (SCM score_smob), + "Return SCORE encapsulated in a BOOK.") +{ +#if 0 + SCM_ASSERT_TYPE (ly_c_parser_p (parser_smob), parser_smobd, SCM_ARG1, __FUNCTION__, "parser_smob"); + SCM_ASSERT_TYPE (ly_c_score_p (score_smob), score_smob, SCM_ARG1, __FUNCTION__, "score_smob"); +#endif + + Score *score = unsmob_score (score_smob); + Book *book = new Book; + book->scores_.push (score); + scm_gc_unprotect_object (book->self_scm ()); + return book->self_scm (); +} diff --git a/lily/source-file.cc b/lily/source-file.cc index eb83b0e1de..d735fd26ff 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -67,9 +67,6 @@ gulp_file (String filename, int *filesize) return str; } -/* - Unused. - */ Source_file::Source_file (String filename, String data) { name_ = filename; @@ -103,12 +100,9 @@ Source_file::Source_file (String filename_string) void Source_file::init_port () { - SCM str =scm_makfrom0str (contents_str0_); - - str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, - __FUNCTION__); - scm_set_port_filename_x (str_port_, - scm_makfrom0str (name_.get_str0())); + SCM str = scm_makfrom0str (contents_str0_); + str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, __FUNCTION__); + scm_set_port_filename_x (str_port_, scm_makfrom0str (name_.get_str0 ())); } int diff --git a/ly/declarations-init.ly b/ly/declarations-init.ly index 360c178ea0..671b97470c 100644 --- a/ly/declarations-init.ly +++ b/ly/declarations-init.ly @@ -146,4 +146,6 @@ unusedEntry = \notes { c4 } #(define musicQuotes (make-hash-table 29)) %%#(define-public toplevel-music-handler ly:parser-add-book-and-score) +#(define toplevel-book-handler default-toplevel-book-handler) #(define toplevel-music-handler default-toplevel-music-handler) +#(define toplevel-score-handler default-toplevel-score-handler) diff --git a/ly/init.ly b/ly/init.ly index 9d8b15f8e9..9a881e8ec6 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -21,6 +21,7 @@ %% #(if (and (ly:get-option 'old-relative) + (defined? 'input-file-name) (not (ly:get-option 'old-relative-used))) (ly:warn (string-append "\n" diff --git a/scm/lily.scm b/scm/lily.scm index 963f064ce1..5ca36f86f8 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -91,12 +91,34 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; lily specific variables. -(define-public default-toplevel-music-handler ly:parser-add-book-and-score) (define-public default-script-alist '()) (define-public safe-mode? #f) +;; parser stuff. +(define-public (print-music-as-book parser music) + (let* ((score (ly:music-scorify music)) + (book (ly:score-bookify score))) + (ly:parser-print-book parser book))) + +(define-public (print-score-as-book parser score) + (let ((book (ly:score-bookify score))) + (ly:parser-print-book parser book))) + +(define-public (print-score parser score) + (let ((book (ly:score-bookify score))) + (ly:parser-print-score parser book))) + +(define-public default-toplevel-music-handler print-music-as-book) +(define-public default-toplevel-book-handler ly:parser-print-book) +(define-public default-toplevel-score-handler print-score-as-book) +;;(define-public toplevel-music-handler print-music-as-book) +;;(define-public toplevel-music-handler toplevel-music-functions) +;;(define-public toplevel-music-handler +;; (lambda (x y) (print-music-as-book x y))) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Unassorted utility functions. diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 6207329357..bdbe2d393d 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -1,11 +1,11 @@ -;;;; music-functions.scm -- implement Scheme output routines for PostScript +;;;; music-functions.scm -- ;;;; ;;;; source file of the GNU LilyPond music typesetter ;;;; ;;;; (c) 1998--2004 Jan Nieuwenhuizen -;;;; Han-Wen Nienhuys +;;;; Han-Wen Nienhuys -(use-modules (ice-9 optargs)) +;; (use-modules (ice-9 optargs)) ;;; ly:music-property with setter ;;; (ly:music-property my-music 'elements) @@ -723,5 +723,3 @@ use PianoStaff as a context. " (else (ly:warn (string-append "Unknown accidental style: " (symbol->string style))) (make-sequential-music '())))))) - - diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index eaafc7dbad..2689e9bce3 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -298,6 +298,7 @@ output = { PREAMBLE_LY = r'''%%%% Generated by %(program_name)s %%%% Options: [%(option_string)s] +#(define toplevel-score-handler ly:parser-print-score) %(preamble_string)s \paper {%(paper_string)s } -- 2.39.5