Esempio n. 1
0
        private void loadPadInfo()
        {
            XmlReader xml;

            xml = XmlReader.Create(new StreamReader("Resource/ChordPad.xml"));
            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.Element && xml.Name == "pad")
                {
                    int    id;
                    string notation;
                    id       = int.Parse(xml.GetAttribute("id"));
                    notation = xml.GetAttribute("notation");
                    var res = Harmony.createHarmony(notation);
                    if (res != null)
                    {
                        harmonyToId.Add(res.uniqueId, harmonies.Count);
                        harmonies.Add(res);
                    }
                }
            }
            xml.Close();
            for (int x = 0; x < ChordBasic.toneCount; x++)
            {
                for (int y = 0; y < harmonies.Count; y++)
                {
                    chordPadList.Add(new ChordPad(x, y, new Chord(ChordBasic.getTone(x), harmonies[y])));
                }
            }
            xml = XmlReader.Create(new StreamReader("Resource/ChordRole.xml"));
            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.Element && xml.Name == "role")
                {
                    string roleChordString = xml.GetAttribute("chord");
                    var    chordPad        = chordPadList.Find(m => m.chord.ToString() == roleChordString);
                    if (chordPad != null)
                    {
                        if (xml.GetAttribute("scale") == "M")
                        {
                            chordPad.roleInMajor = xml.GetAttribute("name");
                        }
                        else
                        {
                            chordPad.roleInMinor = xml.GetAttribute("name");
                        }
                    }
                }
            }
            xml.Close();
            isMajor = true;
        }
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));
            }
        }