]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam-performer.cc
* lily/*-performer.cc: Converted try_music to listen_*
[lilypond.git] / lily / beam-performer.cc
1 /*
2   beam-performer.cc -- implement Beam_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "performer.hh"
10 #include "audio-item.hh"
11 #include "audio-column.hh"
12 #include "global-context.hh"
13 #include "stream-event.hh"
14 #include "warn.hh"
15 #include "music.hh"
16
17 #include "translator.icc"
18
19 class Beam_performer : public Performer
20 {
21 public:
22   TRANSLATOR_DECLARATIONS (Beam_performer);
23
24 protected:
25   void start_translation_timestep ();
26   void process_music ();
27   void set_melisma (bool);
28   DECLARE_TRANSLATOR_LISTENER (beam);
29 private:
30   Stream_event *start_ev_;
31   Stream_event *now_stop_ev_;
32   bool beam_;
33 };
34
35 Beam_performer::Beam_performer ()
36 {
37   beam_ = false;
38   start_ev_ = 0;
39   now_stop_ev_ = 0;
40 }
41
42 void
43 Beam_performer::process_music ()
44 {
45   if (now_stop_ev_)
46     {
47       beam_ = false;
48       set_melisma (false);
49     }
50
51   if (start_ev_)
52     {
53       beam_ = true;
54       set_melisma (true);
55     }
56 }
57
58 void
59 Beam_performer::set_melisma (bool ml)
60 {
61   SCM b = get_property ("autoBeaming");
62   if (!to_boolean (b))
63     context ()->set_property ("beamMelismaBusy", ml ? SCM_BOOL_T : SCM_BOOL_F);
64 }
65
66 void
67 Beam_performer::start_translation_timestep ()
68 {
69   start_ev_ = 0;
70   now_stop_ev_ = 0;
71 }
72
73 IMPLEMENT_TRANSLATOR_LISTENER (Beam_performer, beam);
74 void
75 Beam_performer::listen_beam (Stream_event *ev)
76 {
77   Direction d = to_dir (ev->get_property ("span-direction"));
78
79   if (d == START)
80     start_ev_ = ev;
81   else if (d == STOP)
82     now_stop_ev_ = ev;
83 }
84
85 ADD_TRANSLATOR (Beam_performer, "", "",
86                 "beam-event", "", "");
87