{"size": 812, "ext": "js", "max_stars_repo_path": "packages/piece-pulse-code-modulation/src/get-similar-notes.js", "max_stars_repo_name": "Tiamat-Tech/pieces-alex-bainter", "max_stars_repo_stars_event_min_datetime": "2019-03-17T02:39:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T05:51:47.000Z", "max_issues_repo_path": "packages/piece-pulse-code-modulation/src/get-similar-notes.js", "max_issues_repo_name": "Tiamat-Tech/pieces-alex-bainter", "max_issues_repo_issues_event_min_datetime": "2019-03-29T09:57:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T22:45:13.000Z", "max_forks_repo_path": "packages/piece-pulse-code-modulation/src/get-similar-notes.js", "max_forks_repo_name": "Tiamat-Tech/pieces-alex-bainter", "max_forks_repo_forks_event_min_datetime": "2019-03-17T06:50:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-16T11:46:59.000Z"}
{"max_stars_count": 533, "max_issues_count": 17, "max_forks_count": 58, "avg_line_length": 35.3043478261, "max_line_length": 82, "alphanum_fraction": 0.6403940887}
import { getPitchClass, toss, getDistance } from '@generative-music/utilities';
import getSimilarPitchClasses from './get-similar-pitch-classes';

const getSimilarNotes = (currentNotes, octaves) => {
  const pitchClasses = Array.from(
    new Set(currentNotes.map(note => getPitchClass(note)))
  );
  return toss(getSimilarPitchClasses(pitchClasses), octaves)
    .filter(() => window.generativeMusic.rng() < (11 - pitchClasses.length) / 10)
    .reduce(
      (noYuckyIntervals, note) =>
        noYuckyIntervals.every(otherNote => {
          const distance = Math.abs(getDistance(note, otherNote));
          return distance !== 6 && distance !== 1;
        })
          ? noYuckyIntervals.concat([note])
          : noYuckyIntervals,
      []
    );
};

export default getSimilarNotes;
