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