summaryrefslogtreecommitdiff
path: root/lily/tweak-engraver.cc
blob: 5f97b1e4cbdb11a84bfb469f864e31a01f2b8d0c (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
  This file is part of LilyPond, the GNU music typesetter.

  Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>


  LilyPond is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  LilyPond is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "engraver.hh"

#include "grob.hh"
#include "stream-event.hh"
#include "translator.icc"

class Tweak_engraver : public Engraver
{
  TRANSLATOR_DECLARATIONS (Tweak_engraver);

protected:
  void acknowledge_grob (Grob_info);
};

Tweak_engraver::Tweak_engraver ()
{
}

void
Tweak_engraver::acknowledge_grob (Grob_info info)
{
  Stream_event *ev = info.event_cause ();
  bool direct = ev;
  SCM grobname = SCM_UNDEFINED;
  if (!direct)
    ev = info.ultimate_event_cause ();
  if (ev)
    {
      // Each tweak conses an address and a value.
      // The address has one of the following forms:
      // symbol -> direct tweak
      // (grob . symbol) -> targeted tweak
      // (#t . symbol-path) -> direct nested tweak
      // (grob . symbol-path) -> targeted nested tweak
      for (SCM s = ev->get_property ("tweaks");
           scm_is_pair (s); s = scm_cdr (s))
        {
          if (scm_is_pair (scm_caar (s)))
            {
              if (scm_is_symbol (scm_caaar (s)))
                {
                  if (SCM_UNBNDP (grobname))
                    grobname = scm_from_utf8_symbol
                      (info.grob ()->name ().c_str ());
                  if (scm_is_eq (scm_caaar (s), grobname))
                    {
                      if (scm_is_symbol (scm_cdaar (s)))
                        info.grob ()->set_property (scm_cdaar (s), scm_cdar (s));
                      else
                        set_nested_property (info.grob (), scm_cdaar (s),
                                             scm_cdar (s));
                    }
                }
              else if (direct)
                set_nested_property (info.grob (), scm_cdaar (s),
                                     scm_cdar (s));
            }
          else if (direct)
            info.grob ()->set_property (scm_caar (s), scm_cdar (s));
        }
    }
}

void
Tweak_engraver::boot ()
{
  ADD_ACKNOWLEDGER (Tweak_engraver, grob);
}

ADD_TRANSLATOR (Tweak_engraver,
                /* doc */
                "Read the @code{tweaks} property from the originating event,"
                " and set properties.",

                /* create */
                "",

                /* read */
                "",

                /* write */
                ""
               );