]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam-performer.cc
d723d7a81c864369d2b4272d90620294f74fc31a
[lilypond.git] / lily / beam-performer.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2012 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "performer.hh"
21 #include "audio-item.hh"
22 #include "audio-column.hh"
23 #include "global-context.hh"
24 #include "stream-event.hh"
25 #include "warn.hh"
26
27 #include "translator.icc"
28
29 class Beam_performer : public Performer
30 {
31 public:
32   TRANSLATOR_DECLARATIONS (Beam_performer);
33
34 protected:
35   void start_translation_timestep ();
36   void process_music ();
37   void set_melisma (bool);
38   DECLARE_TRANSLATOR_LISTENER (beam);
39 private:
40   Stream_event *start_ev_;
41   Stream_event *now_stop_ev_;
42   bool beam_;
43 };
44
45 Beam_performer::Beam_performer ()
46 {
47   beam_ = false;
48   start_ev_ = 0;
49   now_stop_ev_ = 0;
50 }
51
52 void
53 Beam_performer::process_music ()
54 {
55   if (now_stop_ev_)
56     {
57       beam_ = false;
58       set_melisma (false);
59     }
60
61   if (start_ev_)
62     {
63       beam_ = true;
64       set_melisma (true);
65     }
66 }
67
68 void
69 Beam_performer::set_melisma (bool ml)
70 {
71   SCM b = get_property ("autoBeaming");
72   if (!to_boolean (b))
73     context ()->set_property ("beamMelismaBusy", ml ? SCM_BOOL_T : SCM_BOOL_F);
74 }
75
76 void
77 Beam_performer::start_translation_timestep ()
78 {
79   start_ev_ = 0;
80   now_stop_ev_ = 0;
81 }
82
83 IMPLEMENT_TRANSLATOR_LISTENER (Beam_performer, beam);
84 void
85 Beam_performer::listen_beam (Stream_event *ev)
86 {
87   Direction d = to_dir (ev->get_property ("span-direction"));
88
89   if (d == START)
90     start_ev_ = ev;
91   else if (d == STOP)
92     now_stop_ev_ = ev;
93 }
94
95 ADD_TRANSLATOR (Beam_performer,
96                 /* doc */
97                 "",
98
99                 /* create */
100                 "",
101
102                 /* read */
103                 "",
104
105                 /* write */
106                 ""
107                );
108