]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-head.cc
3deb46d1d73808b3d226b78b37dc21327c984b7b
[lilypond.git] / lily / music-head.cc
1 /* 
2   music-head.cc --  implement Music_head
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   
8 */
9 #include "music-head.hh"
10 #include "string.hh"
11 #include "music.hh"
12
13 static scm_t_bits music_head_tag;
14
15 /* Print a textual represenation of the smob to a given port.  */
16 static int
17 print_music_head (SCM b, SCM port, scm_print_state *)
18 {
19   SCM value = SCM_CELL_OBJECT_1 (b);
20
21   scm_puts ("#<packaged object ", port);
22   scm_write (value, port);
23   scm_puts (">", port);
24
25   /* Non-zero means success.  */
26   return 1;
27 }
28
29
30 LY_DEFINE (ly_make_music_head, "ly:make-music-head", 2, 0, 0,
31            (SCM signature, SCM func),
32           "Make a function to process music, to be used for the "
33            "parser. @code{func} is the function, and @code{signature} describes "
34            "Its arguments. @code{signature} is a list containing either "
35            "@code{ly:music?} predicates or other type predicates.")
36 {
37   String str = "";
38   for (SCM s = signature; ly_c_pair_p (s); s = ly_cdr (s))
39     {
40       if (str != "")
41         str += "-";
42       
43       if (ly_car (s) == Music_type_p_proc)
44         str += "music";
45       else if (ly_c_procedure_p (ly_car (s)))
46         str += "scm";
47     }
48   
49   scm_set_object_property_x (func, ly_symbol2scm ("music-head-signature"),
50                              signature);
51   
52   scm_set_object_property_x (func, ly_symbol2scm ("music-head-signature-keyword"),
53                              ly_symbol2scm (str.to_str0 ()));
54     
55   SCM_RETURN_NEWSMOB (music_head_tag, func);
56 }
57
58 bool
59 is_music_head (SCM music_head)
60 {
61   return (SCM_NIMP (music_head) && SCM_CELL_TYPE (music_head) == music_head_tag);
62 }
63
64
65 SCM
66 get_music_head_transform (SCM music_head)
67 {
68   if (!is_music_head (music_head))
69     return SCM_UNDEFINED;
70   
71   return SCM_CELL_OBJECT_1 (music_head);
72 }
73
74 static void
75 init_music_head (void)
76 {
77   music_head_tag = scm_make_smob_type ("music-head", 0);
78   scm_set_smob_mark (music_head_tag, scm_markcdr);
79   scm_set_smob_print (music_head_tag, print_music_head);
80 }
81 ADD_SCM_INIT_FUNC (music_head_tag, init_music_head);