]> git.donarmstrong.com Git - lilypond.git/blob - lily/prob-scheme.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / prob-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 "prob.hh"
21
22 LY_DEFINE (ly_prob_set_property_x, "ly:prob-set-property!",
23            2, 1, 0, (SCM obj, SCM sym, SCM value),
24            "Set property @var{sym} of @var{obj} to @var{value}.")
25 {
26   LY_ASSERT_SMOB (Prob, obj, 1);
27   Prob *ps = unsmob_prob (obj);
28   LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
29
30   ps->set_property (sym, value);
31   return SCM_UNSPECIFIED;
32 }
33
34 /*
35   Hmm, this is not orthogonal.
36 */
37 LY_DEFINE (ly_prob_property_p, "ly:prob-property?",
38            2, 1, 0, (SCM obj, SCM sym),
39            "Is boolean prop @var{sym} of @var{sym} set?")
40 {
41   return scm_equal_p (SCM_BOOL_T, ly_prob_property (obj, sym, SCM_BOOL_F));
42 }
43
44 LY_DEFINE (ly_prob_property, "ly:prob-property",
45            2, 1, 0, (SCM prob, SCM sym, SCM val),
46            "Return the value for property @var{sym} of Prob object"
47            " @var{prob}.  If no value is found, return @var{val} or"
48            " @code{'()} if @var{val} is not specified.")
49 {
50   LY_ASSERT_SMOB (Prob, prob, 1);
51   Prob *ps = unsmob_prob (prob);
52   LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
53
54   if (val == SCM_UNDEFINED)
55     val = SCM_EOL;
56
57   SCM retval = ps->internal_get_property (sym);
58   if (retval == SCM_EOL)
59     return val;
60   else
61     return retval;
62 }
63
64 LY_DEFINE (ly_prob_type_p, "ly:prob-type?",
65            2, 0, 0,
66            (SCM obj, SCM type),
67            "Is @var{obj} the specified prob-type?")
68 {
69   Prob *prob = unsmob_prob (obj);
70   return scm_from_bool (prob && prob->type () == type);
71 }
72
73 LY_DEFINE (ly_make_prob, "ly:make-prob",
74            2, 0, 1,
75            (SCM type, SCM init, SCM rest),
76            "Create a @code{Prob} object.")
77 {
78   Prob *pr = new Prob (type, init);
79
80   for (SCM s = rest;
81        scm_is_pair (s) && scm_is_pair (scm_cdr (s)); s = scm_cddr (s))
82     {
83       SCM sym = scm_car (s);
84       SCM val = scm_cadr (s);
85
86       pr->set_property (sym, val);
87     }
88
89   return pr->unprotect ();
90 }
91
92 LY_DEFINE (ly_prob_mutable_properties, "ly:prob-mutable-properties",
93            1, 0, 0,
94            (SCM prob),
95            "Retrieve an alist of mutable properties.")
96 {
97   LY_ASSERT_SMOB (Prob, prob, 1);
98   Prob *ps = unsmob_prob (prob);
99   return ps->get_property_alist (true);
100 }
101
102 LY_DEFINE (ly_prob_immutable_properties, "ly:prob-immutable-properties",
103            1, 0, 0,
104            (SCM prob),
105            "Retrieve an alist of immutable properties.")
106 {
107   LY_ASSERT_SMOB (Prob, prob, 1);
108   Prob *ps = unsmob_prob (prob);
109   return ps->get_property_alist (false);
110 }
111