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