]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-engraver.cc
* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[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");
72       announce_grob (figure_, rest_req_->self_scm ()); // todo
73       figure_->set_property ("text" , scm_makfrom0str ("-"));
74     }
75   else if (figures_.size ())
76     {
77       SCM proc = get_property ("bassFigureFormatFunction");
78       if (ly_procedure_p (proc)) 
79         {
80           SCM l = SCM_EOL;
81           SCM * t = &l;
82           for (int i = 0; i < figures_.size (); i++)
83             {
84               *t = scm_cons (figures_[i]->self_scm (), SCM_EOL);
85               t = SCM_CDRLOC (*t);
86             }
87           figure_ = make_item ("BassFigure");
88           scm_call_3 (proc, l, daddy_context_->self_scm (),
89                       figure_->self_scm ());
90           announce_grob (figure_, figures_[0]->self_scm ()); // todo
91         }
92     }
93 }
94
95   
96 ENTER_DESCRIPTION (Figured_bass_engraver,
97 /* descr */       "Make figured bass numbers.",
98 /* creats*/       "BassFigure",
99 /* accepts */     "rest-event bass-figure-event",
100 /* acks  */      "",
101 /* reads */       "bassFigureFormatFunction",
102 /* write */       "");