]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-engraver.cc
update for the lily-wins.py script.
[lilypond.git] / lily / figured-bass-engraver.cc
1 /*   
2 figured-bass-engraver.cc --  implement Figured_bass_engraver
3
4 source file of the GNU LilyPond music typesetter
5
6 (c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8  */
9
10 #include "engraver.hh"
11 #include "text-item.hh"
12 #include "event.hh"
13 #include "item.hh"
14 #include "context.hh"
15
16 class Figured_bass_engraver : public Engraver
17 {
18   TRANSLATOR_DECLARATIONS (Figured_bass_engraver);
19 protected:
20   Link_array<Music> figures_;
21   Music * rest_req_;
22
23   Grob * figure_;
24   
25   virtual bool try_music (Music*);
26   virtual void stop_translation_timestep ();
27   virtual void process_music ();
28 };
29
30
31 Figured_bass_engraver::Figured_bass_engraver ()
32 {
33   figure_ = 0;
34   rest_req_ = 0;
35 }
36
37 void
38 Figured_bass_engraver::stop_translation_timestep ()
39 {
40   if (figure_)
41     {
42       typeset_grob (figure_);
43       figure_ = 0;
44     }
45
46   figures_.clear ();
47   rest_req_ = 0;
48 }
49
50 bool
51 Figured_bass_engraver::try_music (Music*m)
52 {
53   if (m->is_mus_type ("bass-figure-event"))
54     {
55       figures_.push (m);
56       return true;
57     }
58   else if (m->is_mus_type ("rest-event"))
59     {
60       rest_req_ = m;
61       return true;
62     }
63   return false;
64 }
65
66 void
67 Figured_bass_engraver::process_music ()
68 {
69   if (rest_req_)
70     {
71       figure_ = make_item ("BassFigure", rest_req_->self_scm ());
72       figure_->set_property ("text" , scm_makfrom0str ("-"));
73     }
74   else if (figures_.size ())
75     {
76       SCM proc = get_property ("bassFigureFormatFunction");
77       if (ly_c_procedure_p (proc)) 
78         {
79           SCM l = SCM_EOL;
80           SCM * t = &l;
81           for (int i = 0; i < figures_.size (); i++)
82             {
83               *t = scm_cons (figures_[i]->self_scm (), SCM_EOL);
84               t = SCM_CDRLOC (*t);
85             }
86           figure_ = make_item ("BassFigure", figures_[0]->self_scm ());
87           scm_call_3 (proc, l, context ()->self_scm (),
88                       figure_->self_scm ());
89         }
90     }
91 }
92
93   
94 ENTER_DESCRIPTION (Figured_bass_engraver,
95 /* descr */       "Make figured bass numbers.",
96 /* creats*/       "BassFigure",
97 /* accepts */     "rest-event bass-figure-event",
98 /* acks  */      "",
99 /* reads */       "bassFigureFormatFunction",
100 /* write */       "");