]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-performer.cc
* Documentation/user/examples.itely (Transcription of mensural
[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 "audio-item.hh"
12 #include "context.hh"
13 #include "pqueue.hh"
14 #include "stream-event.hh"
15 #include "translator.icc"
16
17 class Tie_performer : public Performer
18 {
19   Stream_event *event_;
20   vector<Audio_element_info> now_heads_;
21   vector<Audio_element_info> now_tied_heads_;
22   vector<Audio_element_info> heads_to_tie_;
23
24   bool ties_created_;
25
26 protected:
27   void stop_translation_timestep ();
28   void start_translation_timestep ();
29   virtual void acknowledge_audio_element (Audio_element_info);
30   void process_music ();
31   DECLARE_TRANSLATOR_LISTENER (tie);
32 public:
33   TRANSLATOR_DECLARATIONS (Tie_performer);
34 };
35
36 Tie_performer::Tie_performer ()
37 {
38   event_ = 0;
39   ties_created_ = false;
40 }
41
42 IMPLEMENT_TRANSLATOR_LISTENER (Tie_performer, tie);
43 void
44 Tie_performer::listen_tie (Stream_event *ev)
45 {
46   event_ = ev;
47 }
48
49 void
50 Tie_performer::process_music ()
51 {
52   if (event_)
53     context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
54 }
55
56 void
57 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
58 {
59   if (Audio_note *an = dynamic_cast<Audio_note *> (inf.elem_))
60     {
61       if (an->tie_event_)
62         now_tied_heads_.push_back (inf);
63       else
64         now_heads_.push_back (inf);
65
66       for (vsize i = heads_to_tie_.size (); i--;)
67         {
68           Stream_event *right_mus = inf.event_;
69
70           Audio_note *th = dynamic_cast<Audio_note *> (heads_to_tie_[i].elem_);
71           Stream_event *left_mus = heads_to_tie_[i].event_;
72
73           if (right_mus && left_mus
74               && ly_is_equal (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 void
92 Tie_performer::stop_translation_timestep ()
93 {
94   if (ties_created_)
95     {
96       heads_to_tie_.clear ();
97       ties_created_ = false;
98     }
99
100   if (event_)
101     {
102       heads_to_tie_ = now_heads_;
103     }
104
105   for (vsize i = now_tied_heads_.size(); i--;)
106     heads_to_tie_.push_back (now_tied_heads_[i]);
107
108   event_ = 0;
109   now_heads_.clear ();
110   now_tied_heads_.clear ();
111 }
112
113 ADD_TRANSLATOR (Tie_performer,
114                 /* doc */ "Generate ties between noteheads of equal pitch.",
115                 /* create */ "",
116                 /* read */ "tieMelismaBusy",
117                 /* write */ "");