]> git.donarmstrong.com Git - lilypond.git/blob - lily/align-note-column-engraver.cc
75fb5b94e310a4569ff68d822ed413a5cc3b7330
[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
19 /**
20    Catch notes, and put them in a row. Used for aligning grace notes.
21  */
22 class Align_note_column_engraver: public Engraver
23 {
24   Item * align_item_p_;
25   Score_element * now_column_l_;
26   Score_element * accidental_l_;
27
28   virtual void process_acknowledged ();
29   virtual void do_post_move_processing ();
30   virtual void do_creation_processing ();
31   virtual void do_removal_processing ();
32   virtual void acknowledge_element (Score_element_info);
33 public:
34   VIRTUAL_COPY_CONS(Translator);
35   Align_note_column_engraver ();
36 };
37
38 Align_note_column_engraver::Align_note_column_engraver()
39 {
40   align_item_p_ =0;
41   now_column_l_ =0;
42   accidental_l_ =0;
43 }
44
45 void
46 Align_note_column_engraver::do_creation_processing ()
47 {
48   align_item_p_ = new Item (get_property ("basicGraceAlignItemProperties"));
49   Grace_align_item::set_interface (align_item_p_);
50   Side_position::set_axis (align_item_p_, X_AXIS);
51   Side_position::set_direction (align_item_p_, LEFT);
52   
53   // needed  for setting font size.
54   announce_element (align_item_p_, 0);
55 }
56
57 void
58 Align_note_column_engraver::do_removal_processing ()
59 {
60   SCM al = get_property ("graceAlignPosition");
61   if (isdir_b (al))
62     {
63       Direction d = to_dir (al);
64       Directional_element_interface (align_item_p_).set (d);
65     }
66   
67   typeset_element (align_item_p_);
68   align_item_p_ =0;
69 }
70
71 void
72 Align_note_column_engraver::acknowledge_element (Score_element_info inf)
73 {
74   if (Note_column::has_interface(inf.elem_l_))
75     {
76       now_column_l_ =inf.elem_l_;
77     }
78   else if (Local_key_item::has_interface (inf.elem_l_))
79     {
80       accidental_l_ = inf.elem_l_;
81     }
82 }
83 void
84 Align_note_column_engraver::process_acknowledged ()
85 {
86   if (now_column_l_ && accidental_l_)
87     {
88       
89       /* Can't inspect  width of Local_key_item, since
90
91          A. it may not be fully built
92
93          B. it has no pscore_l_ field.
94
95       */
96       SCM grsp = get_property ("graceAccidentalSpace");
97       if (gh_number_p(grsp))
98         {
99           /*
100             ugh.
101           */
102           Real extra_space = gh_scm2double(grsp);
103           SCM e = gh_cons (gh_double2scm (-extra_space), gh_double2scm (0.0));
104           now_column_l_->set_elt_property ("extra-space", e);
105         }
106     }
107
108   if (now_column_l_)
109     {
110       Align_interface::add_element (align_item_p_,now_column_l_);
111       now_column_l_ =0;
112     }
113 }
114
115 void
116 Align_note_column_engraver::do_post_move_processing ()
117 {
118   now_column_l_ =0;
119   accidental_l_ =0;
120 }
121
122 ADD_THIS_TRANSLATOR(Align_note_column_engraver);
123