]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-switch-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / instrument-switch-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2014 Han-Wen Nienhuys <hanwen@lilypond.org>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "engraver.hh"
22 #include "item.hh"
23 #include "text-interface.hh"
24
25 #include "translator.icc"
26
27 class Instrument_switch_engraver : public Engraver
28 {
29
30   TRANSLATOR_DECLARATIONS (Instrument_switch_engraver);
31 protected:
32   Grob *text_;
33   SCM cue_name_;
34
35   void stop_translation_time_step ();
36   void process_music ();
37
38   virtual void derived_mark () const;
39 };
40
41 void
42 Instrument_switch_engraver::derived_mark () const
43 {
44   scm_gc_mark (cue_name_);
45 }
46
47 Instrument_switch_engraver::Instrument_switch_engraver ()
48 {
49   cue_name_ = SCM_EOL;
50   text_ = 0;
51 }
52
53 /*
54   TODO: should use an event.
55  */
56 void
57 Instrument_switch_engraver::process_music ()
58 {
59   SCM cue_text = get_property ("instrumentCueName");
60
61   if (!scm_is_eq (cue_name_, cue_text))
62     {
63       if (Text_interface::is_markup (cue_text))
64         {
65           text_ = make_item ("InstrumentSwitch", SCM_EOL);
66           text_->set_property ("text", cue_text);
67         }
68       cue_name_ = cue_text;
69     }
70 }
71
72 void
73 Instrument_switch_engraver::stop_translation_time_step ()
74 {
75   text_ = 0;
76 }
77
78 ADD_TRANSLATOR (Instrument_switch_engraver,
79                 /* doc */
80                 "Create a cue text for taking instrument.",
81
82                 /* create */
83                 "InstrumentSwitch ",
84
85                 /* read */
86                 "instrumentCueName ",
87
88                 /* write */
89                 ""
90                );