]> git.donarmstrong.com Git - lilypond.git/blob - lily/recording-group-engraver.cc
2003 -> 2004
[lilypond.git] / lily / recording-group-engraver.cc
1 /*   
2   recording-group-engraver.cc -- implement Recording_group_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2003--2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8  */
9
10 #include "engraver-group-engraver.hh"
11 #include "protected-scm.hh"
12
13 class Recording_group_engraver : public Engraver_group_engraver
14 {
15 public:
16   TRANSLATOR_DECLARATIONS(Recording_group_engraver);
17   virtual bool try_music (Music *m);
18   virtual void start_translation_timestep ();
19   virtual void stop_translation_timestep ();
20   virtual void finalize ();
21   virtual void initialize ();
22   Protected_scm accumulator_;
23 };
24
25 void
26 Recording_group_engraver::initialize ()
27 {
28   Engraver_group_engraver::initialize ();
29   accumulator_ = gh_cons (SCM_EOL, SCM_EOL);
30 }
31
32 Recording_group_engraver::Recording_group_engraver()
33 {
34 }
35
36 void
37 Recording_group_engraver::start_translation_timestep ()
38 {
39   Engraver_group_engraver::start_translation_timestep();
40   
41   scm_set_car_x (accumulator_, gh_cons (now_mom ().smobbed_copy (), SCM_EOL));
42 }
43
44 void
45 Recording_group_engraver::stop_translation_timestep ()
46 {
47   Engraver_group_engraver::stop_translation_timestep();
48   scm_set_cdr_x (accumulator_, gh_cons (gh_car (accumulator_), gh_cdr (accumulator_)));
49
50   scm_set_car_x (accumulator_, SCM_EOL);
51 }
52
53 void
54 Recording_group_engraver::finalize ()
55 {
56   Engraver_group_engraver::finalize ();
57   SCM proc = get_property ("recordEventSequence");
58
59   if (gh_procedure_p (proc))
60     scm_call_2  (proc, self_scm(), gh_cdr (accumulator_));
61
62   accumulator_ = SCM_EOL;
63 }
64
65 bool
66 Recording_group_engraver::try_music (Music  *m)
67 {
68   bool here_success = Translator_group::try_music_on_nongroup_children (m);
69   bool retval = here_success;
70   if (!here_success && daddy_trans_)
71     retval = daddy_trans_->try_music (m);
72       
73   SCM seq = gh_cdar (accumulator_);
74   seq = gh_cons (gh_cons  (m->self_scm(), gh_bool2scm (here_success)),
75                  seq);
76   
77   scm_set_cdr_x  (gh_car (accumulator_), seq);
78
79   return retval;
80 }
81
82
83 ENTER_DESCRIPTION(Recording_group_engraver,
84                   "Engraver_group_engraver that records all music events "
85                   "for this context. Calls the procedure "
86                   "in @code{recordEventSequence} when finished.",
87                   "",
88                   "",
89                   "",
90                   "recordEventSequence",
91                   "");