* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[lilypond.git] / lily / recording-group-engraver.cc
blob6ccd234e62635a3bd627cda799b6bd6853bf7bb1
1 /*
2 recording-group-engraver.cc -- implement Recording_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
10 #include "context.hh"
11 #include "engraver-group-engraver.hh"
12 #include "protected-scm.hh"
14 class Recording_group_engraver : public Engraver_group_engraver
16 void start ();
17 public:
18 TRANSLATOR_DECLARATIONS (Recording_group_engraver);
19 virtual bool try_music (Music *m);
20 virtual void start_translation_timestep ();
21 virtual void stop_translation_timestep ();
22 virtual void finalize ();
23 virtual void initialize ();
24 Protected_scm accumulator_;
27 void
28 Recording_group_engraver::initialize ()
30 Engraver_group_engraver::initialize ();
31 start ();
34 Recording_group_engraver::Recording_group_engraver ()
38 void
39 Recording_group_engraver::start_translation_timestep ()
41 Engraver_group_engraver::start_translation_timestep ();
45 We have to do this both in initialize () and
46 start_translation_timestep (), since start_translation_timestep ()
47 isn't called on the first time-step.
49 start () ;
52 void
53 Recording_group_engraver::start ()
55 if (!ly_pair_p (accumulator_))
56 accumulator_ = scm_cons (SCM_EOL, SCM_EOL);
57 if (!ly_pair_p (ly_car (accumulator_)))
60 Need to store transposition for every moment; transposition changes during pieces.
62 scm_set_car_x (accumulator_, scm_cons (scm_cons (now_mom ().smobbed_copy (),
63 get_property ("instrumentTransposition")),
64 SCM_EOL));
68 void
69 Recording_group_engraver::stop_translation_timestep ()
71 Engraver_group_engraver::stop_translation_timestep ();
72 scm_set_cdr_x (accumulator_, scm_cons (ly_car (accumulator_), ly_cdr (accumulator_)));
74 scm_set_car_x (accumulator_, SCM_EOL);
77 void
78 Recording_group_engraver::finalize ()
80 Engraver_group_engraver::finalize ();
81 SCM proc = get_property ("recordEventSequence");
83 if (ly_procedure_p (proc))
84 scm_call_2 (proc, daddy_context_->self_scm (), ly_cdr (accumulator_));
86 accumulator_ = SCM_EOL;
89 bool
90 Recording_group_engraver::try_music (Music *m)
92 bool retval = Translator_group::try_music (m);
94 SCM seq = ly_cdar (accumulator_);
95 seq = scm_cons (scm_cons (m->self_scm (), ly_bool2scm (retval)),
96 seq);
98 scm_set_cdr_x (ly_car (accumulator_), seq);
100 return retval;
104 ENTER_DESCRIPTION (Recording_group_engraver,
105 "Engraver_group_engraver that records all music events "
106 "for this context. Calls the procedure "
107 "in @code{recordEventSequence} when finished.",
111 "recordEventSequence",
112 "");