]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-performer.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "performer.hh"
10
11 #include "music.hh"
12 #include "context.hh"
13 #include "audio-item.hh"
14 #include "pqueue.hh"
15
16 class Tie_performer : public Performer
17 {
18   Music *event_;
19   Music *last_event_;
20   vector<Audio_element_info> now_heads_;
21   vector<Audio_element_info> heads_to_tie_;
22
23   bool ties_created_;
24
25 protected:
26   void stop_translation_timestep ();
27   void start_translation_timestep ();
28   virtual void acknowledge_audio_element (Audio_element_info);
29   virtual bool try_music (Music *);
30   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     event_ = mus;
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_back (inf);
64       for (vsize 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_is_equal (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 void
90 Tie_performer::stop_translation_timestep ()
91 {
92   if (ties_created_)
93     {
94       heads_to_tie_.clear ();
95       last_event_ = 0;
96       ties_created_ = false;
97     }
98
99   if (event_)
100     {
101       heads_to_tie_ = now_heads_;
102       last_event_ = event_;
103     }
104   event_ = 0;
105   now_heads_.clear ();
106 }
107
108 #include "translator.icc"
109
110 ADD_TRANSLATOR (Tie_performer,
111                 /* doc */ "Generate ties between noteheads of equal pitch.",
112                 /* create */ "",
113                 /* accept */ "tie-event",
114                 /* read */ "tieMelismaBusy",
115                 /* write */ "");