Esempio n. 1
0
        public static Harmony createHarmony(string notationName, int rootId = 0)
        {
            string currentNotation = notationName;
            int    baseNote        = 0;

            string[] onChordSplitter = { "/", "on" };
            var      sp = currentNotation.Split(onChordSplitter, StringSplitOptions.None);

            if (sp.Length > 1)
            {
                Tone baseTone = Tone.getToneFromKeyName(sp[1]);
                if (baseTone == null)
                {
                    return(null);
                }
                baseNote        = (baseTone.id + ChordBasic.toneCount - rootId) % ChordBasic.toneCount;
                currentNotation = sp[0];
            }
            currentNotation = currentNotation.Replace("(", "");
            currentNotation = currentNotation.Replace(")", "");

            bool[]          used      = new bool[ChordBasic.notationList.Count];
            List <Notation> notations = new List <Notation>();

            while (true)
            {
                var matchedList = ChordBasic.notationList.FindAll(m =>
                                                                  (m.name.Length <= currentNotation.Length) && (m.name == currentNotation.Substring(currentNotation.Length - m.name.Length)) && !used[m.id]);
                if (matchedList.Count == 0)
                {
                    break;
                }
                matchedList.Sort((n1, n2) => (n1.name.Length < n2.name.Length?1:-1));
                used[matchedList[0].id] = true;
                currentNotation         = currentNotation.Substring(0, currentNotation.Length - matchedList[0].name.Length);
                notations.Insert(0, matchedList[0]);
            }
            if (currentNotation.Length != 0)
            {
                return(null);
            }
            else
            {
                return new Harmony(notations, baseNote)
                       {
                           originalNoationName = notationName
                       }
            };
        }
Esempio n. 2
0
        public static Chord createChordFromChordName(string chordName)
        {
            string rootString;
            string notationString;

            if (chordName.Length == 1)
            {
                rootString     = chordName;
                notationString = "";
            }
            else if (chordName[1] != '#' && chordName[1] != 'b')
            {
                rootString     = chordName.Substring(0, 1);
                notationString = chordName.Substring(1);
            }
            else
            {
                rootString     = chordName.Substring(0, 2);
                notationString = chordName.Substring(2);
            }

            Tone root = Tone.getToneFromKeyName(rootString);

            if (root == null)
            {
                return(null);
            }
            Harmony harmony = Harmony.createHarmony(notationString, root.id);

            if (harmony == null)
            {
                return(null);
            }
            else
            {
                return(new Chord(root, harmony));
            }
        }