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