lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pitch questions


From: Rune Zedeler
Subject: Pitch questions
Date: Thu, 11 Oct 2007 01:08:47 +0200
User-agent: Thunderbird 1.5.0.13 (X11/20070824)

I am looking into splitting pitch into pitchclass and pitch.
Therefore I need to understand what is going on in the pitch class.
Some questions (inserted as c++-comments):

void
Pitch::normalize ()
{
  Rational pitch = tone_pitch ();
  while (notename_ >= (int) scale_->step_tones_.size ())
    {
      notename_ -= scale_->step_tones_.size ();
      octave_++;
      // why? isn't this always 0? -rz
      alteration_ -= tone_pitch () - pitch;
    }
  while (notename_ < 0)
    {
      notename_ += scale_->step_tones_.size ();
      octave_--;
      // do -rz
      alteration_ -= tone_pitch () - pitch;
    }

  while (alteration_ > Rational (1))
    {
// code duplication. Remove this and move the two above while-loops below this one: -rz
      if (notename_ == int (scale_->step_tones_.size ()))
        {
          notename_ = 0;
          octave_++;
        }
      else
        notename_++;

      // isn't this the same as alteration_ = pitch - tone_pitch() -rz
      alteration_ = Rational (0);
      alteration_ -= tone_pitch () - pitch;
    }
  while (alteration_ < Rational (-1))
    {
      // do -rz
      if (notename_ == 0)
        {
          notename_ = scale_->step_tones_.size ();
          octave_--;
        }
      else
        notename_--;

      // do -rz
      alteration_ = 0;
      alteration_ -= tone_pitch () - pitch;
    }
}

And something a bit more serious:

void
Pitch::transpose (Pitch delta)
{
  Rational new_alter = tone_pitch () + delta.tone_pitch ();

  octave_ += delta.octave_;
  notename_ += delta.notename_;
  alteration_ += new_alter - tone_pitch ();

  normalize ();
}

This looks very ineffecient.

  Rational new_alter = tone_pitch () + delta.tone_pitch ();
  alteration_ += new_alter - tone_pitch ();

is equivalent to

alteration_ += delta.tone_pitch ();

So if we transpose a huge distance then we add a lot to the alteration. (A simple transpose c, c'' will add 18 to the alteration) And the normalize () function is linear in the size of the alteration. So transposing time-usage is linear in the distance we transpose.
Afaics.

-Rune





reply via email to

[Prev in Thread] Current Thread [Next in Thread]