]> git.donarmstrong.com Git - lilypond.git/blob - lily/recording-group-engraver.cc
release commit
[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 "context.hh"
11 #include "engraver-group-engraver.hh"
12 #include "protected-scm.hh"
13
14 class Recording_group_engraver : public Engraver_group_engraver
15 {
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   virtual void derived_mark () const;
25   SCM accumulator_;
26 };
27
28 void
29 Recording_group_engraver::derived_mark () const
30 {
31   Engraver_group_engraver::derived_mark();
32   scm_gc_mark (accumulator_);
33 }
34
35 void
36 Recording_group_engraver::initialize ()
37 {
38   Engraver_group_engraver::initialize ();
39   start ();
40 }
41
42 Recording_group_engraver::Recording_group_engraver ()
43 {
44   accumulator_ = SCM_EOL;
45 }
46
47 void
48 Recording_group_engraver::start_translation_timestep ()
49 {
50   Engraver_group_engraver::start_translation_timestep ();
51
52
53   /*
54     We have to do this both in initialize () and
55     start_translation_timestep (), since start_translation_timestep ()
56     isn't called on the first time-step.
57    */
58   start () ;
59 }
60
61 void
62 Recording_group_engraver::start ()
63 {
64   if (!scm_is_pair (accumulator_))
65     accumulator_ = scm_cons (SCM_EOL, SCM_EOL);
66   if (!scm_is_pair (ly_car (accumulator_)))
67     {
68       /*
69         Need to store transposition for every moment; transposition changes during pieces.
70        */
71       scm_set_car_x (accumulator_, scm_cons (scm_cons (now_mom ().smobbed_copy (),
72                                                      get_property ("instrumentTransposition")),
73                                                      SCM_EOL));
74     }
75 }
76
77 void
78 Recording_group_engraver::stop_translation_timestep ()
79 {
80   Engraver_group_engraver::stop_translation_timestep ();
81   scm_set_cdr_x (accumulator_, scm_cons (ly_car (accumulator_), ly_cdr (accumulator_)));
82
83   scm_set_car_x (accumulator_, SCM_EOL);
84 }
85
86 void
87 Recording_group_engraver::finalize ()
88 {
89   Engraver_group_engraver::finalize ();
90   SCM proc = get_property ("recordEventSequence");
91
92   if (ly_c_procedure_p (proc))
93     scm_call_2  (proc, context ()->self_scm (), ly_cdr (accumulator_));
94
95   accumulator_ = SCM_EOL;
96 }
97
98 bool
99 Recording_group_engraver::try_music (Music  *m)
100 {
101   bool retval = Translator_group::try_music (m);
102
103   SCM seq = ly_cdar (accumulator_);
104   seq = scm_cons (scm_cons  (m->self_scm (), ly_bool2scm (retval)),
105                  seq);
106   
107   scm_set_cdr_x  (ly_car (accumulator_), seq);
108
109   return retval;
110 }
111
112
113 ENTER_DESCRIPTION (Recording_group_engraver,
114                   "Engraver_group_engraver that records all music events "
115                   "for this context. Calls the procedure "
116                   "in @code{recordEventSequence} when finished.",
117                   "",
118                   "",
119                   "",
120                   "recordEventSequence",
121                   "");