From d461b7e3857b6c32b0cf3ac5c4d2db07b371780f Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 5 Sep 2004 12:17:01 +0000 Subject: [PATCH] * input/regression/quote-cyclic.ly (Module): new file. * scm/lily.scm (print): add function. * scm/music-functions.scm (quote-substitute): new function. Substitute \quote when putting music into \score. --- ChangeLog | 7 +++++++ VERSION | 2 +- input/regression/quote-cyclic.ly | 23 +++++++++++++++++++++ input/regression/quote.ly | 4 +++- lily/accidental.cc | 3 +++ lily/include/lily-guile.hh | 2 +- lily/include/music.hh | 2 +- lily/include/score.hh | 6 ++++-- lily/lily-parser.cc | 26 ++---------------------- lily/music.cc | 14 +++++-------- lily/parser.yy | 35 +++++--------------------------- lily/quote-iterator.cc | 6 +++++- lily/score.cc | 27 ++++++++++++++++++++++-- scm/define-music-properties.scm | 1 + scm/lily.scm | 8 +++++++- scm/music-functions.scm | 27 ++++++++++++++++++++++-- 16 files changed, 118 insertions(+), 75 deletions(-) create mode 100644 input/regression/quote-cyclic.ly diff --git a/ChangeLog b/ChangeLog index 69102fd611..d6b14869ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2004-09-05 Han-Wen Nienhuys + * input/regression/quote-cyclic.ly (Module): new file. + + * scm/lily.scm (print): add function. + + * scm/music-functions.scm (quote-substitute): new + function. Substitute \quote when putting music into \score. + * input/regression/key-signature-cancellation.ly (Module): new file. * lily/*.cc: more ly_scm2 -> scm_to converions. diff --git a/VERSION b/VERSION index d30d78ded7..74a9994771 100644 --- a/VERSION +++ b/VERSION @@ -1,6 +1,6 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=2 MINOR_VERSION=3 -PATCH_LEVEL=13 +PATCH_LEVEL=14 MY_PATCH_LEVEL= diff --git a/input/regression/quote-cyclic.ly b/input/regression/quote-cyclic.ly new file mode 100644 index 0000000000..2792ad5b26 --- /dev/null +++ b/input/regression/quote-cyclic.ly @@ -0,0 +1,23 @@ + +\header { + + texidoc = "Two quoted voices may refer to each other. In this +example, there are notes with each full-bar rest." + + +} + +A = \relative c' { c4 d e f | << R1 \\ + \quote "qB" 1 >> | } +B = \relative c' { << R1 \\ + \quote "qA" 1 >> | f4 e d c | } + +\addquote "qA" \A +\addquote "qB" \B + +\paper { raggedright = ##t } + +<< + \context Staff = "A" \A + \context Staff = "B" \B +>> diff --git a/input/regression/quote.ly b/input/regression/quote.ly index 6f175b4eb5..12c1e0cba5 100644 --- a/input/regression/quote.ly +++ b/input/regression/quote.ly @@ -6,7 +6,9 @@ music may be quoted. " } \version "2.3.4" - +\paper { + raggedright = ##t +} \addquote bla \relative c' { fis4 g a b } diff --git a/lily/accidental.cc b/lily/accidental.cc index 2844973503..8e00df9b66 100644 --- a/lily/accidental.cc +++ b/lily/accidental.cc @@ -196,6 +196,9 @@ Accidental_interface::print (SCM smob) if (smaller) { SCM ac = Font_interface::music_font_alist_chain (me); + /* + TODO: should calc font-size by adding -2 to current font-size + */ ac = scm_cons (scm_list_1 (scm_cons (ly_symbol2scm ("font-size"), scm_int2num (-2))), diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index c8185778f7..9a7ff0129c 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -33,7 +33,7 @@ inline int ly_scm2int (SCM x) { return scm_num2int (x, 0, "ly_scm2int"); } inline bool ly_c_symbol_p (SCM x) { return SCM_SYMBOLP (x); } #define scm_is_symbol(x) ly_c_symbol_p(x) inline bool ly_c_boolean_p (SCM x) { return SCM_BOOLP (x); } -#define scm_is_bool(x) ly_c_boolean_p( +#define scm_is_bool(x) ly_c_boolean_p(x) inline bool ly_c_eq_p (SCM x, SCM y) { return SCM_EQ_P (x, y); } #define scm_is_eq(x,y) (SCM_EQ_P (x, y)); diff --git a/lily/include/music.hh b/lily/include/music.hh index 0b27e8c2c4..a28786ba66 100644 --- a/lily/include/music.hh +++ b/lily/include/music.hh @@ -71,6 +71,6 @@ DECLARE_UNSMOB(Music,music); Music* make_music_by_name (SCM sym); SCM ly_deep_mus_copy (SCM); -SCM ly_music_scorify (SCM); +SCM ly_music_scorify (SCM, SCM); #endif /* MUSIC_HH */ diff --git a/lily/include/score.hh b/lily/include/score.hh index 0f015a0139..31a2e1483d 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -20,11 +20,13 @@ class Score : public Input { DECLARE_SMOBS (Score, foo); + SCM music_; public: Link_array defs_; - SCM music_; SCM header_; - + + SCM get_music () const; + void set_music (SCM music, SCM parser); Score (); Score (Score const&); SCM book_rendering (String, Output_def*, Output_def*); diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 9d46014696..8ad9b9c47e 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -118,10 +118,6 @@ Lily_parser::parse_file (String init, String name, String out_name) void Lily_parser::parse_string (String ly_code) { -#if 0 - SCM parent_prot = lexer_ ? lexer_->self_scm () : SCM_EOL; -#endif - Lily_lexer * parent = lexer_; lexer_ = (parent == 0 ? new Lily_lexer (sources_) : new Lily_lexer (*parent)); @@ -150,24 +146,6 @@ Lily_parser::parse_string (String ly_code) error_level_ = error_level_ | lexer_->error_level_; -#if 0 - if (Lily_lexer::unsmob (parent_prot)) - { - /* - what the fuck is this good for? - */ - parent->encoding_ = lexer_->encoding_; - parent->chordmodifier_tab_ = lexer_->chordmodifier_tab_; - parent->pitchname_tab_stack_ = lexer_->pitchname_tab_stack_; - parent->sources_ = lexer_->sources_; - parent->scopes_ = lexer_->scopes_; - parent->error_level_ = lexer_->error_level_; - parent->main_input_b_ = lexer_->main_input_b_; - } - - scm_remember_upto_here_1 (parent_prot); -#endif - scm_set_current_module (oldmod); lexer_ = 0; } @@ -456,14 +434,14 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", 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 (), + default_rendering (score->get_music (), score->defs_[i]->self_scm (), bookpaper, header, os); if (score->defs_.is_empty ()) { Output_def *paper = get_paper (parser); - default_rendering (score->music_, paper->self_scm (), + default_rendering (score->get_music(), paper->self_scm (), get_bookpaper (parser)->self_scm (), header, os); scm_gc_unprotect_object (paper->self_scm ()); diff --git a/lily/music.cc b/lily/music.cc index 7ed8aacc90..a729802b6c 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -379,21 +379,17 @@ LY_DEFINE (ly_music_compress, "ly:music-compress", } LY_DEFINE (ly_music_scorify, "ly:music-scorify", - 1, 0, 0, - (SCM music), + 2, 0, 0, + (SCM music, SCM parser), "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; + + score->set_music (music, parser); + scm_gc_unprotect_object (score->self_scm ()); return score->self_scm (); } diff --git a/lily/parser.yy b/lily/parser.yy index 2dedb25e29..b77a0f7b73 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -680,19 +680,7 @@ score_body: | score_body Music { SCM m = $2->self_scm (); scm_gc_unprotect_object (m); - - /* - guh. - */ - SCM check_funcs = ly_scheme_function ("toplevel-music-functions"); - for (; ly_c_pair_p (check_funcs); check_funcs = ly_cdr (check_funcs)) - m = scm_call_1 (ly_car (check_funcs), m); - if (unsmob_music ($$->music_)) - { - THIS->parser_error (_("Already have music in score")); - unsmob_music ($$->music_)->origin ()->error (_("This is the previous music")); - } - $$->music_ = m; + $$->set_music (m, THIS->self_scm ()); } | score_body lilypond_header { $$->header_ = $2; @@ -1527,24 +1515,11 @@ command_element: $$ = skip; } | QUOTE STRING duration_length { - SCM tab = THIS->lexer_->lookup_identifier ("musicQuotes"); - SCM evs = SCM_EOL; - if (scm_hash_table_p (tab) == SCM_BOOL_T) - { - SCM key = $2; // use symbol? - evs = scm_hash_ref (tab, key, SCM_BOOL_F); - } - Music *quote = 0; - if (ly_c_vector_p (evs)) - { - quote = MY_MAKE_MUSIC ("QuoteMusic"); - quote->set_property ("duration", $3); - quote->set_property ("quoted-events", evs); - } else { - THIS->here_input ().warning (_f ("Can\'t find music")); - quote = MY_MAKE_MUSIC ("Event"); - } + Music *quote = MY_MAKE_MUSIC ("QuoteMusic"); + quote->set_property ("duration", $3); + quote->set_property ("quoted-music-name", $2); quote->set_spot (THIS->here_input ()); + $$ = quote; } | OCTAVE { THIS->push_spot (); } diff --git a/lily/quote-iterator.cc b/lily/quote-iterator.cc index 158f271e90..307b860dc9 100644 --- a/lily/quote-iterator.cc +++ b/lily/quote-iterator.cc @@ -103,13 +103,17 @@ Quote_iterator::construct_children () event_idx_ = binsearch_scm_vector (event_vector_, now.smobbed_copy (), &moment_less); end_idx_ = binsearch_scm_vector (event_vector_, stop.smobbed_copy (), &moment_less); } + else + { + get_music ()->origin()->warning (_("No events found for \\quote")); + } } bool Quote_iterator::ok () const { - return (event_idx_ <= end_idx_); + return ly_c_vector_p (event_vector_) && (event_idx_ <= end_idx_); } diff --git a/lily/score.cc b/lily/score.cc index 2dadb3f7f4..ecdddb64a8 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -8,8 +8,8 @@ #include +#include "lily-parser.hh" #include "book.hh" - #include "cpu-timer.hh" #include "global-context.hh" #include "ly-module.hh" @@ -292,9 +292,32 @@ LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format", itself. */ score_def->parent_ = od; - SCM context = ly_run_translator (sc->music_, score_def->self_scm ()); + SCM context = ly_run_translator (sc->get_music (), score_def->self_scm ()); SCM lines = ly_format_output (context, scm_makfrom0str ("")); scm_remember_upto_here_1 (prot); return lines; } + +void +Score::set_music (SCM music, SCM parser) +{ + /* 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_2 (ly_car (check_funcs), music, parser); + + if (unsmob_music (music_)) + { + unsmob_music (music)->origin ()->error (_("Already have music in score")); + unsmob_music (music_)->origin ()->error (_("This is the previous music")); + } + + this->music_ = music; +} + +SCM +Score::get_music () const +{ + return music_; +} diff --git a/scm/define-music-properties.scm b/scm/define-music-properties.scm index 86f3f5cefc..66977251db 100644 --- a/scm/define-music-properties.scm +++ b/scm/define-music-properties.scm @@ -84,6 +84,7 @@ For chord inversions, this is negative.") "Do these operations for instantiating the context.") (predicate ,procedure? "the predicate of a \\outputproperty.") (quoted-events ,vector? "A vector of with moment/event-list entries.") + (quoted-music-name ,string? "The name of the voice to quote.") (type ,symbol? "The type of this music object. Determines iteration in some cases.") (types ,list? "The types of this music object; determines by what engraver this music expression is diff --git a/scm/lily.scm b/scm/lily.scm index 8c680eeda9..9e47a9208f 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -19,8 +19,14 @@ (srfi srfi-1) ; lists (srfi srfi-13)) ; strings +; my display + (define-public (myd k v) (display k) (display ": ") (display v) (display ", ")) +(define-public (print . args) + (apply format (cons (current-output-port) args))) + + ;;; General settings ;;; debugging evaluator is slower. This should ;;; have a more sensible default. @@ -122,7 +128,7 @@ )) (define-public (collect-music-for-book parser music) - (collect-scores-for-book parser (ly:music-scorify music))) + (collect-scores-for-book parser (ly:music-scorify music parser))) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 62832f29c3..96f53bb285 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -601,6 +601,26 @@ Syntax: (lambda (,@args) ,@body))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define-public ((quote-substitute quote-tab) music) + (let* + ((quoted-name (ly:music-property music 'quoted-music-name)) + (quoted-vector (if (string? quoted-name) + (hash-ref quote-tab quoted-name #f) + #f + )) + + ) + (if (string? quoted-name) + (if (vector? quoted-vector) + (set! (ly:music-property music 'quoted-events) quoted-vector) + (ly:warn "Cannot find quoted music `~S'" quoted-name))) + + music)) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; switch it on here, so parsing and init isn't checked (too slow!) ;; @@ -614,8 +634,11 @@ Syntax: (define-public toplevel-music-functions (list ;; check-start-chords ; ; no longer needed with chord syntax. - voicify-music - (lambda (x) (music-map glue-mm-rest-texts x)) + (lambda (music parser) (voicify-music music)) + (lambda (x parser) (music-map glue-mm-rest-texts x)) + (lambda (music parser) + + (music-map (quote-substitute (ly:parser-lookup parser 'musicQuotes)) music)) ;; switch-on-debugging )) -- 2.39.5