]> git.donarmstrong.com Git - lilypond.git/blob - lily/recording-group-engraver.cc
* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[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   Protected_scm accumulator_;
25 };
26
27 void
28 Recording_group_engraver::initialize ()
29 {
30   Engraver_group_engraver::initialize ();
31   start ();
32 }
33
34 Recording_group_engraver::Recording_group_engraver ()
35 {
36 }
37
38 void
39 Recording_group_engraver::start_translation_timestep ()
40 {
41   Engraver_group_engraver::start_translation_timestep ();
42
43
44   /*
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.
48    */
49   start () ;
50 }
51
52 void
53 Recording_group_engraver::start ()
54 {
55   if (!ly_pair_p (accumulator_))
56     accumulator_ = scm_cons (SCM_EOL, SCM_EOL);
57   if (!ly_pair_p (ly_car (accumulator_)))
58     {
59       /*
60         Need to store transposition for every moment; transposition changes during pieces.
61        */
62       scm_set_car_x (accumulator_, scm_cons (scm_cons (now_mom ().smobbed_copy (),
63                                                      get_property ("instrumentTransposition")),
64                                                      SCM_EOL));
65     }
66 }
67
68 void
69 Recording_group_engraver::stop_translation_timestep ()
70 {
71   Engraver_group_engraver::stop_translation_timestep ();
72   scm_set_cdr_x (accumulator_, scm_cons (ly_car (accumulator_), ly_cdr (accumulator_)));
73
74   scm_set_car_x (accumulator_, SCM_EOL);
75 }
76
77 void
78 Recording_group_engraver::finalize ()
79 {
80   Engraver_group_engraver::finalize ();
81   SCM proc = get_property ("recordEventSequence");
82
83   if (ly_procedure_p (proc))
84     scm_call_2  (proc, daddy_context_->self_scm (), ly_cdr (accumulator_));
85
86   accumulator_ = SCM_EOL;
87 }
88
89 bool
90 Recording_group_engraver::try_music (Music  *m)
91 {
92   bool retval = Translator_group::try_music (m);
93
94   SCM seq = ly_cdar (accumulator_);
95   seq = scm_cons (scm_cons  (m->self_scm (), ly_bool2scm (retval)),
96                  seq);
97   
98   scm_set_cdr_x  (ly_car (accumulator_), seq);
99
100   return retval;
101 }
102
103
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.",
108                   "",
109                   "",
110                   "",
111                   "recordEventSequence",
112                   "");