]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
patch::: 1.3.111.jcn2
[lilypond.git] / lily / note-head-line-engraver.cc
1 /*   
2   note-head-line-engraver.cc -- implement Note_head_line_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "engraver.hh"
10 #include "group-interface.hh"
11 #include "item.hh"
12 #include "musical-request.hh"
13 #include "spanner.hh"
14 #include "rhythmic-head.hh"
15 #include "side-position-interface.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "translator-group.hh"
18 #include "protected-scm.hh"
19
20 /**
21    Create line-spanner grobs for glissandi (and possibly other) lines
22    that connect note heads.
23  */
24
25 class Note_head_line_engraver : public Engraver
26 {
27 public:
28   VIRTUAL_COPY_CONS (Translator);
29   Note_head_line_engraver ();
30
31 protected:
32   virtual void acknowledge_grob (Grob_info);
33   virtual void create_grobs ();
34   virtual void stop_translation_timestep ();
35   virtual bool try_music (Music *);
36
37 private:
38   Spanner* line_; 
39   Request* req_;
40   Protected_scm heads_;
41   Translator* last_staff_;
42   Grob* last_head_;
43 };
44
45 Note_head_line_engraver::Note_head_line_engraver ()
46 {
47   line_ = 0;
48   req_ = 0;
49   heads_ = SCM_EOL;
50   last_head_ = 0;
51   last_staff_ = 0;
52 }
53
54 bool
55 Note_head_line_engraver::try_music (Music* m)
56 {
57   if (!req_)
58     {
59       if (Glissando_req *r = dynamic_cast<Glissando_req*> (m))
60         {
61           req_ = r;
62           return true;
63         }
64     }
65   return false;
66 }
67
68 void
69 Note_head_line_engraver::acknowledge_grob (Grob_info info)
70 {
71   if (Rhythmic_head::has_interface (info.elem_l_))
72     {
73       if (req_)
74         heads_ = gh_cons (info.elem_l_->self_scm (), heads_);
75       else if (to_boolean (get_property ("followThread")))
76         {
77           Translator* staff = daddy_trans_l_ && daddy_trans_l_->daddy_trans_l_
78             ? daddy_trans_l_->daddy_trans_l_->daddy_trans_l_ : 0;
79           if (staff != last_staff_)
80             {
81               if (last_head_)
82                 heads_ = gh_list (info.elem_l_->self_scm (),
83                                   last_head_->self_scm (), SCM_UNDEFINED);
84               last_staff_ = staff;
85             }
86           last_head_ = info.elem_l_;
87         }
88     }
89 }
90
91 void
92 Note_head_line_engraver::create_grobs ()
93 {
94   if (!line_ && scm_ilength (heads_) > 1)
95     {
96       /* type Glissando? */
97       line_ = new Spanner (get_property ("NoteHeadLine"));
98       line_->set_bound (LEFT, unsmob_grob (gh_car (heads_)));
99       line_->set_bound (RIGHT, unsmob_grob (ly_last (heads_)));
100
101       line_->set_parent (unsmob_grob (gh_car (heads_)), X_AXIS);
102       line_->set_parent (unsmob_grob (gh_car (heads_)), Y_AXIS);
103
104       line_->set_parent (unsmob_grob (ly_last (heads_)), X_AXIS);
105       line_->set_parent (unsmob_grob (ly_last (heads_)), Y_AXIS);
106
107       announce_grob (line_, req_);
108       req_ = 0;
109       heads_ = SCM_EOL;
110     }
111 }
112
113 void
114 Note_head_line_engraver::stop_translation_timestep ()
115 {
116   if (line_)
117     {
118       typeset_grob (line_);
119       line_ = 0;
120     }
121 }
122
123
124 ADD_THIS_TRANSLATOR (Note_head_line_engraver);
125