From: Erik Sandberg Date: Tue, 11 Jul 2006 05:58:01 +0000 (+0000) Subject: * lily/global-context-scheme.cc: Separated ly:run-translator into X-Git-Tag: cvs/HEAD~258 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e0aab46ee287f06765b982c49fd0491ab033fce7;p=lilypond.git * lily/global-context-scheme.cc: Separated ly:run-translator into smaller pieces. * lily/score-engraver.cc, lily/score-performer.cc, scm/define-context-properties.scm: Make paper/midi output accessable as a context property. * lily/score-translator.cc, lily/score-context.cc: Removed. --- diff --git a/ChangeLog b/ChangeLog index 0200f9dce5..5ae5cece08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-07-11 Erik Sandberg + + * lily/global-context-scheme.cc: Separated ly:run-translator into + smaller pieces. + + * lily/score-engraver.cc, lily/score-performer.cc, + scm/define-context-properties.scm: Make paper/midi output + accessable as a context property. + + * lily/score-translator.cc, lily/score-context.cc: Removed. + 2006-07-07 Guido Amoruso * scm/ps-to-png.scm (Module): diff --git a/lily/bar-engraver.cc b/lily/bar-engraver.cc index 2915165009..16792eac58 100644 --- a/lily/bar-engraver.cc +++ b/lily/bar-engraver.cc @@ -9,7 +9,6 @@ #include "bar-line.hh" #include "context.hh" -#include "score-context.hh" #include "score-engraver.hh" #include "warn.hh" #include "item.hh" diff --git a/lily/beam-engraver.cc b/lily/beam-engraver.cc index c8104d0bd0..f20160518e 100644 --- a/lily/beam-engraver.cc +++ b/lily/beam-engraver.cc @@ -15,7 +15,6 @@ #include "international.hh" #include "item.hh" #include "rest.hh" -#include "score-context.hh" #include "spanner.hh" #include "stem.hh" #include "warn.hh" diff --git a/lily/context-def.cc b/lily/context-def.cc index f4ee43b160..f15a1ab141 100644 --- a/lily/context-def.cc +++ b/lily/context-def.cc @@ -11,9 +11,9 @@ #include "context-def.hh" +#include "context.hh" #include "international.hh" #include "output-def.hh" -#include "score-context.hh" #include "translator.hh" #include "warn.hh" @@ -252,12 +252,7 @@ Context_def::get_translator_names (SCM user_mod) const Context * Context_def::instantiate (SCM ops, Object_key const *key) { - Context *context = 0; - - if (context_name_ == ly_symbol2scm ("Score")) - context = new Score_context (key); - else - context = new Context (key); + Context *context = new Context (key); context->definition_ = self_scm (); context->definition_mods_ = ops; diff --git a/lily/context.cc b/lily/context.cc index f39fb5e1c2..5211cbb3f0 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -10,6 +10,7 @@ #include "context-def.hh" #include "dispatcher.hh" +#include "global-context.hh" #include "international.hh" #include "ly-smobs.icc" #include "main.hh" @@ -17,7 +18,6 @@ #include "profile.hh" #include "program-option.hh" #include "scm-hash.hh" -#include "score-context.hh" #include "translator-group.hh" #include "warn.hh" @@ -140,8 +140,8 @@ Context::create_unique_context (SCM name, string id, SCM operations) } /* - Don't go up to Global_context, because global goes down to - Score_context + Don't go up to Global_context, because global goes down to the + Score context */ Context *ret = 0; if (daddy_context_ && !dynamic_cast (daddy_context_)) @@ -202,8 +202,8 @@ Context::find_create_context (SCM n, string id, SCM operations) } /* - Don't go up to Global_context, because global goes down to - Score_context + Don't go up to Global_context, because global goes down to the + Score context */ Context *ret = 0; if (daddy_context_ && !dynamic_cast (daddy_context_)) @@ -563,12 +563,10 @@ Context::context_name () const return ly_symbol2string (context_name_symbol ()); } -Score_context * +Context * Context::get_score_context () const { - if (Score_context *sc = dynamic_cast ((Context *) this)) - return sc; - else if (daddy_context_) + if (daddy_context_) return daddy_context_->get_score_context (); else return 0; diff --git a/lily/engraver.cc b/lily/engraver.cc index eebd22e4be..7f7dc65f3a 100644 --- a/lily/engraver.cc +++ b/lily/engraver.cc @@ -14,7 +14,6 @@ #include "spanner.hh" #include "item.hh" #include "context.hh" -#include "score-context.hh" #include "lilypond-key.hh" Engraver_group * diff --git a/lily/folded-repeat-iterator.cc b/lily/folded-repeat-iterator.cc index 1a4de7c369..79bfcb2fc7 100644 --- a/lily/folded-repeat-iterator.cc +++ b/lily/folded-repeat-iterator.cc @@ -98,7 +98,7 @@ Folded_repeat_iterator::enter_alternative () */ Simultaneous_music_iterator *s = new Simultaneous_music_iterator; s->create_separate_contexts_ = true; - s->init_translator (mus, get_outlet ()); + s->init_context (mus, get_outlet ()); alternative_iter_ = s; alternative_iter_->construct_children (); diff --git a/lily/forbid-break-engraver.cc b/lily/forbid-break-engraver.cc index 14471e8ec6..709f5e87d1 100644 --- a/lily/forbid-break-engraver.cc +++ b/lily/forbid-break-engraver.cc @@ -5,14 +5,14 @@ (c) 2002--_2005 Han-Wen Nienhuys */ +#include "context.hh" #include "duration.hh" -#include "grob.hh" #include "engraver.hh" +#include "grob.hh" #include "input.hh" #include "moment.hh" #include "pitch.hh" #include "rhythmic-head.hh" -#include "score-context.hh" #include "translator.icc" diff --git a/lily/global-context-scheme.cc b/lily/global-context-scheme.cc index 9229a8a0d9..273ae10b1d 100644 --- a/lily/global-context-scheme.cc +++ b/lily/global-context-scheme.cc @@ -5,7 +5,6 @@ (c) 2005--2006 Han-Wen Nienhuys */ - #include "cpu-timer.hh" #include "global-context.hh" #include "international.hh" @@ -47,47 +46,57 @@ LY_DEFINE (ly_make_global_translator, "ly:make-global-translator", return tg->unprotect (); } -LY_DEFINE (ly_run_translator, "ly:run-translator", - 2, 1, 0, (SCM mus, SCM output_def, SCM key), - "Process @var{mus} according to @var{output_def}. \n" - "An interpretation context is set up,\n" - "and @var{mus} is interpreted with it. \n" - "The context is returned in its final state.\n" - "\n\n" - "Optionally, this routine takes an Object-key to\n" +LY_DEFINE (ly_make_global_context, "ly:make-global-context", + 1, 1, 0, (SCM output_def, SCM key), + "Set up a global interpretation context, using the output\n" + "block @var{output_def}.\n" + "The context is returned.\n" + + "\n\nOptionally, this routine takes an Object-key to\n" "to uniquely identify the Score block containing it.\n") { Output_def *odef = unsmob_output_def (output_def); - Music *music = unsmob_music (mus); - if (!music - || !music->get_length ().to_bool ()) + SCM_ASSERT_TYPE (odef, output_def, SCM_ARG1, __FUNCTION__, + "Output definition"); + + Global_context *glob = new Global_context (odef, unsmob_key (key)); + + if (!glob) { - warning (_ ("no music found in score")); + programming_error ("no toplevel translator"); return SCM_BOOL_F; } - SCM_ASSERT_TYPE (music, mus, SCM_ARG1, __FUNCTION__, "Music"); - SCM_ASSERT_TYPE (odef, output_def, SCM_ARG2, __FUNCTION__, - "Output definition"); + return glob->unprotect (); +} - Cpu_timer timer; +LY_DEFINE (ly_interpret_music_expression, "ly:interpret-music-expression", + 2, 0, 0, (SCM mus, SCM ctx), + "Interpret the music expression @var{mus} in the\n" + "global context @var{ctx}. The context is returned in its\n" + "final state.\n") +{ + Music *music = unsmob_music (mus); + Global_context *g = dynamic_cast (unsmob_context (ctx)); + SCM_ASSERT_TYPE (music, mus, SCM_ARG1, __FUNCTION__, "Music"); + SCM_ASSERT_TYPE (g, ctx, SCM_ARG2, __FUNCTION__, "Global context"); - Global_context *glob = new Global_context (odef, unsmob_key (key)); - if (!glob) + if (!music + || !music->get_length ().to_bool ()) { - programming_error ("Couldn't create Global context"); + warning (_ ("no music found in score")); return SCM_BOOL_F; } - SCM tgs = ly_make_global_translator (glob->self_scm ()); - Translator_group *tg = unsmob_translator_group (tgs); + Cpu_timer timer; message (_ ("Interpreting music... ")); SCM protected_iter = Music_iterator::get_static_get_iterator (music); Music_iterator *iter = unsmob_iterator (protected_iter); - iter->init_translator (music, glob); + + iter->init_context (music, g); iter->construct_children (); if (!iter->ok ()) @@ -97,13 +106,31 @@ LY_DEFINE (ly_run_translator, "ly:run-translator", return SCM_BOOL_F; } - glob->run_iterator_on_me (iter); + g->run_iterator_on_me (iter); + iter->quit (); scm_remember_upto_here_1 (protected_iter); - send_stream_event (glob, "Finish", 0, 0); + + send_stream_event (g, "Finish", 0, 0); if (be_verbose_global) message (_f ("elapsed time: %.2f seconds", timer.read ())); - return glob->unprotect (); + return ctx; +} + +LY_DEFINE (ly_run_translator, "ly:run-translator", + 2, 1, 0, (SCM mus, SCM output_def, SCM key), + "Process @var{mus} according to @var{output_def}. \n" + "An interpretation context is set up,\n" + "and @var{mus} is interpreted with it. \n" + "The context is returned in its final state.\n" + "\n\n" + "Optionally, this routine takes an Object-key to\n" + "to uniquely identify the Score block containing it.\n") +{ + SCM glob = ly_make_global_context (output_def, key); + ly_make_global_translator (glob); + ly_interpret_music_expression (mus, glob); + return glob; } diff --git a/lily/global-context.cc b/lily/global-context.cc index 94f3547630..40fe3a61cd 100644 --- a/lily/global-context.cc +++ b/lily/global-context.cc @@ -18,7 +18,6 @@ using namespace std; #include "music-iterator.hh" #include "music.hh" #include "output-def.hh" -#include "score-context.hh" #include "stream-event.hh" #include "warn.hh" @@ -96,10 +95,6 @@ Global_context::prepare (SCM sev) now_mom_ = *mom; clear_key_disambiguations (); - - // should do nothing now - if (get_score_context ()) - get_score_context ()->prepare (now_mom_); } Moment @@ -108,31 +103,18 @@ Global_context::now_mom () const return now_mom_; } -Score_context * +Context * Global_context::get_score_context () const { return (scm_is_pair (context_list_)) - ? dynamic_cast (unsmob_context (scm_car (context_list_))) + ? unsmob_context (scm_car (context_list_)) : 0; } SCM Global_context::get_output () { - return get_score_context ()->get_output (); -} - -void -Global_context::one_time_step () -{ - get_score_context ()->one_time_step (); -} - -void -Global_context::finish () -{ - if (get_score_context ()) - get_score_context ()->finish (); + return get_score_context ()->get_property ("output"); } void @@ -169,23 +151,6 @@ Global_context::run_iterator_on_me (Music_iterator *iter) if (iter->ok ()) iter->process (w); - if (!get_score_context ()) - { - error ("ES TODO: no score context, this shouldn't happen"); - SCM sym = ly_symbol2scm ("Score"); - Context_def *t = unsmob_context_def (find_context_def (get_output_def (), - sym)); - if (!t) - error (_f ("can't find `%s' context", "Score")); - - Object_key const *key = get_context_key ("Score", ""); - Context *c = t->instantiate (SCM_EOL, key); - add_context (c); - - Score_context *sc = dynamic_cast (c); - sc->prepare (w); - } - send_stream_event (this, "OneTimeStep", 0, 0); apply_finalizations (); check_removal (); diff --git a/lily/include/context.hh b/lily/include/context.hh index eaa280ff58..1a9c0c2567 100644 --- a/lily/include/context.hh +++ b/lily/include/context.hh @@ -102,7 +102,7 @@ public: SCM context_name_symbol () const; Global_context *get_global_context () const; - virtual Score_context *get_score_context () const; + virtual Context *get_score_context () const; virtual Output_def *get_output_def () const; virtual Moment now_mom () const; virtual Context *get_default_interpreter (); diff --git a/lily/include/global-context.hh b/lily/include/global-context.hh index 0ff225c50d..75172595cc 100644 --- a/lily/include/global-context.hh +++ b/lily/include/global-context.hh @@ -26,14 +26,12 @@ public: Moment sneaky_insert_extra_moment (Moment); void add_moment_to_process (Moment); void run_iterator_on_me (Music_iterator *); - virtual Score_context *get_score_context () const; + virtual Context *get_score_context () const; void apply_finalizations (); void add_finalization (SCM); DECLARE_LISTENER (prepare); - virtual void one_time_step (); - virtual void finish (); virtual SCM get_output (); virtual Output_def *get_output_def () const; virtual Moment now_mom () const; diff --git a/lily/include/music-iterator.hh b/lily/include/music-iterator.hh index 3c62205b90..4078ec655b 100644 --- a/lily/include/music-iterator.hh +++ b/lily/include/music-iterator.hh @@ -65,7 +65,7 @@ public: Context *get_outlet () const; void set_context (Context *); static SCM get_static_get_iterator (Music *mus); - void init_translator (Music *, Context *); + void init_context (Music *, Context *); void quit (); void substitute_outlet (Context *from, Context *to); void descend_to_bottom_context (); diff --git a/lily/include/score-context.hh b/lily/include/score-context.hh deleted file mode 100644 index 349c768696..0000000000 --- a/lily/include/score-context.hh +++ /dev/null @@ -1,24 +0,0 @@ -/* - score-context.hh -- declare Score_context - - source file of the GNU LilyPond music typesetter - - (c) 2004--2006 Han-Wen Nienhuys -*/ -#ifndef SCORE_CONTEXT_HH -#define SCORE_CONTEXT_HH - -#include "global-context.hh" - -class Score_context : public Context -{ -public: - Score_context (Object_key const *); - - virtual SCM get_output (); - virtual void prepare (Moment); - virtual void finish (); - virtual void one_time_step (); -}; - -#endif /* SCORE_CONTEXT_HH */ diff --git a/lily/include/score-engraver.hh b/lily/include/score-engraver.hh index b3127f8977..47f7604f1a 100644 --- a/lily/include/score-engraver.hh +++ b/lily/include/score-engraver.hh @@ -10,10 +10,8 @@ #define SCORE_ENGRAVER_HH #include "engraver-group.hh" -#include "score-translator.hh" -class Score_engraver : public virtual Score_translator, - public virtual Engraver_group +class Score_engraver : public Engraver_group { System *system_; @@ -43,7 +41,6 @@ protected: public: Score_engraver (); - virtual SCM get_output (); }; #endif /* SCORE_ENGRAVER_HH */ diff --git a/lily/include/score-performer.hh b/lily/include/score-performer.hh index f98dd18dd5..0987ef7d68 100644 --- a/lily/include/score-performer.hh +++ b/lily/include/score-performer.hh @@ -10,13 +10,11 @@ #include "moment.hh" #include "performer-group.hh" -#include "score-translator.hh" /** Top level performer. Completely takes care of MIDI output */ -class Score_performer : public Score_translator, - public virtual Performer_group +class Score_performer : public Performer_group { public: VIRTUAL_COPY_CONSTRUCTOR (Translator_group, Score_performer); @@ -36,7 +34,6 @@ protected: virtual void announce_element (Audio_element_info); virtual int get_tempo () const; virtual void play_element (Audio_element *p); - virtual SCM get_output (); virtual void derived_mark () const; private: void header (Midi_stream &); diff --git a/lily/include/score-translator.hh b/lily/include/score-translator.hh deleted file mode 100644 index 01ee9e3ad0..0000000000 --- a/lily/include/score-translator.hh +++ /dev/null @@ -1,22 +0,0 @@ -/* - score-translator.hh -- declare Score_translator - - source file of the GNU LilyPond music typesetter - - (c) 2004--2006 Han-Wen Nienhuys -*/ - -#ifndef SCORE_TRANSLATOR_HH -#define SCORE_TRANSLATOR_HH - -#include "translator-group.hh" - -class Score_translator : public virtual Translator_group -{ - friend class Score_context; -protected: - virtual SCM get_output (); -}; - -#endif /* SCORE_TRANSLATOR_HH */ - diff --git a/lily/include/translator.hh b/lily/include/translator.hh index f6b3c88819..4429429321 100644 --- a/lily/include/translator.hh +++ b/lily/include/translator.hh @@ -89,7 +89,7 @@ public: void process_music (); void process_acknowledged (); - Score_context *get_score_context () const; + Context *get_score_context () const; Global_context *get_global_context () const; TRANSLATOR_DECLARATIONS (Translator); diff --git a/lily/ligature-engraver.cc b/lily/ligature-engraver.cc index 87db230110..822df306ff 100644 --- a/lily/ligature-engraver.cc +++ b/lily/ligature-engraver.cc @@ -12,7 +12,6 @@ #include "international.hh" #include "note-head.hh" #include "rest.hh" -#include "score-context.hh" #include "spanner.hh" #include "warn.hh" diff --git a/lily/music-iterator.cc b/lily/music-iterator.cc index 83838427df..ce824968a9 100644 --- a/lily/music-iterator.cc +++ b/lily/music-iterator.cc @@ -118,7 +118,7 @@ Music_iterator::music_start_mom ()const } void -Music_iterator::init_translator (Music *m, Context *report) +Music_iterator::init_context (Music *m, Context *report) { music_ = m; assert (m); @@ -145,7 +145,7 @@ Music_iterator::get_iterator (Music *m) const SCM ip = get_static_get_iterator (m); Music_iterator *p = unsmob_iterator (ip); - p->init_translator (m, get_outlet ()); + p->init_context (m, get_outlet ()); p->construct_children (); return ip; diff --git a/lily/paper-column-engraver.cc b/lily/paper-column-engraver.cc index cef0f9e5c0..b6f249e9af 100644 --- a/lily/paper-column-engraver.cc +++ b/lily/paper-column-engraver.cc @@ -14,7 +14,6 @@ #include "note-spacing.hh" #include "pointer-group-interface.hh" #include "context.hh" -#include "score-context.hh" #include "axis-group-interface.hh" #include "warn.hh" diff --git a/lily/percent-repeat-engraver.cc b/lily/percent-repeat-engraver.cc index a979a2e743..81d831aff8 100644 --- a/lily/percent-repeat-engraver.cc +++ b/lily/percent-repeat-engraver.cc @@ -16,7 +16,6 @@ #include "misc.hh" #include "percent-repeat-iterator.hh" #include "repeated-music.hh" -#include "score-context.hh" #include "side-position-interface.hh" #include "spanner.hh" #include "warn.hh" diff --git a/lily/score-context.cc b/lily/score-context.cc deleted file mode 100644 index 60ef490517..0000000000 --- a/lily/score-context.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - score-context.cc -- implement Score_context - - source file of the GNU LilyPond music typesetter - - (c) 2004--2006 Han-Wen Nienhuys -*/ - -#include "score-context.hh" - -#include "score-translator.hh" - -void -Score_context::prepare (Moment) -{ -} - -void -Score_context::finish () -{ -} - -void -Score_context::one_time_step () -{ -} - -SCM -Score_context::get_output () -{ - Translator_group *t = implementation (); - Score_translator *s = dynamic_cast (t); - return s->get_output (); -} - -Score_context::Score_context (Object_key const *key) - : Context (key) -{ -} diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index b6c79d0158..9ad0998cfb 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -35,7 +35,6 @@ Score_engraver::derived_mark () const { if (pscore_) scm_gc_mark (pscore_->self_scm ()); - Score_translator::derived_mark (); Engraver_group::derived_mark (); } @@ -77,6 +76,7 @@ Score_engraver::initialize () pscore_ = new Paper_score (dynamic_cast (context ()->get_output_def ())); pscore_->unprotect (); + context ()->set_property ("output", pscore_->self_scm ()); SCM props = updated_grob_properties (context (), ly_symbol2scm ("System")); @@ -114,7 +114,7 @@ Score_engraver::disconnect_from_context () void Score_engraver::finalize () { - Score_translator::finalize (); + Engraver_group::finalize (); typeset_all (); } @@ -157,13 +157,6 @@ Score_engraver::typeset_all () elems_.clear (); } -SCM -Score_engraver::get_output () -{ - Music_output *o = pscore_; - return o->self_scm (); -} - bool Score_engraver::try_music (Music *m) { diff --git a/lily/score-performer.cc b/lily/score-performer.cc index c71b4c5361..a0b0c7d17e 100644 --- a/lily/score-performer.cc +++ b/lily/score-performer.cc @@ -130,21 +130,12 @@ Score_performer::get_tempo () const return ::get_tempo (performance_->midi_, Moment (Rational (1, 4))); } -SCM -Score_performer::get_output () -{ - Music_output *o = performance_; - performance_ = 0; - return o->self_scm (); -} - void Score_performer::derived_mark () const { if (performance_) scm_gc_mark (performance_->self_scm ()); - Score_translator::derived_mark (); Performer_group::derived_mark (); } @@ -153,6 +144,7 @@ Score_performer::initialize () { performance_ = new Performance; performance_->unprotect (); + context ()->set_property ("output", performance_->self_scm ()); performance_->midi_ = context ()->get_output_def (); Translator_group::initialize (); diff --git a/lily/score-translator.cc b/lily/score-translator.cc deleted file mode 100644 index 68baba6010..0000000000 --- a/lily/score-translator.cc +++ /dev/null @@ -1,16 +0,0 @@ -/* - score-translator.cc -- implement Score_translator - - source file of the GNU LilyPond music typesetter - - (c) 2004--2006 Han-Wen Nienhuys -*/ - -#include "score-translator.hh" -#include "moment.hh" - -SCM -Score_translator::get_output () -{ - return SCM_EOL; -} diff --git a/lily/simultaneous-music-iterator.cc b/lily/simultaneous-music-iterator.cc index a264d55ba9..62d3b3c200 100644 --- a/lily/simultaneous-music-iterator.cc +++ b/lily/simultaneous-music-iterator.cc @@ -51,14 +51,14 @@ Simultaneous_music_iterator::construct_children () number number as name */ SCM name = ly_symbol2scm (get_outlet ()->context_name ().c_str ()); - Context *t = (j && create_separate_contexts_) + Context *c = (j && create_separate_contexts_) ? get_outlet ()->find_create_context (name, to_string (j), SCM_EOL) : get_outlet (); - if (!t) - t = get_outlet (); + if (!c) + c = get_outlet (); - mi->init_translator (mus, t); + mi->init_context (mus, c); mi->construct_children (); if (mi->ok ()) diff --git a/lily/translator.cc b/lily/translator.cc index 391af52b4b..762fdfd2f9 100644 --- a/lily/translator.cc +++ b/lily/translator.cc @@ -125,7 +125,7 @@ Translator::get_global_context () const return daddy_context_->get_global_context (); } -Score_context * +Context * Translator::get_score_context () const { return daddy_context_->get_score_context (); diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index 427c14c2bc..084ab18f6b 100644 --- a/scm/define-context-properties.scm +++ b/scm/define-context-properties.scm @@ -308,6 +308,7 @@ markup. Called with 2 arguments, event and context.") selects the highest string with a fret at least @code{minimumFret}") (minimumVerticalExtent ,number-pair? "minimum vertical extent, same format as @var{verticalExtent}") + (output ,ly:music-output? "The output produced by a score-level translator during music interpretation") (ottavation ,string? "If set, the text for an ottava spanner. Changing this creates a new text spanner. ") (pedalSustainStrings ,list? "List of string to print for