private string Calculate(clsFileStream fs, int?inertia) { KeysList = new List <clsKeysAlg>(); KeysLabels = new List <string>(); clsKeysAlg.eAlg alg = clsKeysAlg.eAlg.Weighted; if (optAlgFlat.Checked) { alg = clsKeysAlg.eAlg.Flat; } //clsFileStream csvfileconv; clsNoteMap notemap; if (chkChordFile.Checked) { if (P.F.CF?.Evs == null || P.F.CF.Evs.Count == 0) { return("Empty ChordFile"); } notemap = P.F.CF.NoteMap; } else { if (fs != null) { notemap = fs.NoteMap; } else { try { notemap = (new clsFileStream(FileName, TrkSelect, true, false, true)).NoteMap; } catch (MidiFileException exc) { return("MidiFileException: " + exc.Message); } } } clsKeysAlg.eProfile profile = clsKeysAlg.eProfile.Default; if (optProfileJazz.Checked) { profile = clsKeysAlg.eProfile.Jazz; } else if (optProfileSpecial.Checked) { profile = clsKeysAlg.eProfile.Special; } Segments = new clsKeysAlg.clsSegments(notemap); if (Segments.indEmpty) { return("Empty Tracks"); } CF = (chkLoadTxt.Checked && P.F.CF != null) ? CF = P.F.CF : null; KeysLabels.Add("Txt"); //leave in, even if text not present clsKeysAlg.Alg = alg; //clsKeysAlg.Trace = indTrace; clsKeysAlg.Segments = Segments; if (inertia.HasValue) { AddToKeysList(alg, profile, inertia.Value); } else { AddToKeysList(alg, profile, 0); AddToKeysList(alg, profile, 30); AddToKeysList(alg, profile, 50); AddToKeysList(alg, profile, 70); AddToKeysList(alg, profile, 90); AddToKeysList(alg, profile, 110); } CalcMinorScores(); PopulatelvMod(true); //cmdDebugSegs.Enabled = true; return(""); }
private void CalcMinorScores() { //* calculate minor key scores for different minor key types //* use currently selected inertia(penalty), alg, profile //* calculate totals of each pitchclass for segements(bars) in a minor key int[] pctots = new int[12]; //pitchclass totals for (int i = 0; i < 12; i++) { pctots[i] = 0; } int index = (KeysList.Count > 1) ? GetInertia() : 0; if (KeysList.Count == 0) { LogicError.Throw(eStopError.Y003); //unable to reproduce this, but it did happen! return; } clsKeysAlg keysalg = KeysList[index]; clsKeysAlg.clsSegments segs = clsKeysAlg.Segments; for (int segnum = 0; segnum < keysalg.Keys.Count; segnum++) { clsKeyTicks key = keysalg.Keys[segnum]; if (key != null && key.Scale == "minor") { if (segnum != key.BBT.Bar) { LogicError.Throw(eLogicError.X094); break; } for (int pc = 0; pc < 12; pc++) { pctots[pc] += segs.Segs[segnum][pc]; } } } //* calculate totals of l/l- t/t- combinations int totharmonic = pctots[8] + pctots[11]; //l- t int totmelup = pctots[9] + pctots[11]; //l t int totmeldown = pctots[8] + pctots[10]; //l- t- int totspecial = pctots[9] + pctots[10]; //l t- lblTotHarmonic.Text = totharmonic.ToString(); lblTotMelUp.Text = totmelup.ToString(); lblTotMelDown.Text = totmeldown.ToString(); lblTotSpecial.Text = totspecial.ToString(); eMinorKeyType maxtottype = eMinorKeyType.Harmonic; int maxtot = totharmonic; if (totmelup > maxtot) { maxtottype = eMinorKeyType.MelodicUp; maxtot = totmelup; } if (totmeldown > maxtot) { maxtottype = eMinorKeyType.MelodicDown; maxtot = totmeldown; } if (totspecial > maxtot) { maxtottype = eMinorKeyType.Special; maxtot = totspecial; } FontStyle fontstyle; fontstyle = (maxtottype == eMinorKeyType.Harmonic) ? FontStyle.Bold : FontStyle.Regular; lblTotHarmonic.Font = new Font(lblTotHarmonic.Font, fontstyle); fontstyle = (maxtottype == eMinorKeyType.MelodicUp) ? FontStyle.Bold : FontStyle.Regular; lblTotMelUp.Font = new Font(lblTotMelUp.Font, fontstyle); fontstyle = (maxtottype == eMinorKeyType.MelodicDown) ? FontStyle.Bold : FontStyle.Regular; lblTotMelDown.Font = new Font(lblTotMelDown.Font, fontstyle); fontstyle = (maxtottype == eMinorKeyType.Special) ? FontStyle.Bold : FontStyle.Regular; lblTotSpecial.Font = new Font(lblTotSpecial.Font, fontstyle); if (chkUseHighestMinorKeyType.Checked) { P.frmStart.MinorKeyType = maxtottype; } }