]> git.donarmstrong.com Git - lilypond.git/blob - lily/align-note-column-engraver.cc
431e013fad1ab7756d5fcec5987f86db3fe94d27
[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   SCM al = get_property ("graceAlignPosition");
62   if (isdir_b (al))
63     {
64       Direction d = to_dir (al);
65       Directional_element_interface::set (align_item_p_,d);
66     }
67   
68   typeset_element (align_item_p_);
69   align_item_p_ =0;
70 }
71
72 void
73 Align_note_column_engraver::acknowledge_element (Score_element_info inf)
74 {
75   if (Note_column::has_interface(inf.elem_l_))
76     {
77       now_column_l_ =inf.elem_l_;
78     }
79   else if (Local_key_item::has_interface (inf.elem_l_))
80     {
81       accidental_l_ = inf.elem_l_;
82     }
83 }
84 void
85 Align_note_column_engraver::process_acknowledged ()
86 {
87   if (now_column_l_ && accidental_l_)
88     {
89       
90       /* Can't inspect  width of Local_key_item, since
91
92          A. it may not be fully built
93
94          B. it has no pscore_l_ field.
95
96
97          UGH UGH: separate note-spacing into  separate class,  and
98          use that to space grace notes.  
99       */
100       SCM grsp = get_property ("graceAccidentalSpace") ;
101       if (gh_number_p(grsp))
102         {
103           /*
104             ugh.
105           */
106           Real extra_space = gh_scm2double(grsp);
107           SCM e = gh_cons (gh_double2scm (-extra_space * paper_l ()->get_var ("staffspace")),
108                            gh_double2scm (0.0));
109           now_column_l_->set_elt_property ("extra-space", e);
110         }
111     }
112
113   if (now_column_l_)
114     {
115       Align_interface::add_element (align_item_p_,now_column_l_);
116       now_column_l_ =0;
117     }
118 }
119
120 void
121 Align_note_column_engraver::do_post_move_processing ()
122 {
123   now_column_l_ =0;
124   accidental_l_ =0;
125 }
126
127 ADD_THIS_TRANSLATOR(Align_note_column_engraver);
128