]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-performer.cc
*** empty log message ***
[lilypond.git] / lily / tie-performer.cc
1 /*   
2   new-tie-engraver.cc --  implement Tie_performer
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "context.hh"
11 #include "audio-item.hh"
12 #include "pqueue.hh"
13 #include "performer.hh"
14
15 class Tie_performer : public Performer
16 {
17   Music *event_;
18   Music *last_event_;
19   Array<Audio_element_info> now_heads_;
20   Array<Audio_element_info> heads_to_tie_;
21
22   bool ties_created_;
23   
24 protected:
25   virtual void stop_translation_timestep ();
26   virtual void start_translation_timestep ();
27   virtual void acknowledge_audio_element (Audio_element_info);
28   virtual bool try_music (Music*);
29   virtual void process_music ();
30 public:
31   TRANSLATOR_DECLARATIONS (Tie_performer);
32 };
33
34 Tie_performer::Tie_performer ()
35 {
36   event_ = 0;
37   last_event_  = 0;
38   ties_created_ = false;
39 }
40
41 bool
42 Tie_performer::try_music (Music *mus)
43 {
44   if (mus->is_mus_type ("tie-event"))
45     {
46       event_ = mus;
47     }
48   
49   return true;
50 }
51
52 void
53 Tie_performer::process_music ()
54 {
55   if (event_)
56     context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
57 }
58
59 void
60 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
61 {
62   if (Audio_note * an = dynamic_cast<Audio_note *> (inf.elem_))
63     {
64       now_heads_.push (inf);
65       for  (int i = heads_to_tie_.size (); i--;)
66         {
67           Music * right_mus = inf.event_;
68           
69           Audio_note *th =  dynamic_cast<Audio_note*> (heads_to_tie_[i].elem_);
70           Music * left_mus = heads_to_tie_[i].event_;
71
72           if (right_mus && left_mus
73               && ly_c_equal_p (right_mus->get_property ("pitch"),
74                                left_mus->get_property ("pitch")))
75             {
76               an->tie_to (th);
77               ties_created_ = true;  
78             }
79         }
80     }
81 }
82
83 void
84 Tie_performer::start_translation_timestep ()
85 {
86   context ()->set_property ("tieMelismaBusy",
87                             ly_bool2scm (heads_to_tie_.size ()));
88       
89 }
90
91 void
92 Tie_performer::stop_translation_timestep ()
93 {
94   if (ties_created_)
95     {
96       heads_to_tie_.clear ();
97       last_event_ = 0;
98       ties_created_ = false;
99     }
100   
101   if (event_)
102     {
103       heads_to_tie_ = now_heads_;
104       last_event_ = event_;
105     }
106   event_ = 0;
107   now_heads_.clear ();
108 }
109
110 ADD_TRANSLATOR (Tie_performer,
111 /* descr */       "Generate ties between noteheads of equal pitch.",
112 /* creats*/       "",
113 /* accepts */     "tie-event",
114 /* acks  */       "",
115 /* reads */       "tieMelismaBusy",
116 /* write */       "");