]> git.donarmstrong.com Git - lilypond.git/blob - lily/align-note-column-engraver.cc
a5e3c57bb8b3d19148998f3595512dc98f5fa462
[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 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "grace-align-item.hh"
12 #include "note-column.hh"
13 #include "local-key-item.hh"
14 #include "warn.hh"
15 #include "directional-element-interface.hh"
16
17 /**
18    Catch notes, and put them in a row. Used for aligning grace notes.
19  */
20 class Align_note_column_engraver: public Engraver
21 {
22   Grace_align_item * align_item_p_;
23   Note_column * now_column_l_;
24   Local_key_item * accidental_l_;
25
26   virtual void process_acknowledged ();
27   virtual void do_post_move_processing ();
28   virtual void do_creation_processing ();
29   virtual void do_removal_processing ();
30   virtual void acknowledge_element (Score_element_info);
31 public:
32   VIRTUAL_COPY_CONS(Translator);
33   Align_note_column_engraver ();
34 };
35
36 Align_note_column_engraver::Align_note_column_engraver()
37 {
38   align_item_p_ =0;
39   now_column_l_ =0;
40   accidental_l_ =0;
41 }
42
43 void
44 Align_note_column_engraver::do_creation_processing ()
45 {
46   align_item_p_ = new Grace_align_item;
47   // needed  for setting font size.
48   announce_element (Score_element_info (align_item_p_, 0));
49 }
50
51 void
52 Align_note_column_engraver::do_removal_processing ()
53 {
54   SCM al = get_property ("graceAlignPosition", 0);
55   if (isdir_b (al))
56     {
57       directional_element (align_item_p_).set (to_dir (al));
58     }
59   
60   typeset_element (align_item_p_);
61   align_item_p_ =0;
62 }
63
64 void
65 Align_note_column_engraver::acknowledge_element (Score_element_info inf)
66 {
67   if (Note_column * n = dynamic_cast<Note_column*> (inf.elem_l_))
68     {
69       now_column_l_ =n;
70     }
71   else if (Local_key_item * it = dynamic_cast<Local_key_item*> (inf.elem_l_))
72     {
73       accidental_l_ = it;
74     }
75 }
76 void
77 Align_note_column_engraver::process_acknowledged ()
78 {
79   if (now_column_l_ && accidental_l_)
80     {
81       
82       /* Can't inspect  width of Local_key_item, since
83
84          A. it may not be fully built
85
86          B. it has no pscore_l_ field.
87
88       */
89       SCM grsp = get_property ("graceAccidentalSpace", 0);
90       if (gh_number_p(grsp))
91         {
92           /*
93             ugh.
94           */
95           Real extra_space = gh_scm2double(grsp);
96           SCM e = gh_cons (gh_double2scm (-extra_space), gh_double2scm (0.0));
97           now_column_l_->set_elt_property ("extra-space", e);
98         }
99     }
100
101   if (now_column_l_)
102     {
103       align_item_p_->add_element (now_column_l_);
104       now_column_l_ =0;
105     }
106 }
107
108 void
109 Align_note_column_engraver::do_post_move_processing ()
110 {
111   now_column_l_ =0;
112   accidental_l_ =0;
113 }
114
115 ADD_THIS_TRANSLATOR(Align_note_column_engraver);
116