]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
patch::: 1.3.111.jcn1
[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 "protected-scm.hh"
18
19 /**
20    Create line-spanner grobs for glissandi (and possibly other) lines
21    that connect note heads.
22  */
23
24 class Note_head_line_engraver : public Engraver
25 {
26 public:
27   VIRTUAL_COPY_CONS (Translator);
28   Note_head_line_engraver ();
29
30 protected:
31   virtual void acknowledge_grob (Grob_info);
32   virtual void create_grobs ();
33   virtual void stop_translation_timestep ();
34   virtual bool try_music (Music *);
35
36 private:
37   Spanner* line_; 
38   Request* req_;
39   Protected_scm heads_;
40 };
41
42 Note_head_line_engraver::Note_head_line_engraver ()
43 {
44   line_ = 0;
45   req_ = 0;
46   heads_ = SCM_EOL;
47 }
48
49 bool
50 Note_head_line_engraver::try_music (Music* m)
51 {
52   if (!req_)
53     {
54       if (Glissando_req *r = dynamic_cast<Glissando_req*> (m))
55         {
56           req_ = r;
57           return true;
58         }
59     }
60   return false;
61 }
62
63 void
64 Note_head_line_engraver::acknowledge_grob (Grob_info info)
65 {
66   if (req_)
67     {
68       if (Rhythmic_head::has_interface (info.elem_l_))
69         {
70           heads_ = gh_cons (info.elem_l_->self_scm (), heads_);
71         }
72     }
73 }
74
75 void
76 Note_head_line_engraver::create_grobs ()
77 {
78   if (!line_ && scm_ilength (heads_) > 1)
79     {
80       /* type Glissando? */
81       line_ = new Spanner (get_property ("NoteHeadLine"));
82       line_->set_bound (LEFT, unsmob_grob (gh_car (heads_)));
83       line_->set_bound (RIGHT, unsmob_grob (ly_last (heads_)));
84
85       line_->set_parent (unsmob_grob (gh_car (heads_)), X_AXIS);
86       line_->set_parent (unsmob_grob (gh_car (heads_)), Y_AXIS);
87
88       line_->set_parent (unsmob_grob (ly_last (heads_)), X_AXIS);
89       line_->set_parent (unsmob_grob (ly_last (heads_)), Y_AXIS);
90
91       announce_grob (line_, req_);
92       req_ = 0;
93       heads_ = SCM_EOL;
94     }
95 }
96
97 void
98 Note_head_line_engraver::stop_translation_timestep ()
99 {
100   if (line_)
101     {
102       typeset_grob (line_);
103       line_ = 0;
104     }
105 }
106
107
108 ADD_THIS_TRANSLATOR (Note_head_line_engraver);
109