notename_ = n;
alteration_ = a;
octave_ = o;
-
- if (n < 0 || n >= 7 ||
- a < -2 || a > 2)
- {
- String s = _ ("Pitch arguments out of range");
- s += ": alteration = " + to_string (a);
- s += ", notename = " + to_string (n);
- warning (s);
- }
normalise ();
}
/*
should be settable from input?
*/
-static Byte pitch_byte_a[ ] = { 0, 2, 4, 5, 7, 9, 11 };
+static Byte diatonic_scale_semitones[ ] = { 0, 2, 4, 5, 7, 9, 11 };
/* Calculate pitch height in 12th octave steps. Don't assume
n += 7;
o --;
}
- return (o + n / 7) * 12 + pitch_byte_a[n % 7] + alteration_;
+
+ if (alteration_ % 2)
+ {
+ programming_error ("Calling semitone_pitch() for quarter tone alterations.");
+
+ }
+
+ return (o + n / 7) * 12 + diatonic_scale_semitones[n % 7] + (alteration_/2);
+}
+
+int
+Pitch::quartertone_pitch () const
+{
+ int o = octave_;
+ int n = notename_;
+ while (n < 0)
+ {
+ n += 7;
+ o --;
+ }
+
+ return (o + n / 7) * 24 + 2* diatonic_scale_semitones[n % 7] + (alteration_);
}
void
Pitch::normalise ()
{
- int pitch = semitone_pitch ();
+ int pitch = quartertone_pitch ();
while (notename_ >= 7)
{
notename_ -= 7;
octave_++;
- alteration_ -= semitone_pitch () - pitch;
+ alteration_ -= quartertone_pitch () - pitch;
}
while (notename_ < 0)
{
notename_ += 7;
octave_--;
- alteration_ -= semitone_pitch () - pitch;
+ alteration_ -= quartertone_pitch () - pitch;
}
- while (alteration_ >= 3)
+ while (alteration_ > DOUBLE_SHARP)
{
if (notename_ == 6)
{
notename_++;
alteration_ = 0;
- alteration_ -= semitone_pitch () - pitch;
+ alteration_ -= quartertone_pitch () - pitch;
}
- while (alteration_ <= -3)
+
+ while (alteration_ < DOUBLE_FLAT)
{
if (notename_ == 0)
{
notename_--;
alteration_ = 0;
- alteration_ -= semitone_pitch () - pitch;
+ alteration_ -= quartertone_pitch () - pitch;
}
}
void
Pitch::transpose (Pitch delta)
{
- int new_semi = semitone_pitch () +delta.semitone_pitch();
+ int new_semi = quartertone_pitch () +delta.quartertone_pitch();
octave_ += delta.octave_;
notename_ += delta.notename_;
- alteration_ += new_semi - semitone_pitch();
+ alteration_ += new_semi - quartertone_pitch();
normalise ();
}
Pitch
interval (Pitch const & from , Pitch const & to )
{
- int sound = to.semitone_pitch() - from.semitone_pitch ();
+ int sound = to.quartertone_pitch() - from.quartertone_pitch ();
Pitch pt (to.get_octave () - from.get_octave (),
to.get_notename() - from.get_notename(),
+
to.get_alteration() - from.get_alteration());
- return pt.transposed (Pitch(0,0,sound - pt.semitone_pitch()));
+ return pt.transposed (Pitch(0,0,sound - pt.quartertone_pitch()));
}
/* FIXME
Merge with *pitch->text* funcs in chord-name.scm
*/
-char const *accname[] = {"eses", "es", "", "is" , "isis"};
+char const *accname[] = {"eses", "eseh", "es", "eh", "",
+ "ih", "is" , "isih", "isis"};
String
-Pitch::string () const
+Pitch::to_string () const
{
int n = (notename_ + 2) % 7;
- String s = to_string (char (n + 'a'));
+ String s = ::to_string (char (n + 'a'));
if (alteration_)
- s += String (accname[alteration_ + 2]);
+ s += String (accname[alteration_ - DOUBLE_FLAT]);
if (octave_ >= 0)
{
{
int o = (-octave_) - 1;
while (o--)
- s += to_string (',');
+ s += ::to_string (',');
}
return s;
Pitch *r = (Pitch *) ly_cdr (s);
scm_puts ("#<Pitch ", port);
- scm_display (scm_makfrom0str (r->string ().to_str0 ()), port);
+ scm_display (scm_makfrom0str (r->to_string ().to_str0 ()), port);
scm_puts (" >", port);
return 1;
return gh_int2scm (q);
}
-LY_DEFINE(pitch_semitones, "ly:pitch-semitones", 1, 0, 0,
+LY_DEFINE(ly_pitch_quartertones, "ly:pitch-quartertones", 1, 0, 0,
+ (SCM pp),
+ "calculate the number of semitones of @var{p} from central C.")
+{
+ Pitch *p = unsmob_pitch (pp);
+ SCM_ASSERT_TYPE(p, pp, SCM_ARG1, __FUNCTION__, "Pitch");
+
+ int q = p->quartertone_pitch ();
+
+ return gh_int2scm (q);
+}
+
+LY_DEFINE(ly_pitch_semitones, "ly:pitch-semitones", 1, 0, 0,
(SCM pp),
"calculate the number of semitones of @var{p} from central C.")
{
LY_DEFINE(pitch_less, "ly:pitch<?", 2,0,0, (SCM p1, SCM p2),
"Is @var{p1} lower than @var{p2}? This uses lexicographic ordening.")
{
- return Pitch::less_p (ly_car (p1), ly_car (p2));
-}
+ Pitch *a = unsmob_pitch (p1);
+ Pitch *b = unsmob_pitch (p2);
+
+ SCM_ASSERT_TYPE(a, p1, SCM_ARG1, __FUNCTION__, "Pitch");
+ SCM_ASSERT_TYPE(b, p2, SCM_ARG2, __FUNCTION__, "Pitch");
+ if (Pitch::compare (*a, *b) < 0)
+ return SCM_BOOL_T;
+ else
+ return SCM_BOOL_F;
+}
LY_DEFINE(ly_pitch_diff, "ly:pitch-diff", 2 ,0 ,0,
(SCM pitch, SCM root),
- "Return pitch with value DELTA = PITCH - ROOT, ie,
-ROOT == (ly:pitch-transpose root delta).")
+ "Return pitch with value DELTA = PITCH - ROOT, ie, "
+ "ROOT == (ly:pitch-transpose root delta).")
{
Pitch *p = unsmob_pitch (pitch);
Pitch *r = unsmob_pitch (root);
SCM_ASSERT_TYPE(p, pitch, SCM_ARG1, __FUNCTION__, "Pitch");
SCM_ASSERT_TYPE(r, root, SCM_ARG2, __FUNCTION__, "Pitch");
- return interval (*p, *r ).smobbed_copy();
+ return interval (*r, *p).smobbed_copy();
}
-
-
-
-
SCM
Pitch::smobbed_copy ()const
{