X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmusic-scheme.cc;h=c0e4eb3167fdfcaa55b82b89491a8ba1b85a3eb6;hb=941dff9d2a67080e0dd8474f1e70f0c72ace6424;hp=27e5db98804752020a1460fb1cff339eac7f1398;hpb=556b8f79cbe6b89388a37c3e72037f54229d462d;p=lilypond.git diff --git a/lily/music-scheme.cc b/lily/music-scheme.cc index 27e5db9880..c0e4eb3167 100644 --- a/lily/music-scheme.cc +++ b/lily/music-scheme.cc @@ -1,42 +1,54 @@ /* - music-scheme.cc -- implement Music bindings + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2005--2011 Han-Wen Nienhuys - (c) 2005--2006 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ -#include "duration.hh" -#include "warn.hh" #include "music.hh" -#include "pitch.hh" +#include "duration.hh" +#include "warn.hh" LY_DEFINE (ly_music_length, "ly:music-length", 1, 0, 0, (SCM mus), - "Get the length of music expression @var{mus}, and return as a @code{Moment} object.") + "Get the length of music expression @var{mus} and return" + " it as a @code{Moment} object.") { + LY_ASSERT_TYPE (unsmob_music, mus, 1); Music *sc = unsmob_music (mus); - SCM_ASSERT_TYPE (sc, mus, SCM_ARG1, __FUNCTION__, "music"); return sc->get_length ().smobbed_copy (); } -LY_DEFINE (ly_music_property, - "ly:music-property", 2, 1, 0, (SCM mus, SCM sym, SCM dfault), - "Get the property @var{sym} of music expression @var{mus}.\n" - "If @var{sym} is undefined, return @code{'()}.\n") +LY_DEFINE (ly_music_property, "ly:music-property", + 2, 1, 0, (SCM mus, SCM sym, SCM val), + "Return the value for property @var{sym} of music expression" + " @var{mus}. If no value is found, return @var{val} or" + " @code{'()} if @var{val} is not specified.") { - Music *sc = unsmob_music (mus); - SCM_ASSERT_TYPE (sc, mus, SCM_ARG1, __FUNCTION__, "music"); - return ly_prob_property (mus,sym,dfault); + LY_ASSERT_TYPE (unsmob_music, mus, 1); + return ly_prob_property (mus, sym, val); } -LY_DEFINE (ly_music_set_property, "ly:music-set-property!", +LY_DEFINE (ly_music_set_property_x, "ly:music-set-property!", 3, 0, 0, (SCM mus, SCM sym, SCM val), - "Set property @var{sym} in music expression @var{mus} to @var{val}.") + "Set property @var{sym} in music expression @var{mus} to" + " @var{val}.") { - Music *sc = unsmob_music (mus); - SCM_ASSERT_TYPE (sc, mus, SCM_ARG1, __FUNCTION__, "music"); + LY_ASSERT_TYPE (unsmob_music, mus, 1); + return ly_prob_set_property_x (mus, sym, val); } @@ -44,12 +56,12 @@ LY_DEFINE (ly_music_set_property, "ly:music-set-property!", /* todo: property args */ LY_DEFINE (ly_make_music, "ly:make-music", 1, 0, 0, (SCM props), - "Make a C++ Music object, initialize with\n" - "@var{props}. \n\n" - "" - "This function is for internal use, and is only called by " - "@code{make-music}, which is the preferred interface " - "for creating music objects. ") + "Make a C++ @code{Music} object and initialize it with" + " @var{props}.\n" + "\n" + "This function is for internal use and is only called by" + " @code{make-music}, which is the preferred interface" + " for creating music objects.") { Music *ms = new Music (props); return ms->unprotect (); @@ -57,7 +69,7 @@ LY_DEFINE (ly_make_music, "ly:make-music", LY_DEFINE (ly_music_p, "ly:music?", 1, 0, 0, (SCM obj), - "Type predicate") + "Is @var{obj} a music object?") { return scm_from_bool (unsmob_music (obj)); } @@ -65,20 +77,18 @@ LY_DEFINE (ly_music_p, "ly:music?", /* todo: property args */ LY_DEFINE (ly_music_mutable_properties, "ly:music-mutable-properties", 1, 0, 0, (SCM mus), - "Return an alist containing the mutable properties of @var{mus}.\n" - "The immutable properties are not available, since " - "they are constant and initialized by the " - "@code{make-music} function.\n") + "Return an alist containing the mutable properties of @var{mus}." + " The immutable properties are not available, since they are" + " constant and initialized by the @code{make-music} function.") { + LY_ASSERT_TYPE (unsmob_music, mus, 1); Music *m = unsmob_music (mus); - SCM_ASSERT_TYPE (m, mus, SCM_ARG1, __FUNCTION__, "music"); return m->get_property_alist (true); } LY_DEFINE (ly_music_list_p, "ly:music-list?", 1, 0, 0, (SCM lst), - "Type predicate: return true if @var{lst} is a list " - "of music objects.") + "Is @var{lst} a list of music objects?") { if (scm_list_p (lst) == SCM_BOOL_T) while (scm_is_pair (lst)) @@ -93,7 +103,7 @@ LY_DEFINE (ly_music_list_p, "ly:music-list?", LY_DEFINE (ly_music_deep_copy, "ly:music-deep-copy", 1, 0, 0, (SCM m), - "Copy @var{m} and all sub expressions of @var{m}") + "Copy @var{m} and all sub expressions of@tie{}@var{m}.") { SCM copy = m; if (unsmob_music (m)) @@ -109,13 +119,14 @@ LY_DEFINE (ly_music_deep_copy, "ly:music-deep-copy", LY_DEFINE (ly_music_transpose, "ly:music-transpose", 2, 0, 0, (SCM m, SCM p), - "Transpose @var{m} such that central C is mapped to @var{p}. " - "Return @var{m}.") + "Transpose @var{m} such that central@tie{}C is mapped" + " to@tie{}@var{p}. Return@tie{}@var{m}.") { + LY_ASSERT_TYPE (unsmob_music, m, 1); + LY_ASSERT_SMOB (Pitch, p, 2); + Music *sc = unsmob_music (m); Pitch *sp = unsmob_pitch (p); - SCM_ASSERT_TYPE (sc, m, SCM_ARG1, __FUNCTION__, "music"); - SCM_ASSERT_TYPE (sp, p, SCM_ARG2, __FUNCTION__, "pitch"); sc->transpose (*sp); // SCM_UNDEFINED ? @@ -127,23 +138,23 @@ LY_DEFINE (ly_music_transpose, "ly:music-transpose", */ LY_DEFINE (ly_music_compress, "ly:music-compress", 2, 0, 0, (SCM m, SCM factor), - "Compress music object @var{m} by moment @var{factor}.") + "Compress music object@tie{}@var{m} by moment @var{factor}.") { - Music *sc = unsmob_music (m); - - SCM_ASSERT_TYPE (sc, m, SCM_ARG1, __FUNCTION__, "music"); - SCM_ASSERT_TYPE (unsmob_moment (factor), factor, SCM_ARG2, __FUNCTION__, "moment"); + LY_ASSERT_TYPE (unsmob_music, m, 1); + LY_ASSERT_TYPE (unsmob_moment, factor, 2); + Music *sc = unsmob_music (m); sc->compress (*unsmob_moment (factor)); return sc->self_scm (); } LY_DEFINE (ly_music_duration_length, "ly:music-duration-length", 1, 0, 0, (SCM mus), - "Extract the duration field from @var{mus}, and return the length.") + "Extract the duration field from @var{mus} and return the" + " length.") { + LY_ASSERT_TYPE (unsmob_music, mus, 1); Music *m = unsmob_music (mus); - SCM_ASSERT_TYPE (m, mus, SCM_ARG1, __FUNCTION__, "Music"); Duration *d = unsmob_duration (m->get_property ("duration")); Moment len; @@ -157,12 +168,14 @@ LY_DEFINE (ly_music_duration_length, "ly:music-duration-length", 1, 0, 0, LY_DEFINE (ly_music_duration_compress, "ly:music-duration-compress", 2, 0, 0, (SCM mus, SCM fact), - "Compress @var{mus} by factor @var{fact}, which is a @code{Moment}.") + "Compress @var{mus} by factor @var{fact}, which is a" + " @code{Moment}.") { + LY_ASSERT_TYPE (unsmob_music, mus, 1); + LY_ASSERT_SMOB (Moment, fact, 2); + Music *m = unsmob_music (mus); Moment *f = unsmob_moment (fact); - SCM_ASSERT_TYPE (m, mus, SCM_ARG1, __FUNCTION__, "Music"); - SCM_ASSERT_TYPE (f, fact, SCM_ARG2, __FUNCTION__, "Moment"); Duration *d = unsmob_duration (m->get_property ("duration")); if (d) @@ -179,7 +192,8 @@ LY_DEFINE (ly_music_duration_compress, "ly:music-duration-compress", 2, 0, 0, */ LY_DEFINE (ly_transpose_key_alist, "ly:transpose-key-alist", 2, 0, 0, (SCM l, SCM pit), - "Make a new key alist of @var{l} transposed by pitch @var{pit}") + "Make a new key alist of@tie{}@var{l} transposed by" + " pitch @var{pit}.") { SCM newlist = SCM_EOL; Pitch *p = unsmob_pitch (pit); @@ -192,23 +206,23 @@ LY_DEFINE (ly_transpose_key_alist, "ly:transpose-key-alist", { Pitch orig (scm_to_int (scm_car (key)), scm_to_int (scm_cdr (key)), - scm_to_int (alter)); + ly_scm2rational (alter)); orig = orig.transposed (*p); SCM key = scm_cons (scm_from_int (orig.get_octave ()), scm_from_int (orig.get_notename ())); - newlist = scm_cons (scm_cons (key, scm_from_int (orig.get_alteration ())), + newlist = scm_cons (scm_cons (key, ly_rational2scm (orig.get_alteration ())), newlist); } else if (scm_is_number (key)) { - Pitch orig (0, scm_to_int (key), scm_to_int (alter)); + Pitch orig (0, scm_to_int (key), ly_scm2rational (alter)); orig = orig.transposed (*p); key = scm_from_int (orig.get_notename ()); - alter = scm_from_int (orig.get_alteration ()); + alter = ly_rational2scm (orig.get_alteration ()); newlist = scm_cons (scm_cons (key, alter), newlist); } }