]> git.donarmstrong.com Git - lilypond.git/blob - lily/voice-devnull-engraver.cc
* lily/spacing-engraver.cc (finalize): robustifications.
[lilypond.git] / lily / voice-devnull-engraver.cc
1 /*
2   voice-devnull-engraver.cc -- implement Voice_devnull_engraver
3
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10 #include "item.hh"
11 #include "event.hh"
12 #include "translator-group.hh"
13
14 class Voice_devnull_engraver : public Engraver
15 {
16 public:
17   TRANSLATOR_DECLARATIONS(Voice_devnull_engraver);
18   
19 protected:
20   virtual bool try_music (Music *m);
21   virtual void acknowledge_grob (Grob_info);
22 };
23
24
25 /*
26
27 ARGH .
28
29
30 This really sucks.
31
32  */
33 static char const *eat_spanners[] = {
34   "beam",
35   "crescendo",
36   "decrescendo",
37   "rest",
38   "slur",
39   0
40 };
41
42 bool
43 Voice_devnull_engraver::try_music (Music *m)
44 {
45   SCM s = get_property ("devNullVoice");
46
47   if (gh_equal_p (s, ly_symbol2scm ("always"))
48       || (s == SCM_EOL
49           && daddy_trans_->id_string_.left_string (3) == "two"
50           && (to_boolean (get_property ("unison"))
51               || to_boolean (get_property ("unisilence")))))
52     {
53       if (m->is_mus_type ("span-event"))
54         {
55           SCM t = m->get_mus_property ("span-type");
56         
57           for (char const **p = eat_spanners; *p; p++)
58             {
59               if (t == scm_makfrom0str (*p))
60                 return true;
61             }
62         }
63       /* Ugh.  Should eat other events, script etc. too. */  
64       else if (m->is_mus_type ("tie-event"))
65         return true;
66     }
67   return false;
68 }
69     
70 static char const *junk_interfaces[] = {
71   "beam-interface",
72   "dynamic-interface",
73   "hairpin-interface",
74   "multi-measure-rest-interface",
75   "script-interface",
76   "slur-interface",
77   "text-interface",
78   "text-item-interface",
79   "text-script-interface",
80   "text-spanner-interface",
81   "tie-interface",
82   0
83 };
84
85 void
86 Voice_devnull_engraver::acknowledge_grob (Grob_info i)
87 {
88   SCM s = get_property ("devNullVoice");
89
90   if (s == ly_symbol2scm ("always")
91       || (s == SCM_EOL
92           && to_boolean (get_property ("soloADue"))
93           && ((daddy_trans_->id_string_.left_string (3) == "two"
94                && (to_boolean (get_property ("unison"))
95                    || to_boolean (get_property ("unisilence"))))
96                 
97               /* Maybe this should be optional? */
98               || to_boolean (get_property ("othersolo")))))
99     
100     for (char const **p = junk_interfaces; *p; p++)
101       if (i.grob_->internal_has_interface (ly_symbol2scm (*p)))
102         {
103           i.grob_->suicide ();
104           return;
105         }
106 }
107  
108 Voice_devnull_engraver::Voice_devnull_engraver(){}
109   
110 ENTER_DESCRIPTION(Voice_devnull_engraver,
111 /* descr */       "Kill off certain items and spanners if we're Voice `two' and unison or unisilence is set.",
112 /* creats*/       "",
113 /* accepts */     "general-music", /*UGH.*/
114 /* acks  */      "grob-interface",
115 /* reads */       "",
116 /* write */       "");