]> git.donarmstrong.com Git - lilypond.git/blob - lily/align-note-column-engraver.cc
patch::: 1.3.108.jcn5
[lilypond.git] / lily / align-note-column-engraver.cc
1 /*   
2   align-note-column-engraver.cc --  implement Align_note_column_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "grace-align-item.hh"
12 #include "align-interface.hh"
13 #include "note-column.hh"
14 #include "warn.hh"
15 #include "directional-element-interface.hh"
16 #include "side-position-interface.hh"
17 #include "local-key-item.hh"
18 #include "paper-def.hh"
19
20 /**
21    Catch notes, and put them in a row. Used for aligning grace notes.
22  */
23 class Align_note_column_engraver: public Engraver
24 {
25   Item * align_item_p_;
26   Score_element * now_column_l_;
27   Score_element * accidental_l_;
28
29   virtual void process_acknowledged ();
30   virtual void do_post_move_processing ();
31   virtual void do_creation_processing ();
32   virtual void do_removal_processing ();
33   virtual void acknowledge_element (Score_element_info);
34 public:
35   VIRTUAL_COPY_CONS(Translator);
36   Align_note_column_engraver ();
37 };
38
39 Align_note_column_engraver::Align_note_column_engraver()
40 {
41   align_item_p_ =0;
42   now_column_l_ =0;
43   accidental_l_ =0;
44 }
45
46 void
47 Align_note_column_engraver::do_creation_processing ()
48 {
49   align_item_p_ = new Item (get_property ("GraceAlignment"));
50   Grace_align_item::set_interface (align_item_p_);
51   Side_position::set_axis (align_item_p_, X_AXIS);
52   Side_position::set_direction (align_item_p_, LEFT);
53   
54   // needed  for setting font size.
55   announce_element (align_item_p_, 0);
56 }
57
58 void
59 Align_note_column_engraver::do_removal_processing ()
60 {
61   if (!align_item_p_)
62     {
63       programming_error ("Align_note_column_engraver:: urg\n");
64       return;
65     }
66   
67   SCM al = get_property ("graceAlignPosition");
68   if (isdir_b (al))
69     {
70       Direction d = to_dir (al);
71       Directional_element_interface::set (align_item_p_,d);
72     }
73   
74   typeset_element (align_item_p_);
75   align_item_p_ =0;
76 }
77
78 void
79 Align_note_column_engraver::acknowledge_element (Score_element_info inf)
80 {
81   if (Note_column::has_interface(inf.elem_l_))
82     {
83       now_column_l_ =inf.elem_l_;
84     }
85   else if (Local_key_item::has_interface (inf.elem_l_))
86     {
87       accidental_l_ = inf.elem_l_;
88     }
89 }
90 void
91 Align_note_column_engraver::process_acknowledged ()
92 {
93   if (now_column_l_ && accidental_l_)
94     {
95       
96       /* Can't inspect  width of Local_key_item, since
97
98          A. it may not be fully built
99
100          B. it has no pscore_l_ field.
101
102
103          UGH UGH: separate note-spacing into  separate class,  and
104          use that to space grace notes.  
105       */
106       SCM grsp = get_property ("graceAccidentalSpace") ;
107       if (gh_number_p(grsp))
108         {
109           /*
110             ugh.
111           */
112           Real extra_space = gh_scm2double(grsp);
113           SCM e = gh_cons (gh_double2scm (-extra_space),
114                            gh_double2scm (0.0));
115           now_column_l_->set_elt_property ("extra-space", e);
116         }
117     }
118
119   if (now_column_l_ && !align_item_p_)
120     programming_error ("Align_note_column_engraver:: urg\n");
121   else
122       
123   if (now_column_l_)
124     {
125         
126       Align_interface::add_element (align_item_p_,now_column_l_);
127       now_column_l_ =0;
128     }
129 }
130
131 void
132 Align_note_column_engraver::do_post_move_processing ()
133 {
134   now_column_l_ =0;
135   accidental_l_ =0;
136 }
137
138 ADD_THIS_TRANSLATOR(Align_note_column_engraver);
139