]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-closure.cc
(PATCH_LEVEL): release 2.7.15
[lilypond.git] / lily / grob-closure.cc
1 #include "grob.hh"
2 #include "simple-closure.hh"
3
4 SCM
5 axis_offset_symbol (Axis a)
6 {
7   return a == X_AXIS
8     ? ly_symbol2scm ("X-offset")
9     : ly_symbol2scm ("Y-offset");
10 }
11
12 SCM
13 axis_parent_positioning (Axis a)
14 {
15   return (a == X_AXIS)
16     ? Grob::x_parent_positioning_proc
17     : Grob::y_parent_positioning_proc;
18 }
19
20
21
22 /*
23   Replace
24
25   (orig-proc GROB)
26
27   by
28
29   (+ (PROC GROB) (orig-proc GROB))
30   
31 */
32 void
33 add_offset_callback (Grob *g, SCM proc, Axis a)
34 {
35   SCM data = g->get_property_data (axis_offset_symbol (a));
36   if (ly_is_procedure (data))
37     data = ly_make_simple_closure (scm_list_1  (data));
38   else if (is_simple_closure (data))
39     data = simple_closure_expression (data);
40   else if (!scm_is_number (data))
41     g->internal_set_property (axis_offset_symbol (a),
42                               proc);
43   else
44     {
45       SCM plus = ly_lily_module_constant ("+");
46       SCM expr = scm_list_3 (plus,
47                              ly_make_simple_closure (scm_list_1 (proc)),
48                              data);
49       g->internal_set_property (axis_offset_symbol (a),
50                                 ly_make_simple_closure (expr));
51     }
52 }
53
54
55 /*
56   replace
57
58   (orig-proc GROB)
59
60   by
61
62   (PROC GROB (orig-proc GROB)) 
63
64 */
65 void
66 chain_offset_callback (Grob *g, SCM proc, Axis a)
67 {
68   SCM data = g->get_property_data (axis_offset_symbol (a));
69
70   if (ly_is_procedure (data))
71     data = ly_make_simple_closure (scm_list_1  (data));
72   else if (is_simple_closure (data))
73     data = simple_closure_expression (data);
74   else if (!scm_is_number (data))
75     data = scm_from_int (0);
76   
77   SCM expr = scm_list_2 (proc, data);
78   g->internal_set_property (axis_offset_symbol (a),
79                             
80                             // twice: one as a wrapper for grob property routines,
81                             // once for the actual delayed binding. 
82                             ly_make_simple_closure (ly_make_simple_closure (expr)));
83 }