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