]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-function.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / music-function.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--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 "music-function.hh"
21
22 #include "music.hh"
23 #include "ly-smobs.icc"
24
25 class Musicfunction
26 {
27   DECLARE_SIMPLE_SMOBS (Musicfunction);
28   SCM signature_;
29   SCM function_;
30 public:
31   Musicfunction (SCM signature, SCM function):
32     signature_ (signature), function_ (function) { }
33   SCM get_function () { return function_; }
34   SCM get_signature () { return signature_; }
35 };
36
37 IMPLEMENT_SIMPLE_SMOBS (Musicfunction);
38 IMPLEMENT_DEFAULT_EQUAL_P (Musicfunction);
39
40 /* Print a textual represenation of the smob to a given port.  */
41 int
42 Musicfunction::print_smob (SCM b, SCM port, scm_print_state *)
43 {
44   scm_puts ("#<Music function ", port);
45   scm_write (Musicfunction::unsmob (b)->get_function (), port);
46   scm_puts (">", port);
47
48   /* Non-zero means success.  */
49   return 1;
50 }
51
52 bool
53 is_music_function (SCM music_function)
54 {
55   return Musicfunction::unsmob (music_function);
56 }
57
58 SCM
59 get_music_function_transform (SCM music_function)
60 {
61   if (!is_music_function (music_function))
62     return SCM_UNDEFINED;
63
64   return Musicfunction::unsmob (music_function)->get_function ();
65 }
66
67 SCM
68 make_music_function (SCM signature, SCM func)
69 {
70   return Musicfunction (signature, func).smobbed_copy ();
71 }
72
73 SCM
74 get_music_function_signature (SCM music_function)
75 {
76   if (!is_music_function (music_function))
77     return SCM_UNDEFINED;
78
79   return Musicfunction::unsmob (music_function)->get_signature ();
80 }
81
82 SCM
83 Musicfunction::mark_smob (SCM s)
84 {
85   Musicfunction *p = Musicfunction::unsmob (s);
86   scm_gc_mark (p->signature_);
87   ASSERT_LIVE_IS_ALLOWED (s);
88   return p->function_;
89 }