* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[lilypond.git] / lily / tie-performer.cc
blobeeb0a37ec39ff9c2f383f25d6d616d2dafc6f1e3
1 /*
2 new-tie-engraver.cc -- implement Tie_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "context.hh"
11 #include "audio-item.hh"
12 #include "event.hh"
13 #include "pqueue.hh"
14 #include "performer.hh"
16 class Tie_performer : public Performer
18 Music *event_;
19 Music *last_event_;
20 Array<Audio_element_info> now_heads_;
21 Array<Audio_element_info> heads_to_tie_;
23 bool ties_created_;
25 protected:
26 virtual void stop_translation_timestep ();
27 virtual void start_translation_timestep ();
28 virtual void acknowledge_audio_element (Audio_element_info);
29 virtual bool try_music (Music*);
30 virtual void process_music ();
31 public:
32 TRANSLATOR_DECLARATIONS (Tie_performer);
37 Tie_performer::Tie_performer ()
39 event_ = 0;
40 last_event_ = 0;
41 ties_created_ = false;
45 bool
46 Tie_performer::try_music (Music *mus)
48 if (mus->is_mus_type ("tie-event"))
50 event_ = mus;
53 return true;
56 void
57 Tie_performer::process_music ()
59 if (event_)
60 daddy_context_->set_property ("tieMelismaBusy", SCM_BOOL_T);
63 void
64 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
66 if (Audio_note * an = dynamic_cast<Audio_note *> (inf.elem_))
68 now_heads_.push (inf);
69 for (int i = heads_to_tie_.size (); i--;)
71 Music * right_mus = inf.event_;
73 Audio_note *th = dynamic_cast<Audio_note*> (heads_to_tie_[i].elem_);
74 Music * left_mus = heads_to_tie_[i].event_;
76 if (right_mus && left_mus
77 && ly_equal_p (right_mus->get_property ("pitch"),
78 left_mus->get_property ("pitch")))
80 an->tie_to (th);
81 ties_created_ = true;
87 void
88 Tie_performer::start_translation_timestep ()
90 daddy_context_->set_property ("tieMelismaBusy",
91 ly_bool2scm (heads_to_tie_.size ()));
95 void
96 Tie_performer::stop_translation_timestep ()
98 if (ties_created_)
100 heads_to_tie_.clear ();
101 last_event_ = 0;
104 if (event_)
106 heads_to_tie_ = now_heads_;
107 last_event_ = event_;
109 event_ = 0;
110 now_heads_.clear ();
113 ENTER_DESCRIPTION (Tie_performer,
114 /* descr */ "Generate ties between noteheads of equal pitch.",
115 /* creats*/ "",
116 /* accepts */ "tie-event",
117 /* acks */ "",
118 /* reads */ "tieMelismaBusy",
119 /* write */ "");