]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-engraver.cc
*** empty log message ***
[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   figure_ = 0;
41
42   figures_.clear ();
43   rest_req_ = 0;
44 }
45
46 bool
47 Figured_bass_engraver::try_music (Music*m)
48 {
49   if (m->is_mus_type ("bass-figure-event"))
50     {
51       figures_.push (m);
52       return true;
53     }
54   else if (m->is_mus_type ("rest-event"))
55     {
56       rest_req_ = m;
57       return true;
58     }
59   return false;
60 }
61
62 void
63 Figured_bass_engraver::process_music ()
64 {
65   if (rest_req_)
66     {
67       figure_ = make_item ("BassFigure", rest_req_->self_scm ());
68       figure_->set_property ("text" , scm_makfrom0str ("-"));
69     }
70   else if (figures_.size ())
71     {
72       SCM proc = get_property ("bassFigureFormatFunction");
73       if (ly_c_procedure_p (proc)) 
74         {
75           SCM l = SCM_EOL;
76           SCM * t = &l;
77           for (int i = 0; i < figures_.size (); i++)
78             {
79               *t = scm_cons (figures_[i]->self_scm (), SCM_EOL);
80               t = SCM_CDRLOC (*t);
81             }
82           figure_ = make_item ("BassFigure", figures_[0]->self_scm ());
83           scm_call_3 (proc, l, context ()->self_scm (),
84                       figure_->self_scm ());
85         }
86     }
87 }
88
89   
90 ENTER_DESCRIPTION (Figured_bass_engraver,
91 /* descr */       "Make figured bass numbers.",
92 /* creats*/       "BassFigure",
93 /* accepts */     "rest-event bass-figure-event",
94 /* acks  */      "",
95 /* reads */       "bassFigureFormatFunction",
96 /* write */       "");