]> git.donarmstrong.com Git - lilypond.git/commitdiff
* input/regression/music-head.ly (texidoc): new file.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 4 May 2004 22:45:15 +0000 (22:45 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 4 May 2004 22:45:15 +0000 (22:45 +0000)
* lily/include/music-head.hh (is_music_head): new file.

* lily/music-head.cc (get_music_head_transform): new file.

ChangeLog
input/regression/music-head.ly [new file with mode: 0644]
lily/include/music-head.hh [new file with mode: 0644]
lily/include/music.hh
lily/include/smobs.hh
lily/music-head.cc [new file with mode: 0644]

index d51100910f817f0283415656aad3b7b311f0f014..6fdd422bb1c8fb1a061e9a6f5581d8f3b343b238 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2004-05-05  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * input/regression/music-head.ly (texidoc): new file.
+
        * lily/parser.yy (Generic_prefix_music): allow generic
        music-transformation functions. 
 
diff --git a/input/regression/music-head.ly b/input/regression/music-head.ly
new file mode 100644 (file)
index 0000000..e300c3b
--- /dev/null
@@ -0,0 +1,25 @@
+\header
+{
+texidoc = "Music heads are generic music transformation functions,
+which can be used to extend music syntax seamlessly."
+
+}
+\version "2.3.1"
+
+#(define myBar
+  (ly:make-music-head
+   (lambda (where type)
+    (context-spec-music
+     (context-spec-music (make-property-set whichBar type) 'Timing)
+     'Score))
+   (list string?)
+    
+    ))
+
+\score{
+    \notes {
+       d4 \myBar #"|:" d4
+       
+    }
+}
+
diff --git a/lily/include/music-head.hh b/lily/include/music-head.hh
new file mode 100644 (file)
index 0000000..b010c22
--- /dev/null
@@ -0,0 +1,20 @@
+/* 
+  music-head.hh -- declare Music_head
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  
+*/
+
+#ifndef MUSIC_HEAD_HH
+#define MUSIC_HEAD_HH
+
+#include "lily-guile.hh"
+
+SCM ly_make_music_head (SCM, SCM);
+SCM get_music_head_transform (SCM);
+bool is_music_head (SCM);
+
+#endif /* MUSIC_HEAD_HH */
+
index 78d1be7bde982e4274190a3a77fc440e8397c372..902c151b89dcf64647e00e38d389edd4e84d91e3 100644 (file)
@@ -68,7 +68,7 @@ protected:
   friend SCM ly_extended_make_music(SCM,SCM);
 };
 
-
+DECLARE_TYPE_P(Music);
 DECLARE_UNSMOB(Music,music);
 
 Music* make_music_by_name (SCM sym);
index 0feae768fd29262f33315644af50185fdd95adf1..a31ce06e45ba72caa8601a40cf8e1e8fc9ea79e5 100644 (file)
@@ -134,7 +134,7 @@ unsmob_ ## name (SCM s)                     \
 return  CL::unsmob (s);                                \
 }
 
-
+#define DECLARE_TYPE_P(CL) extern SCM CL_ ## _type_p_proc
 
 #endif /* SMOBS_HH */
 
diff --git a/lily/music-head.cc b/lily/music-head.cc
new file mode 100644 (file)
index 0000000..e847b29
--- /dev/null
@@ -0,0 +1,94 @@
+/* 
+  music-head.cc --  implement Music_head
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  
+*/
+#include "music-head.hh"
+#include "string.hh"
+
+/*
+  C&P from example/box.c
+ */
+
+static scm_t_bits music_head_tag;
+
+/* Print a textual represenation of the smob to a given port.  */
+static int
+print_music_head (SCM b, SCM port, scm_print_state *)
+{
+  SCM value = SCM_CELL_OBJECT_1 (b);
+
+  scm_puts ("#<packaged object ", port);
+  scm_write (value, port);
+  scm_puts (">", port);
+
+  /* Non-zero means success.  */
+  return 1;
+}
+
+
+/* This defines the primitve `make-music_head', which returns a new smob of
+   type `music_head', initialized to `#f'.  */
+LY_DEFINE (ly_make_music_head, "ly:make-music-head", 2, 0, 0,
+          (SCM func, SCM signature),
+         "Make a function to process music, to be used for the "
+          "parser. @code{func} is the function, and @code{signature} describes "
+          "Its arguments. @code{signature} is a list containing either "
+          "@code{ly:music?} predicates or other type predicates.")
+{
+  /* This macro creates the new objects, stores the value `#f' into it
+     and returns it to the caller.  */
+  String str = "";
+
+  int k = 0;
+  for (SCM s = signature; ly_c_pair_p (s); s = ly_cdr (s))
+    {
+      if (str != "")
+       str += "-";
+      
+      if (ly_car (s) == Music_type_p_proc)
+       str += "music";
+      else if (ly_procedure_p (ly_car (s)))
+       str += "scm";
+
+      k++;
+    }
+  
+  scm_set_object_property_x (func, ly_symbol2scm ("music-head-signature"),
+                            signature);
+  
+  scm_set_object_property_x (func, ly_symbol2scm ("music-head-signature-keyword"),
+                            ly_symbol2scm (str.to_str0 ()));
+    
+  SCM_RETURN_NEWSMOB (music_head_tag, func);
+}
+
+bool
+is_music_head (SCM music_head)
+{
+  return (SCM_NIMP (music_head) && SCM_CELL_TYPE (music_head) == music_head_tag);
+}
+
+
+/* This is the primitive `music_head-ref' which returns the object stored in
+   the music_head.  */
+SCM
+get_music_head_transform (SCM music_head)
+{
+  if (!is_music_head (music_head))
+    return SCM_UNDEFINED;
+  
+  return SCM_CELL_OBJECT_1 (music_head);
+}
+
+static void
+init_music_head (void)
+{
+  music_head_tag = scm_make_smob_type ("music-head", 0);
+  scm_set_smob_mark (music_head_tag, scm_markcdr);
+  scm_set_smob_print (music_head_tag, print_music_head);
+}
+ADD_SCM_INIT_FUNC (music_head_tag, init_music_head);