]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-performer.cc
* lily/*-performer.cc: Converted try_music to listen_*
[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   Stream_event *last_event_;
21   vector<Audio_element_info> now_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   last_event_ = 0;
40   ties_created_ = false;
41 }
42
43 IMPLEMENT_TRANSLATOR_LISTENER (Tie_performer, tie);
44 void
45 Tie_performer::listen_tie (Stream_event *ev)
46 {
47   event_ = ev;
48 }
49
50 void
51 Tie_performer::process_music ()
52 {
53   if (event_)
54     context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
55 }
56
57 void
58 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
59 {
60   if (Audio_note *an = dynamic_cast<Audio_note *> (inf.elem_))
61     {
62       now_heads_.push_back (inf);
63       for (vsize i = heads_to_tie_.size (); i--;)
64         {
65           Stream_event *right_mus = inf.event_;
66
67           Audio_note *th = dynamic_cast<Audio_note *> (heads_to_tie_[i].elem_);
68           Stream_event *left_mus = heads_to_tie_[i].event_;
69
70           if (right_mus && left_mus
71               && ly_is_equal (right_mus->get_property ("pitch"),
72                               left_mus->get_property ("pitch")))
73             {
74               an->tie_to (th);
75               ties_created_ = true;
76             }
77         }
78     }
79 }
80
81 void
82 Tie_performer::start_translation_timestep ()
83 {
84   context ()->set_property ("tieMelismaBusy",
85                             ly_bool2scm (heads_to_tie_.size ()));
86 }
87
88 void
89 Tie_performer::stop_translation_timestep ()
90 {
91   if (ties_created_)
92     {
93       heads_to_tie_.clear ();
94       last_event_ = 0;
95       ties_created_ = false;
96     }
97
98   if (event_)
99     {
100       heads_to_tie_ = now_heads_;
101       last_event_ = event_;
102     }
103   event_ = 0;
104   now_heads_.clear ();
105 }
106
107 ADD_TRANSLATOR (Tie_performer,
108                 /* doc */ "Generate ties between noteheads of equal pitch.",
109                 /* create */ "",
110                 /* accept */ "tie-event",
111                 /* read */ "tieMelismaBusy",
112                 /* write */ "");