]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-head.cc
* input/regression/music-head.ly (texidoc): new file.
[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
12 /*
13   C&P from example/box.c
14  */
15
16 static scm_t_bits music_head_tag;
17
18 /* Print a textual represenation of the smob to a given port.  */
19 static int
20 print_music_head (SCM b, SCM port, scm_print_state *)
21 {
22   SCM value = SCM_CELL_OBJECT_1 (b);
23
24   scm_puts ("#<packaged object ", port);
25   scm_write (value, port);
26   scm_puts (">", port);
27
28   /* Non-zero means success.  */
29   return 1;
30 }
31
32
33 /* This defines the primitve `make-music_head', which returns a new smob of
34    type `music_head', initialized to `#f'.  */
35 LY_DEFINE (ly_make_music_head, "ly:make-music-head", 2, 0, 0,
36            (SCM func, SCM signature),
37           "Make a function to process music, to be used for the "
38            "parser. @code{func} is the function, and @code{signature} describes "
39            "Its arguments. @code{signature} is a list containing either "
40            "@code{ly:music?} predicates or other type predicates.")
41 {
42   /* This macro creates the new objects, stores the value `#f' into it
43      and returns it to the caller.  */
44   String str = "";
45
46   int k = 0;
47   for (SCM s = signature; ly_c_pair_p (s); s = ly_cdr (s))
48     {
49       if (str != "")
50         str += "-";
51       
52       if (ly_car (s) == Music_type_p_proc)
53         str += "music";
54       else if (ly_procedure_p (ly_car (s)))
55         str += "scm";
56
57       k++;
58     }
59   
60   scm_set_object_property_x (func, ly_symbol2scm ("music-head-signature"),
61                              signature);
62   
63   scm_set_object_property_x (func, ly_symbol2scm ("music-head-signature-keyword"),
64                              ly_symbol2scm (str.to_str0 ()));
65     
66   SCM_RETURN_NEWSMOB (music_head_tag, func);
67 }
68
69 bool
70 is_music_head (SCM music_head)
71 {
72   return (SCM_NIMP (music_head) && SCM_CELL_TYPE (music_head) == music_head_tag);
73 }
74
75
76 /* This is the primitive `music_head-ref' which returns the object stored in
77    the music_head.  */
78 SCM
79 get_music_head_transform (SCM music_head)
80 {
81   if (!is_music_head (music_head))
82     return SCM_UNDEFINED;
83   
84   return SCM_CELL_OBJECT_1 (music_head);
85 }
86
87 static void
88 init_music_head (void)
89 {
90   music_head_tag = scm_make_smob_type ("music-head", 0);
91   scm_set_smob_mark (music_head_tag, scm_markcdr);
92   scm_set_smob_print (music_head_tag, print_music_head);
93 }
94 ADD_SCM_INIT_FUNC (music_head_tag, init_music_head);