]> git.donarmstrong.com Git - lilypond.git/blob - lily/align-note-column-engraver.cc
f346fb9191a36e914465c550327512e29941c502
[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 "local-key-item.hh"
15 #include "warn.hh"
16 #include "directional-element-interface.hh"
17 #include "side-position-interface.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   Grace_align_item * align_item_p_;
25   Note_column * now_column_l_;
26   Local_key_item * 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 Grace_align_item (get_property ("basicGraceAlignItemProperties"));
49   Side_position_interface (align_item_p_).set_axis (X_AXIS);
50   Side_position_interface (align_item_p_).set_direction (LEFT);
51   
52   // needed  for setting font size.
53   announce_element (Score_element_info (align_item_p_, 0));
54 }
55
56 void
57 Align_note_column_engraver::do_removal_processing ()
58 {
59   SCM al = get_property ("graceAlignPosition");
60   if (isdir_b (al))
61     {
62       Direction d = to_dir (al);
63       Directional_element_interface (align_item_p_).set (d);
64     }
65   
66   typeset_element (align_item_p_);
67   align_item_p_ =0;
68 }
69
70 void
71 Align_note_column_engraver::acknowledge_element (Score_element_info inf)
72 {
73   if (Note_column * n = dynamic_cast<Note_column*> (inf.elem_l_))
74     {
75       now_column_l_ =n;
76     }
77   else if (Local_key_item * it = dynamic_cast<Local_key_item*> (inf.elem_l_))
78     {
79       accidental_l_ = it;
80     }
81 }
82 void
83 Align_note_column_engraver::process_acknowledged ()
84 {
85   if (now_column_l_ && accidental_l_)
86     {
87       
88       /* Can't inspect  width of Local_key_item, since
89
90          A. it may not be fully built
91
92          B. it has no pscore_l_ field.
93
94       */
95       SCM grsp = get_property ("graceAccidentalSpace");
96       if (gh_number_p(grsp))
97         {
98           /*
99             ugh.
100           */
101           Real extra_space = gh_scm2double(grsp);
102           SCM e = gh_cons (gh_double2scm (-extra_space), gh_double2scm (0.0));
103           now_column_l_->set_elt_property ("extra-space", e);
104         }
105     }
106
107   if (now_column_l_)
108     {
109       Align_interface (align_item_p_).add_element (now_column_l_);
110       now_column_l_ =0;
111     }
112 }
113
114 void
115 Align_note_column_engraver::do_post_move_processing ()
116 {
117   now_column_l_ =0;
118   accidental_l_ =0;
119 }
120
121 ADD_THIS_TRANSLATOR(Align_note_column_engraver);
122