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