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 } }; }
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)); } }
private Harmony(List <Notation> _notations, int _baseNote = 0) { notations = _notations; baseNote = _baseNote; for (int i = 0; i < notations.Count; i++) { for (int j = 0; j < notations[i].work.Length; j++) { string[] operation = notations[i].work[j].Split(' '); if (operation.Length != 2) { continue; } int targetStep = Tone.getStepFromIntervalName(operation[1]); if (operation[0] == "add") { toneStepList.Add(targetStep); } else if (operation[0] == "del") { toneStepList.Remove(targetStep); } else if (operation[0] == "inc") { int targetIndex = toneStepList.FindIndex(m => m == targetStep); toneStepList[targetIndex]++; } else if (operation[0] == "dec") { int targetIndex = toneStepList.FindIndex(m => m == targetStep); toneStepList[targetIndex]--; } } } }
public Chord(Tone _root, Harmony _harmony) { root = _root; harmony = _harmony; }