]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-performer.cc
tie_performer: ties_created_ variable no longer needed
[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--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "performer.hh"
10
11 #include "audio-item.hh"
12 #include "context.hh"
13 #include "stream-event.hh"
14 #include "translator.icc"
15
16 class Tie_performer : public Performer
17 {
18   Stream_event *event_;
19   vector<Audio_element_info> now_heads_;
20   vector<Audio_element_info> now_tied_heads_;
21   vector<Audio_element_info> heads_to_tie_;
22
23 protected:
24   void stop_translation_timestep ();
25   void start_translation_timestep ();
26   virtual void acknowledge_audio_element (Audio_element_info);
27   void process_music ();
28   DECLARE_TRANSLATOR_LISTENER (tie);
29 public:
30   TRANSLATOR_DECLARATIONS (Tie_performer);
31 };
32
33 Tie_performer::Tie_performer ()
34 {
35   event_ = 0;
36 }
37
38 IMPLEMENT_TRANSLATOR_LISTENER (Tie_performer, tie);
39 void
40 Tie_performer::listen_tie (Stream_event *ev)
41 {
42   event_ = ev;
43 }
44
45 void
46 Tie_performer::process_music ()
47 {
48   if (event_)
49     context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
50 }
51
52 void
53 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
54 {
55   if (Audio_note *an = dynamic_cast<Audio_note *> (inf.elem_))
56     {
57       if (an->tie_event_)
58         now_tied_heads_.push_back (inf);
59       else
60         now_heads_.push_back (inf);
61
62       // Find a previous note that ties to the current note. If it exists, 
63       // remove it from the heads_to_tie vector and create the tie
64       vector<Audio_element_info>::iterator it;
65       bool found = false;
66       Stream_event *right_mus = inf.event_;
67       for ( it = heads_to_tie_.begin() ; (!found) && (it < heads_to_tie_.end()); it++ )
68         {
69           Audio_element_info et = *it;
70           Audio_note *th = dynamic_cast<Audio_note *> (et.elem_);
71           Stream_event *left_mus = et.event_;
72
73           if (th && right_mus && left_mus
74               && ly_is_equal (right_mus->get_property ("pitch"),
75                               left_mus->get_property ("pitch")))
76             {
77               found = true;
78               an->tie_to (th);
79               // this invalidates the iterator, we are leaving the loop anyway
80               heads_to_tie_.erase (it);
81             }
82         }
83     }
84 }
85
86 void
87 Tie_performer::start_translation_timestep ()
88 {
89   context ()->set_property ("tieMelismaBusy",
90                             ly_bool2scm (heads_to_tie_.size ()));
91 }
92
93 void
94 Tie_performer::stop_translation_timestep ()
95 {
96   // We might have dangling open ties like c~ d. Close them, unless we have
97   // tieWaitForNote set...
98   if (!to_boolean (get_property ("tieWaitForNote")))
99     {
100       heads_to_tie_.clear ();
101     }
102
103   if (event_)
104     {
105       heads_to_tie_ = now_heads_;
106     }
107
108   for (vsize i = now_tied_heads_.size (); i--;)
109     heads_to_tie_.push_back (now_tied_heads_[i]);
110
111   event_ = 0;
112   now_heads_.clear ();
113   now_tied_heads_.clear ();
114 }
115
116 ADD_TRANSLATOR (Tie_performer,
117                 /* doc */
118                 "Generate ties between note heads of equal pitch.",
119
120                 /* create */
121                 "",
122
123                 /* read */
124                 "tieWaitForNote",
125
126                 /* write */
127                 "tieMelismaBusy"
128                 );