]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-engraver.cc
release: 1.5.10
[lilypond.git] / lily / figured-bass-engraver.cc
1 #include "engraver.hh"
2 #include "text-item.hh"
3 #include "musical-request.hh"
4 #include "item.hh"
5
6 class Figured_bass_engraver : public Engraver
7 {
8 public:
9   VIRTUAL_COPY_CONS(Translator);
10   Figured_bass_engraver();
11
12 protected:
13   Link_array<Note_req> figures_;
14   Rest_req * rest_req_;
15
16   Grob * figure_;
17   
18   virtual bool try_music (Music*);
19   virtual void stop_translation_timestep ();
20   virtual void process_music ();
21 };
22
23
24 Figured_bass_engraver::Figured_bass_engraver()
25 {
26   figure_ = 0;
27   rest_req_ = 0;
28 }
29
30 void
31 Figured_bass_engraver::stop_translation_timestep ()
32 {
33   if (figure_)
34     {
35       typeset_grob (figure_);
36       figure_ =00;
37     }
38
39   figures_.clear ();
40 }
41
42 bool
43 Figured_bass_engraver::try_music (Music*m)
44 {
45   if (Note_req* n = dynamic_cast<Note_req*> (m))
46     {
47       figures_.push (n);
48       return true;
49     }
50   else if (Rest_req * r = dynamic_cast<Rest_req*> (m))
51     {
52       rest_req_ = r;
53       return true;
54     }
55   return false;
56 }
57
58 void
59 Figured_bass_engraver::process_music ()
60 {
61   if (rest_req_)
62     {
63       figure_ = new Item (get_property ("BassFigure"));
64       announce_grob (figure_, rest_req_); // todo
65       figure_->set_grob_property ("text" , gh_str02scm ("-"));
66     }
67   else if (figures_.size ())
68     {
69       figure_ = new Item (get_property ("BassFigure"));
70       announce_grob (figure_, figures_[0]); // todo
71       SCM flist = SCM_EOL;
72       for (int i = 0; i < figures_.size (); i++)
73         {
74           Note_req * n = figures_[i];
75           Pitch *p = unsmob_pitch (n->get_mus_property ("pitch"));
76           
77           String fstr = to_str (p->steps ()+ 1);
78           
79           SCM one_fig = ly_str02scm(fstr.ch_C ());
80
81           if (p->alteration_i_ || to_boolean (n->get_mus_property ("force-accidental") ))
82             {
83               SCM alter = scm_assoc (gh_int2scm (p->alteration_i_),
84                                      figure_->get_grob_property ("accidental-alist"));
85               if (gh_pair_p (alter))
86                 {
87                   one_fig = gh_list (ly_symbol2scm ("columns"),
88                                      one_fig,
89                                      gh_cdr(alter),
90                                      SCM_UNDEFINED);
91                 }
92             }
93           
94           flist = gh_cons (one_fig, flist);
95         }
96
97       flist = gh_cons (ly_symbol2scm ("lines"), flist);
98
99       figure_-> set_grob_property ("text", flist);
100     }
101 }
102
103   
104 ADD_THIS_TRANSLATOR(Figured_bass_engraver);