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-11 Erik Sandberg <mandolaerik@gmail.com>
+
+ * 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 <guidonte@katamail.com>
* scm/ps-to-png.scm (Module):
#include "bar-line.hh"
#include "context.hh"
-#include "score-context.hh"
#include "score-engraver.hh"
#include "warn.hh"
#include "item.hh"
#include "international.hh"
#include "item.hh"
#include "rest.hh"
-#include "score-context.hh"
#include "spanner.hh"
#include "stem.hh"
#include "warn.hh"
#include "context-def.hh"
+#include "context.hh"
#include "international.hh"
#include "output-def.hh"
-#include "score-context.hh"
#include "translator.hh"
#include "warn.hh"
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;
#include "context-def.hh"
#include "dispatcher.hh"
+#include "global-context.hh"
#include "international.hh"
#include "ly-smobs.icc"
#include "main.hh"
#include "profile.hh"
#include "program-option.hh"
#include "scm-hash.hh"
-#include "score-context.hh"
#include "translator-group.hh"
#include "warn.hh"
}
/*
- 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<Global_context *> (daddy_context_))
}
/*
- 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<Global_context *> (daddy_context_))
return ly_symbol2string (context_name_symbol ());
}
-Score_context *
+Context *
Context::get_score_context () const
{
- if (Score_context *sc = dynamic_cast<Score_context *> ((Context *) this))
- return sc;
- else if (daddy_context_)
+ if (daddy_context_)
return daddy_context_->get_score_context ();
else
return 0;
#include "spanner.hh"
#include "item.hh"
#include "context.hh"
-#include "score-context.hh"
#include "lilypond-key.hh"
Engraver_group *
*/
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 ();
(c) 2002--_2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
+#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"
(c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
-
#include "cpu-timer.hh"
#include "global-context.hh"
#include "international.hh"
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<Global_context *> (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 ())
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;
}
#include "music-iterator.hh"
#include "music.hh"
#include "output-def.hh"
-#include "score-context.hh"
#include "stream-event.hh"
#include "warn.hh"
now_mom_ = *mom;
clear_key_disambiguations ();
-
- // should do nothing now
- if (get_score_context ())
- get_score_context ()->prepare (now_mom_);
}
Moment
return now_mom_;
}
-Score_context *
+Context *
Global_context::get_score_context () const
{
return (scm_is_pair (context_list_))
- ? dynamic_cast<Score_context *> (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
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<Score_context *> (c);
- sc->prepare (w);
- }
-
send_stream_event (this, "OneTimeStep", 0, 0);
apply_finalizations ();
check_removal ();
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 ();
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;
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 ();
+++ /dev/null
-/*
- score-context.hh -- declare Score_context
-
- source file of the GNU LilyPond music typesetter
-
- (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-#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 */
#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_;
public:
Score_engraver ();
- virtual SCM get_output ();
};
#endif /* SCORE_ENGRAVER_HH */
#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);
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 &);
+++ /dev/null
-/*
- score-translator.hh -- declare Score_translator
-
- source file of the GNU LilyPond music typesetter
-
- (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#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 */
-
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);
#include "international.hh"
#include "note-head.hh"
#include "rest.hh"
-#include "score-context.hh"
#include "spanner.hh"
#include "warn.hh"
}
void
-Music_iterator::init_translator (Music *m, Context *report)
+Music_iterator::init_context (Music *m, Context *report)
{
music_ = m;
assert (m);
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;
#include "note-spacing.hh"
#include "pointer-group-interface.hh"
#include "context.hh"
-#include "score-context.hh"
#include "axis-group-interface.hh"
#include "warn.hh"
#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"
+++ /dev/null
-/*
- score-context.cc -- implement Score_context
-
- source file of the GNU LilyPond music typesetter
-
- (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#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<Score_translator *> (t);
- return s->get_output ();
-}
-
-Score_context::Score_context (Object_key const *key)
- : Context (key)
-{
-}
{
if (pscore_)
scm_gc_mark (pscore_->self_scm ());
- Score_translator::derived_mark ();
Engraver_group::derived_mark ();
}
pscore_ = new Paper_score (dynamic_cast<Output_def *> (context ()->get_output_def ()));
pscore_->unprotect ();
+ context ()->set_property ("output", pscore_->self_scm ());
SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
void
Score_engraver::finalize ()
{
- Score_translator::finalize ();
+ Engraver_group::finalize ();
typeset_all ();
}
elems_.clear ();
}
-SCM
-Score_engraver::get_output ()
-{
- Music_output *o = pscore_;
- return o->self_scm ();
-}
-
bool
Score_engraver::try_music (Music *m)
{
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 ();
}
{
performance_ = new Performance;
performance_->unprotect ();
+ context ()->set_property ("output", performance_->self_scm ());
performance_->midi_ = context ()->get_output_def ();
Translator_group::initialize ();
+++ /dev/null
-/*
- score-translator.cc -- implement Score_translator
-
- source file of the GNU LilyPond music typesetter
-
- (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#include "score-translator.hh"
-#include "moment.hh"
-
-SCM
-Score_translator::get_output ()
-{
- return SCM_EOL;
-}
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 ())
return daddy_context_->get_global_context ();
}
-Score_context *
+Context *
Translator::get_score_context () const
{
return daddy_context_->get_score_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