]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-performer.cc
* lily/text-item.cc (interpret_string): new file, select font with
[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
36
37 Tie_performer::Tie_performer ()
38 {
39   event_ = 0;
40   last_event_  = 0;
41   ties_created_ = false;
42 }
43
44
45 bool
46 Tie_performer::try_music (Music *mus)
47 {
48   if (mus->is_mus_type ("tie-event"))
49     {
50       event_ = mus;
51     }
52   
53   return true;
54 }
55
56 void
57 Tie_performer::process_music ()
58 {
59   if (event_)
60     daddy_context_->set_property ("tieMelismaBusy", SCM_BOOL_T);
61 }
62
63 void
64 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
65 {
66   if (Audio_note * an = dynamic_cast<Audio_note *> (inf.elem_))
67     {
68       now_heads_.push (inf);
69       for  (int i = heads_to_tie_.size (); i--;)
70         {
71           Music * right_mus = inf.event_;
72           
73           Audio_note *th =  dynamic_cast<Audio_note*> (heads_to_tie_[i].elem_);
74           Music * left_mus = heads_to_tie_[i].event_;
75
76           if (right_mus && left_mus
77               && is_equal (right_mus->get_property ("pitch"),
78                              left_mus->get_property ("pitch")))
79             {
80               an->tie_to (th);
81               ties_created_ = true;  
82             }
83         }
84     }
85 }
86
87 void
88 Tie_performer::start_translation_timestep ()
89 {
90   daddy_context_->set_property ("tieMelismaBusy",
91                               ly_bool2scm (heads_to_tie_.size ()));
92       
93 }
94
95 void
96 Tie_performer::stop_translation_timestep ()
97 {
98   if (ties_created_)
99     {
100       heads_to_tie_.clear ();
101       last_event_ = 0;
102     }
103   
104   if (event_)
105     {
106       heads_to_tie_ = now_heads_;
107       last_event_ = event_;
108     }
109   event_ = 0;
110   now_heads_.clear ();
111 }
112
113 ENTER_DESCRIPTION (Tie_performer,
114 /* descr */       "Generate ties between noteheads of equal pitch.",
115 /* creats*/       "",
116 /* accepts */     "tie-event",
117 /* acks  */       "",
118 /* reads */       "tieMelismaBusy",
119 /* write */       "");