public LengthContainer Clone() { var clone = new LengthContainer(); length.ForEach(x => clone.AddLengthElement(x)); return(clone); }
private void FillLengthTableLoop(LengthContainer[] table, List <LengthElement> elements, int n, LengthContainer container, Settings.NoteRest settings) { if (elements.Count == n) { return; } LengthContainer newContainer = container.Clone(); int loopcnt = (elements[n].TripletFlag ? 2 : 1); for (int i = 0; i < loopcnt; i++) { newContainer.AddLengthElement(elements[n]); if (newContainer.Gate >= table.Length) { return; } if (table[newContainer.Gate] == null) { table[newContainer.Gate] = newContainer; } else { if (settings.LengthStyle == 0) { if (newContainer.Count < table[newContainer.Gate].Count) { table[newContainer.Gate] = newContainer; } else if (newContainer.Count == table[newContainer.Gate].Count) { if (newContainer.TripletCount < table[newContainer.Gate].TripletCount) { table[newContainer.Gate] = newContainer; } } } else { if (newContainer.TripletCount < table[newContainer.Gate].TripletCount) { table[newContainer.Gate] = newContainer; } } } for (int j = n + 1; j < elements.Count; j++) { FillLengthTableLoop(table, elements, j, newContainer, settings); } if (elements[n].TripletFlag) { newContainer = container.Clone(); } } }
private int[][] CreateLengthTable(uint countsPerWholeNote, Settings.NoteRest settings) { // Create length elements var elements = new List <LengthElement>(); int div = 1; int divtri; while (true) { if (countsPerWholeNote % div == 0) { elements.Add(new LengthElement(div, ((int)countsPerWholeNote / div), false)); divtri = div * 3; if (countsPerWholeNote % divtri == 0) { elements.Add(new LengthElement(divtri, ((int)countsPerWholeNote / divtri), true)); } div <<= 1; } else { break; } } elements = elements.OrderBy(x => x.Length).ToList(); // Create length table var table = new LengthContainer[countsPerWholeNote]; table[0] = new LengthContainer(); table[0].AddLengthElement(elements.Find(x => x.Length == 1)); elements.Remove(elements.Find(x => x.Length == 1)); // Remove whole note for (int i = 0; i < elements.Count; i++) { FillLengthTableLoop(table, elements, i, new LengthContainer(), settings); } return(table.Select(x => x.GetLength(settings)).ToArray()); }