]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
Configure only pristine build tree or on user
[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--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "engraver.hh"
10 #include "group-interface.hh"
11 #include "item.hh"
12 #include "event.hh"
13 #include "spanner.hh"
14 #include "stem.hh"
15 #include "rhythmic-head.hh"
16 #include "side-position-interface.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "context.hh"
19
20
21 /**
22    Create line-spanner grobs for lines that connect note heads.
23
24    TODO: have the line commit suicide if the notes are connected with
25    either slur or beam.
26
27 */
28 class Note_head_line_engraver : public Engraver
29 {
30 public:
31   TRANSLATOR_DECLARATIONS (Note_head_line_engraver);
32
33 protected:
34   virtual void acknowledge_grob (Grob_info);
35   virtual void process_acknowledged_grobs ();
36   virtual void stop_translation_timestep ();
37
38 private:
39   Spanner* line_; 
40   Context* last_staff_;
41   bool follow_;
42   Grob* head_;
43   Grob* last_head_;
44 };
45
46 Note_head_line_engraver::Note_head_line_engraver ()
47 {
48   line_ = 0;
49   follow_ = false;
50   head_ = 0;
51   last_head_ = 0;
52   last_staff_ = 0;
53 }
54
55 void
56 Note_head_line_engraver::acknowledge_grob (Grob_info info)
57 {
58   if (Rhythmic_head::has_interface (info.grob_))
59     {
60       head_ = info.grob_;
61       if (to_boolean (get_property ("followVoice")))
62         {
63           Context * tr = context ();
64           while (tr && !tr->is_alias (ly_symbol2scm ( "Staff")))
65             tr = tr->get_parent_context () ;
66
67           if (tr
68               && tr->is_alias (ly_symbol2scm ("Staff")) && tr != last_staff_)
69             {
70               if (last_head_)
71                 follow_ = true;
72               last_staff_ = tr;
73             }
74         }
75     }
76 }
77
78
79 void
80 Note_head_line_engraver::process_acknowledged_grobs ()
81 {
82   if (!line_ && follow_ && last_head_ && head_)
83     {
84       /* TODO: Don't follow if there's a beam.
85
86          We can't do beam-stuff here, since beam doesn't exist yet.
87          Should probably store follow_ in line_, and suicide at some
88          later point */
89       if (follow_)
90         line_ = make_spanner ("VoiceFollower", head_->self_scm ());
91           
92       line_->set_bound (LEFT, last_head_);
93       line_->set_bound (RIGHT, head_);
94       
95
96       follow_ = false;
97     }
98 }
99
100 void
101 Note_head_line_engraver::stop_translation_timestep ()
102 {
103   line_ = 0;
104   if (head_)
105     last_head_ = head_;
106   head_ = 0;
107 }
108
109
110
111
112 ENTER_DESCRIPTION (Note_head_line_engraver,
113 /* descr */       "Engrave a line between two note heads, for example a glissando.  If "
114 " followVoice is set, staff switches also generate a line.",
115 /* creats*/       "Glissando VoiceFollower",
116 /* accepts */     "glissando-event",
117 /* acks  */       "rhythmic-head-interface",
118 /* reads */       "followVoice",
119 /* write */       "");