Logo Search packages:      
Sourcecode: csound version File versions  Download package

double csound::Voicelead::closestPitch ( double  pitch,
const std::vector< double > &  pitches 
) [static]

Return the pitch in pitches that is closest to the specified pitch.

Definition at line 434 of file Voicelead.cpp.

Referenced by conformToPitchClassSet(), and csound::Score::setPitches().

  {
    std::map<double, double> pitchesForDistances;
    for (size_t i = 0, n = pitches_.size(); i < n; i++) {
      double pitch_ = pitches_[i];
      double distance = std::fabs(pitch_ - pitch);
      pitchesForDistances[distance] = pitch_;
    }
    return pitchesForDistances.begin()->second;
  }


Generated by  Doxygen 1.6.0   Back to index