]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-engraver.cc
* scm/chords-ignatzek.scm (alteration->text-accidental-markup):
[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, 2003 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 "translator-group.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_ = new Item (get_property ("BassFigure"));
72       announce_grob(figure_, rest_req_->self_scm()); // todo
73       figure_->set_grob_property ("text" , scm_makfrom0str ("-"));
74     }
75   else if (figures_.size ())
76     {
77       SCM proc = get_property ("bassFigureFormatFunction");
78       if (gh_procedure_p (proc)) 
79         {
80           SCM l = SCM_EOL;
81
82           for (int i = 0; i <figures_.size (); i++)
83             l = gh_cons (figures_[i]->self_scm(), l);
84
85           SCM markup = scm_call_2 (proc, l, daddy_trans_->self_scm ());
86
87           figure_ = new Item (get_property ("BassFigure"));
88           figure_->set_grob_property ("text", markup);
89           announce_grob(figure_, figures_[0]->self_scm()); // todo
90         }
91     }
92 }
93
94   
95 ENTER_DESCRIPTION(Figured_bass_engraver,
96 /* descr */       "Make figured bass numbers.",
97 /* creats*/       "BassFigure",
98 /* accepts */     "rest-event bass-figure-event",
99 /* acks  */      "",
100 /* reads */       "bassFigureFormatFunction",
101 /* write */       "");