public void LessonPlanChanged(int value) { bool lessonplanSelected = (value != 0); if (lessonplanSelected) { string lessonplanFile = lessonplanInfos[value - 1].FullName; ParsedCSV lessonplanCSV = ReadCSV(lessonplanFile); Scale.LessonPlanNames = lessonplanCSV.names; Scale.Distribution = lessonplanCSV.values; lessonplanSliders.Activate(); acceptButton.interactable = true; } }
public void ScaleChanged(int value) { bool scaleSelected = (value != 0); if (scaleSelected) { // Read CSV string scaleDir = scaleDirInfos[value - 1].FullName; scaleName = scaleDirInfos[value - 1].Name; string csvFrequenciesPath = Path.Combine(scaleDir, csvFrequenciesFilename); ParsedCSV frequencyCSV = ReadCSV(csvFrequenciesPath); Scale.NoteNames = frequencyCSV.names; Scale.Frequencies = frequencyCSV.values; Scale.ScaleDegrees = frequencyCSV.itemsPerLine; Scale.Alterations = frequencyCSV.linePairs; lessonplanDropdown.interactable = true; } }
private ParsedCSV ReadCSV(string csvPath) { const int NAMES = 0; const int VALUES = 1; ParsedCSV csv = new ParsedCSV(); using (StreamReader reader = new StreamReader(csvPath)) { int lineNumber = 0; while (!reader.EndOfStream) { var line = reader.ReadLine(); var tokens = line.Split(','); if (csv.itemsPerLine == 0) { csv.itemsPerLine = tokens.Length; } int lineType = lineNumber % 2 == 0 ? NAMES : VALUES; foreach (string token in tokens) { if (lineType == VALUES) { float t = float.Parse(token); csv.values.Add(t); } else { csv.names.Add(token); } } if (lineType == VALUES) { csv.linePairs++; } lineNumber++; } } return(csv); }