]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-performer.cc
* lily/context.cc (where_defined): also assign value in
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.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
17 class Tie_performer : public Performer
18 {
19   Music *event_;
20   Music *last_event_;
21   Array<Audio_element_info> now_heads_;
22   Array<Audio_element_info> heads_to_tie_;
23
24   bool ties_created_;
25
26 protected:
27   PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
28   PRECOMPUTED_VIRTUAL void start_translation_timestep ();
29   virtual void acknowledge_audio_element (Audio_element_info);
30   virtual bool try_music (Music *);
31   PRECOMPUTED_VIRTUAL void process_music ();
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 bool
44 Tie_performer::try_music (Music *mus)
45 {
46   if (mus->is_mus_type ("tie-event"))
47     {
48       event_ = mus;
49     }
50
51   return true;
52 }
53
54 void
55 Tie_performer::process_music ()
56 {
57   if (event_)
58     context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
59 }
60
61 void
62 Tie_performer::acknowledge_audio_element (Audio_element_info inf)
63 {
64   if (Audio_note *an = dynamic_cast<Audio_note *> (inf.elem_))
65     {
66       now_heads_.push (inf);
67       for (int i = heads_to_tie_.size (); i--;)
68         {
69           Music *right_mus = inf.event_;
70
71           Audio_note *th = dynamic_cast<Audio_note *> (heads_to_tie_[i].elem_);
72           Music *left_mus = heads_to_tie_[i].event_;
73
74           if (right_mus && left_mus
75               && ly_is_equal (right_mus->get_property ("pitch"),
76                                left_mus->get_property ("pitch")))
77             {
78               an->tie_to (th);
79               ties_created_ = true;
80             }
81         }
82     }
83 }
84
85 void
86 Tie_performer::start_translation_timestep ()
87 {
88   context ()->set_property ("tieMelismaBusy",
89                             ly_bool2scm (heads_to_tie_.size ()));
90 }
91
92 void
93 Tie_performer::stop_translation_timestep ()
94 {
95   if (ties_created_)
96     {
97       heads_to_tie_.clear ();
98       last_event_ = 0;
99       ties_created_ = false;
100     }
101
102   if (event_)
103     {
104       heads_to_tie_ = now_heads_;
105       last_event_ = event_;
106     }
107   event_ = 0;
108   now_heads_.clear ();
109 }
110
111 #include "translator.icc"
112
113 ADD_TRANSLATOR (Tie_performer,
114                 /* descr */ "Generate ties between noteheads of equal pitch.",
115                 /* creats*/ "",
116                 /* accepts */ "tie-event",
117                 /* reads */ "tieMelismaBusy",
118                 /* write */ "");