X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpitch-scheme.cc;h=f4231f06859ed305a70a6bdc73d2e0fabb3f6337;hb=623fac8d645e4078af36758af5d437c5eb39e793;hp=12ddddf10a1c9b71e729622fc0be5c64a5feda5d;hpb=92e8f758e29427d28c413d1998c895b9c61932fd;p=lilypond.git diff --git a/lily/pitch-scheme.cc b/lily/pitch-scheme.cc index 12ddddf10a..f4231f0685 100644 --- a/lily/pitch-scheme.cc +++ b/lily/pitch-scheme.cc @@ -1,17 +1,28 @@ /* - pitch-scheme.cc -- implement scheme functions for Pitch + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2005--2012 Han-Wen Nienhuys - (c) 2005--2007 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 "pitch.hh" LY_DEFINE (ly_pitch_transpose, "ly:pitch-transpose", - 2, 0, 0, (SCM p, SCM delta), - "Transpose @var{p} by the amount @var{delta}," - " where @var{delta} is relative to middle@tie{}C.") + 2, 0, 0, (SCM p, SCM delta), + "Transpose @var{p} by the amount @var{delta}," + " where @var{delta} is relative to middle@tie{}C.") { LY_ASSERT_SMOB (Pitch, p, 1); LY_ASSERT_SMOB (Pitch, delta, 2); @@ -21,28 +32,31 @@ LY_DEFINE (ly_pitch_transpose, "ly:pitch-transpose", return t->transposed (*d).smobbed_copy (); } -/* Should add optional args. */ LY_DEFINE (ly_make_pitch, "ly:make-pitch", - 2, 1, 0, (SCM octave, SCM note, SCM alter), - "@var{octave} is specified by an integer, zero for the octave" - " containing middle@tie{}C. @var{note} is a number from 0" - " to@tie{}6, with 0 corresponding to pitch@tie{}C and 6" - " corresponding to pitch@tie{}B. @var{alter} is a rational" - " number of whole tones for alteration.") + 2, 1, 0, (SCM octave, SCM note, SCM alter), + "@var{octave} is specified by an integer, zero for the octave" + " containing middle@tie{}C. @var{note} is a number indexing the" + " global default scale, with 0 corresponding to pitch@tie{}C" + " and 6 usually corresponding to pitch@tie{}B." + " Optional @var{alter} is" + " a rational number of 200-cent whole tones for alteration.") + { LY_ASSERT_TYPE (scm_is_integer, octave, 1); LY_ASSERT_TYPE (scm_is_integer, note, 2); + if (SCM_UNBNDP (alter)) + alter = SCM_INUM0; LY_ASSERT_TYPE (scm_is_rational, alter, 3); - + Pitch p (scm_to_int (octave), scm_to_int (note), - ly_scm2rational (alter)); - + ly_scm2rational (alter)); + return p.smobbed_copy (); } LY_DEFINE (ly_pitch_negate, "ly:pitch-negate", 1, 0, 0, - (SCM p), - "Negate @var{p}.") + (SCM p), + "Negate @var{p}.") { LY_ASSERT_SMOB (Pitch, p, 1); Pitch *pp = unsmob_pitch (p); @@ -50,9 +64,9 @@ LY_DEFINE (ly_pitch_negate, "ly:pitch-negate", 1, 0, 0, } LY_DEFINE (ly_pitch_steps, "ly:pitch-steps", 1, 0, 0, - (SCM p), - "Number of steps counted from middle@tie{}C of the" - " pitch@tie{}@var{p}.") + (SCM p), + "Number of steps counted from middle@tie{}C of the" + " pitch@tie{}@var{p}.") { LY_ASSERT_SMOB (Pitch, p, 1); Pitch *pp = unsmob_pitch (p); @@ -60,8 +74,8 @@ LY_DEFINE (ly_pitch_steps, "ly:pitch-steps", 1, 0, 0, } LY_DEFINE (ly_pitch_octave, "ly:pitch-octave", - 1, 0, 0, (SCM pp), - "Extract the octave from pitch@tie{}@var{pp}.") + 1, 0, 0, (SCM pp), + "Extract the octave from pitch@tie{}@var{pp}.") { LY_ASSERT_SMOB (Pitch, pp, 1); Pitch *p = unsmob_pitch (pp); @@ -70,8 +84,8 @@ LY_DEFINE (ly_pitch_octave, "ly:pitch-octave", } LY_DEFINE (ly_pitch_alteration, "ly:pitch-alteration", - 1, 0, 0, (SCM pp), - "Extract the alteration from pitch@tie{}@var{pp}.") + 1, 0, 0, (SCM pp), + "Extract the alteration from pitch@tie{}@var{pp}.") { LY_ASSERT_SMOB (Pitch, pp, 1); Pitch *p = unsmob_pitch (pp); @@ -80,9 +94,9 @@ LY_DEFINE (ly_pitch_alteration, "ly:pitch-alteration", return ly_rational2scm (q); } -LY_DEFINE (pitch_notename, "ly:pitch-notename", - 1, 0, 0, (SCM pp), - "Extract the note name from pitch @var{pp}.") +LY_DEFINE (ly_pitch_notename, "ly:pitch-notename", + 1, 0, 0, (SCM pp), + "Extract the note name from pitch @var{pp}.") { LY_ASSERT_SMOB (Pitch, pp, 1); Pitch *p = unsmob_pitch (pp); @@ -90,10 +104,20 @@ LY_DEFINE (pitch_notename, "ly:pitch-notename", return scm_from_int (q); } -LY_DEFINE (ly_pitch_quartertones, "ly:pitch-quartertones", +LY_DEFINE (ly_pitch_tones, "ly:pitch-tones", 1, 0, 0, (SCM pp), - "Calculate the number of quarter tones of@tie{}@var{pp} from" - " middle@tie{}C.") + "Calculate the number of tones of@tie{}@var{pp} from" + " middle@tie{}C as a rational number.") +{ + LY_ASSERT_SMOB (Pitch, pp, 1); + return ly_rational2scm (unsmob_pitch (pp)->tone_pitch ()); +} + + +LY_DEFINE (ly_pitch_quartertones, "ly:pitch-quartertones", + 1, 0, 0, (SCM pp), + "Calculate the number of quarter tones of@tie{}@var{pp} from" + " middle@tie{}C.") { LY_ASSERT_SMOB (Pitch, pp, 1); Pitch *p = unsmob_pitch (pp); @@ -102,9 +126,9 @@ LY_DEFINE (ly_pitch_quartertones, "ly:pitch-quartertones", } LY_DEFINE (ly_pitch_semitones, "ly:pitch-semitones", - 1, 0, 0, (SCM pp), - "Calculate the number of semitones of@tie{}@var{pp} from" - " middle@tie{}C.") + 1, 0, 0, (SCM pp), + "Calculate the number of semitones of@tie{}@var{pp} from" + " middle@tie{}C.") { LY_ASSERT_SMOB (Pitch, pp, 1); Pitch *p = unsmob_pitch (pp); @@ -113,8 +137,8 @@ LY_DEFINE (ly_pitch_semitones, "ly:pitch-semitones", } LY_DEFINE (ly_pitch_less_p, "ly:pitchget_property ("middleCClefPosition"), 0); + int offset = robust_scm2int (c->get_property ("middleCOffset"), 0); + /* middleCCuePosition overrides the clef! */ + SCM cue_pos = c->get_property ("middleCCuePosition"); + if (scm_is_number (cue_pos)) + clef_pos = robust_scm2int (cue_pos, 0); + + c->set_property (ly_symbol2scm ("middleCPosition"), scm_from_int (clef_pos + offset)); + return SCM_UNSPECIFIED; +}