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