]> git.donarmstrong.com Git - lilypond.git/blob - lily/arpeggio-engraver.cc
19fc31342bd74f778adb30b972c439c3fe2de89c
[lilypond.git] / lily / arpeggio-engraver.cc
1 /*   
2   arpeggio-engraver.cc -- implement Arpeggio_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "engraver.hh"
10 #include "group-interface.hh"
11 #include "item.hh"
12 #include "musical-request.hh"
13 #include "arpeggio.hh"
14 #include "stem.hh"
15 #include "rhythmic-head.hh"
16 #include "side-position-interface.hh"
17 #include "note-column.hh"
18
19 class Arpeggio_engraver : public Engraver
20 {
21 public:
22   TRANSLATOR_DECLARATIONS(Arpeggio_engraver); 
23 protected:
24   virtual void acknowledge_grob (Grob_info);
25   virtual void process_music ();
26
27   virtual void stop_translation_timestep ();
28   virtual bool try_music (Music *);
29
30 private:
31   Item* arpeggio_; 
32   Arpeggio_req *arpeggio_req_;
33 };
34
35 Arpeggio_engraver::Arpeggio_engraver ()
36 {
37   arpeggio_ = 0;
38   arpeggio_req_ = 0;
39 }
40
41 bool
42 Arpeggio_engraver::try_music (Music* m)
43 {
44   if (!arpeggio_req_)
45     {
46       if (Arpeggio_req *a = dynamic_cast<Arpeggio_req*> (m))
47         {
48           arpeggio_req_ = a;
49           return true;
50         }
51     }
52   return false;
53 }
54
55 void
56 Arpeggio_engraver::acknowledge_grob (Grob_info info)
57 {
58   if (arpeggio_)
59     {
60       if (Stem::has_interface (info.grob_))
61         {
62           if (!arpeggio_->get_parent  (Y_AXIS))
63             arpeggio_->set_parent (info.grob_, Y_AXIS);
64       
65           Pointer_group_interface::add_grob (arpeggio_, ly_symbol2scm ("stems"), info.grob_);
66         }
67       
68       /*
69         We can't catch local key items (accidentals) from Voice context,
70         see Local_key_engraver
71       */
72       else if (Rhythmic_head::has_interface (info.grob_))
73         {
74           Side_position_interface::add_support (arpeggio_, info.grob_);
75         }
76       else if (Note_column::has_interface (info.grob_ ))
77         {
78           info.grob_->set_grob_property ("arpeggio", arpeggio_->self_scm ());
79         }
80     }
81 }
82
83 void
84 Arpeggio_engraver::process_music ()
85 {
86   if (arpeggio_req_)
87     {
88       arpeggio_ = new Item (get_property ("Arpeggio"));
89       announce_grob(arpeggio_, arpeggio_req_->self_scm());
90     }
91 }
92
93 void
94 Arpeggio_engraver::stop_translation_timestep ()
95 {
96   if (arpeggio_)
97     {
98       typeset_grob (arpeggio_);
99       arpeggio_ = 0;
100     }
101   arpeggio_req_ = 0;
102 }
103
104
105
106
107 ENTER_DESCRIPTION(Arpeggio_engraver,
108 /* descr */       "Generate an Arpeggio from a Arpeggio_req",
109 /* creats*/       "Arpeggio",
110 /* accepts */     "general-music",
111 /* acks  */      "stem-interface rhythmic-head-interface note-column-interface",
112 /* reads */       "",
113 /* write */       "");