コード例 #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 <Scale> GetScales()
        {
            if (_scales != null)
            {
                return(_scales);
            }

            _scales = new List <Scale>();

            var chromaticNotes = NoteHelper.GetNoteNames().Select(NoteHelper.NoteToNumber).ToList();

            chromaticNotes.AddRange(NoteHelper.GetNoteNames().Select(NoteHelper.NoteToNumber).ToList());

            var scaleDefinitions = new Dictionary <string, int[]>
            {
                { "Natural Minor", new[] { 0, 2, 1, 2, 2, 1, 2 } },
                { "Harmonic Minor", new[] { 0, 2, 1, 2, 2, 1, 3 } },
                { "Major", new[] { 0, 2, 2, 1, 2, 2, 2 } }
            };


            foreach (var scaleDefinition in scaleDefinitions)
            {
                var increments = scaleDefinition.Value.ToList();
                for (var i = 0; i < 12; i++)
                {
                    var noteIndex = i;
                    var notes     = new List <int>();
                    foreach (var increment in increments)
                    {
                        noteIndex += increment;
                        notes.Add(chromaticNotes[noteIndex]);
                    }
                    var scale = new Scale()
                    {
                        Name  = NoteHelper.NumberToNoteOnly(chromaticNotes[i]) + " " + scaleDefinition.Key,
                        Notes = notes
                    };
                    _scales.Add(scale);
                }
            }

            return(_scales);
        }