示例#1
0
        public static Phrase TransposeToScale(Phrase phrase, string fromScale, string toScale)
        {
            var fromRoot = GetScaleRootNote(fromScale);
            var toRoot   = GetScaleRootNote(toScale);

            var fromType = GetScaleType(fromScale);
            var toType   = GetScaleType(toScale);

            Phrase transposedPhrase;

            if (fromType == toType)
            {
                transposedPhrase = phrase.Clone();
            }
            else
            {
                var intermediateScale = NoteHelper.NumberToNoteOnly(fromRoot) + " " + toType;
                transposedPhrase = MashNotesToScale(phrase, intermediateScale);
            }

            var distance = NoteHelper.GetDistanceBetweenNotes(fromRoot, toRoot);

            if (distance == 0)
            {
                return(transposedPhrase);
            }

            var direction = distance < 0 ? Direction.Down : Direction.Up;

            transposedPhrase = NoteHelper.ShiftNotes(transposedPhrase, Math.Abs(distance), Interval.Step, direction);
            transposedPhrase = MashNotesToScale(transposedPhrase, toScale);

            return(transposedPhrase);
        }
示例#2
0
        public static List <ScaleMatch> FindMatchingScales(List <int> notes)
        {
            var noteNumbers = notes
                              .Select(NoteHelper.NumberToNoteOnly)
                              .Select(NoteHelper.NoteToNumber)
                              .Distinct()
                              .OrderBy(x => x)
                              .ToList();

            var matches = new List <ScaleMatch>();

            foreach (var scale in GetScales())
            {
                var match = MatchNotesToScale(noteNumbers, scale);
                matches.Add(match);
            }

            return(matches.OrderBy(x => x.DistanceFromScale)
                   .ThenBy(x => Math.Abs(NoteHelper.GetDistanceBetweenNotes(notes[0], x.Scale.Notes[0])))
                   .ToList());
        }
示例#3
0
 private static int DistanceFromScale(int note, Scale scale)
 {
     return(scale.Notes.Select(x => Math.Abs(NoteHelper.GetDistanceBetweenNotes(note, x))).Min());
 }