private void PrintSegs(int seglo, int seghi, int[] tot) { int maxtot = tot.Max(); Debug.WriteLine("SegCount for " + FileName + " From Seg:" + (seglo + 1) + " To Seg:" + (seghi + 1)); string msg = "Abs: "; for (int p = 0; p < 12; p++) { tot[p] = (tot[p] * 100) / maxtot; msg += NoteName.ToSharpFlat(NoteName.GetNoteName(0, 0, p)) + ": " + tot[p] + " "; } Debug.WriteLine(msg); if (CF != null) //print rel { clsKeyTicks txtkey = GetFileKey(seglo); //assume seglo is key for this range msg = NoteName.ToSharpFlat(txtkey.KeyStrShort) + ": "; for (int p = 0; p < 12; p++) { int i = (p + txtkey.KeyNote).Mod12(); msg += NoteName.Solfa.Substring(p * 2, 2) + ": " + tot[i] + " "; } Debug.WriteLine(msg); } }
private void picPC_Paint(object sender, PaintEventArgs e) { Graphics xgr = e.Graphics; xgr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; SizeF size = new SizeF(Diameter, Diameter); //int oldkeynote = Key.KBTrans_KeyNote; //Key = (P.F.MTime == null) ? new clsKey(0, "major", 0) : P.F.Keys[P.F.CurrentBBT.Ticks]; int oldkeynote = Key.KeyNote; Key = (P.F.MTime == null) ? new clsKeyTicks(0, "major", 0) : P.F.Keys[P.F.CurrentBBT.Ticks, kbtrans : true]; int cfindex = P.F.CF.FindCFEv(P.F.CurrentBBT); //this or prev //* recreate nodes if necessary //if (Key.KBTrans_KeyNote != oldkeynote) CreateNodes(); if (Key.KeyNote != oldkeynote) { CreateNodes(); //update solfa (and enharmonic notes?) } //* show nodes ShowNodes(xgr, size); //* check if bullseyes should be shown if (LookAhead > 0 && P.F.CF != null) { ShowBullsEyes(xgr, size); } //* drawstring solfa or note ShowNodesTxt(xgr, size); //* show chords (name and qualifier) ShowChords(); }
private void frmTonnetz_Load(object sender, EventArgs e) { BackColor = Utils.SetBackColor(Forms.frmSC.Mtx, BackColor); nudLookAhead.Value = LookAhead; SetFormTitle(); Cfg.DictFormProps[Name].SetForm(this); if (P.F?.Keys != null) { Key = P.F.Keys[0, kbtrans : true]; } CreateNodes(); picPC.BackColor = P.ColorsTonnetz["Background"].Co; clsTT.LoadToolTips(this); }
private static void NewManChords(bool down, bool playactual) { if (down) { clsKeyTicks key = new clsKeyTicks("C", "major", 0); //temp P.frmSC.Play.ManChords = new ChordCadenza.clsManChords(key, playactual); } else { if (P.frmSC.Play.ManChords != null) { clsManChords.ShowChord(null, null); P.frmSC.Play.ManChords = null; } } }
internal void ShowList() { if (Type == eList.Msgs) { txtList.Lines = Msgs; return; } string[] lines = null; clsFileStream fs = null; if (P.F.FSTrackMap != null) { fs = P.F.FSTrackMap; } else if (P.F.FileStreamConv != null) { fs = P.F.FileStreamConv; } //* get first selected track, or null if (Type == eList.Strm) { clsTrks.T trk = null; clsFileStream.clsEvStrm[] strm = P.F.FSTrackMap.Strm; if (strm == null) { return; } clsTrks.Array <bool> trkselect = P.F.frmTrackMap?.GetSelectedTrks(); if (trkselect != null) { foreach (clsTrks.T t in trkselect.Next) { if (trkselect[t]) { trk = t; break; } } } Text = "Show Strm for "; Text += (trk == null) ? "all tracks" : "track " + trk.ToString(); //* display headings List <string> list = new List <string>(110); string fmt = "{0,6} {1,3} {2,6} {3,6} {4}"; list.Add((string.Format(fmt, "Seq", "Trk", "Ticks", "DITime", "Data"))); //* show data from CurrentBBT int strmpos = clsFileStream.clsPlay.Find(P.F.FSTrackMap, strm, P.F.CurrentBBT.Ticks); int cnt = 0; for (int i = strmpos; i < strm.Length; i++) { clsFileStream.clsEvStrm s = strm[i]; if (trk != null && s.Trk != null && trk != s.Trk) { continue; } string t = (s.Trk == null) ? "*" : s.Trk.ToString(); list.Add(String.Format(fmt, i, t, s.Ticks, s.QTime, s.ToString())); if (++cnt > 100) { break; } } lines = list.ToArray(); } else if (Type == eList.Attributes) { if (P.F.MTime == null) { return; } Text = "Show Project and System Attributes"; List <string> lineslist = new List <string>(); //lineslist.Add("Version = " + P.Version); lineslist.Add("64-bit Operating System = " + Environment.Is64BitOperatingSystem); lineslist.Add("64-bit Process = " + Environment.Is64BitProcess); lineslist.Add("Debug Mode = " + Debugger.IsAttached); //#if APPDATAPATH // lineslist.Add("AppDataPath = true"); //#else // lineslist.Add("AppDataPath = false"); //#endif #if ADVANCED lineslist.Add("Advanced = true"); #else lineslist.Add("Advanced = false"); #endif lineslist.Add("TicksPerQuarterNote = " + P.F.MTime.TicksPerQNote); lineslist.Add("TicksPerQI = " + P.F.TicksPerQI); lineslist.Add("QIPerNote = " + P.F.QIPerNote); if (P.F.FSTrackMap?.Text00.Count > 0) { lineslist.Add(""); lineslist.Add("Initial text events on MidiFile conductor track"); lineslist.Add("-----------------------------------------------"); foreach (string text in P.F.FSTrackMap?.Text00) { lineslist.Add(text); } } lines = lineslist.ToArray(); } else if (Type == eList.TSigs) { if (P.F.MTime?.TSigs == null) { return; } Text = "Show Time Signatures"; string fmt = "{0,3} {1,2}/{2,-2}"; //* bar nn / dd lines = new string[P.F.MTime.TSigs.Length + 2]; //lines[0] = "Source: Midi"; lines[0] = string.Format(fmt, "Bar", "NN", "DD"); for (int i = 0; i < P.F.MTime.TSigs.Length; i++) { clsMTime.clsTSigBB tsig = P.F.MTime.TSigs[i]; lines[i + 1] = String.Format(fmt, tsig.Bar + 1, tsig.NN, tsig.DD); } } else if (Type == eList.Keys) { clsKeysTicks keys = P.F.Keys; if (keys == null) { return; } Text = "Show Keys"; string fmt = "{0,3} {1,4} {2,5} {3,-5}"; //* bar beat pitch scale lines = new string[keys.Keys.Count + 1]; lines[0] = string.Format(fmt, "Bar", "Beat", "Pitch", "Scale"); for (int i = 0; i < keys.Keys.Count; i++) { clsKeyTicks key = keys.Keys[i]; lines[i + 1] = String.Format(fmt, key.BBT.Bar + 1, key.BBT.BeatsRemBar + 1, key.KeyNoteStr_ToSharpFlat, key.Scale); } } else if (Type == eList.Tempos) { if (fs == null || fs.TempoMap == null) { return; } Text = "Show Tempos"; string fmt = "{0,3} {1,4} {2,5} {3,9} {4,10}"; //* bar beat tempo lines = new string[Math.Max(2, fs.TempoMap.Count + 1)]; lines[0] = string.Format(fmt, "Bar", "Beat", "Tempo", "MidiTempo", "MSecsPerQI"); int miditempo, bpm, msecsperqi; if (fs.TempoMap.Count == 0) { //miditempo = fs.TempoMap[0]; //default miditempo = fs.TempoMap.GetFirstValue(); //default msecsperqi = (P.F.TicksPerQI * miditempo) / (P.F.MTime.TicksPerQNote * 1000); //msecsperpi = (P.F.TicksPerPI * miditempo) / (P.F.MTime.TicksPerQNote * 1000); int dd = P.F.MTime.GetTSig(0).DD; bpm = clsAudioSync.DivRound(dd * 60000000, 4 * miditempo); lines[1] = String.Format(fmt, 1, 1, bpm, miditempo, msecsperqi); lines[1] += " (default)"; } else { //for (int i = 0; i < fs.TempoMap.Count; i++) { // int ticks = fs.TempoMap.KeyByIndex(i); // miditempo = fs.TempoMap.ValByIndex(i); int linenum = 1; foreach (KeyValuePair <int, int> pair in fs.TempoMap) { int ticks = pair.Key; miditempo = pair.Value; clsMTime.clsBBT bbt = new clsMTime.clsBBT(ticks); msecsperqi = (P.F.TicksPerQI * miditempo) / (P.F.MTime.TicksPerQNote * 1000); int dd = P.F.MTime.GetTSig(ticks).DD; bpm = clsAudioSync.DivRound(dd * 60000000, 4 * miditempo); //lines[i + 1] = String.Format(fmt, bbt.Bar + 1, bbt.BeatsRemBar + 1, bpm, miditempo, msecsperdi); lines[linenum++] = String.Format(fmt, bbt.Bar + 1, bbt.BeatsRemBar + 1, bpm, miditempo, msecsperqi); } } } else if (Type == eList.CtlrTots) { if (fs == null || fs.MidiCtlrs == null) { return; //or P.F.MultiMap or P.F.MultiPlay??? } Text = "Show Controller Totals"; string fmt = "{0,4} {1,4} {2,4} {3,6} {4}"; //string fmt = "{0,4} {1,4} {2,4} {3,4} {4,6} {5}"; //* trk port chan ctlr total description List <string> l = new List <string>(); l.Add(string.Format(fmt, " Trk", "Chan", "Ctlr", "Total", "Description")); for (int ctlr = 0; ctlr < fs.MidiCtlrs.DataLast.GetLength(0); ctlr++) { for (int pc = 0; pc < 16; pc++) { if (fs.MidiCtlrs.DataLast[ctlr, pc] == null) { continue; } int tot = fs.MidiCtlrs.DataLast[ctlr, pc].Count; string trk = "*"; string desc = "???"; if (ctlr == clsMidiCtlrs.PatchCtlrNum) { desc = "Patch"; } else { desc = MidiCtlrList.Desc[ctlr]; } l.Add(String.Format(fmt, trk, (pc + 1), ctlr, tot, desc)); } } lines = l.ToArray(); } else if (Type == eList.CtlrDetails) { if (fs == null || fs.MidiCtlrs == null) { return; //or P.F.MultiMap or P.F.MultiPlay??? } Text = "Show Controller Details"; string fmt = "{0,4} {1,4} {2,4} {3,6} {4,9} {5,4} {6}"; //string fmt = "{0,4} {1,4} {2,4} {3,4} {4,6} {5,9} {6,4} {7}"; //* trk port chan ctlr ticks value description List <string> l = new List <string>(); l.Add(string.Format(fmt, " Trk", "Chan", "Ctlr", "Ticks", "BBT", " Val", "Description")); for (int pc = 0; pc < 16; pc++) { string trk = "*"; for (int ctlr = 0; ctlr < fs.MidiCtlrs.DataLast.GetLength(0); ctlr++) { string desc = "???"; //clsMidiCtlrs.clsMap<int> map = fs.MidiCtlrs.DataLast[ctlr, pc]; clsMap <int> map = fs.MidiCtlrs.DataLast[ctlr, pc]; if (map == null) { continue; } foreach (KeyValuePair <int, int> pair in map) { int ticks = pair.Key; clsMTime.clsBBT bbt = new clsMTime.clsBBT(ticks); int val = pair.Value; if (ctlr == clsMidiCtlrs.PatchCtlrNum) { desc = "Patch: " + GeneralMidiList.Desc[val]; } else { desc = MidiCtlrList.Desc[ctlr]; } l.Add(String.Format(fmt, trk, (pc + 1), ctlr, ticks, bbt.ToString(), val, desc)); } } } lines = l.ToArray(); } else if (Type == eList.Debug) { Text = "Show Debug Info"; List <string> l = new List <string>(); l.Add("Current Ticks = " + P.F.CurrentBBT.Ticks); if (P.F != null) { if (P.F.MTime != null) { l.Add("P.F.MTime.TicksPerQNote = " + P.F.MTime.TicksPerQNote); } l.Add("P.F.TicksPerDI = " + P.F.TicksPerQI); //l.Add("P.F.TicksPerPI = " + P.F.TicksPerPI); l.Add("P.F.MaxTicks = " + P.F.MaxBBT.Ticks); l.Add("P.F.MaxDITime = " + P.F.MaxBBT.QI); //l.Add("P.F.MaxPITime = " + P.F.MaxPITime); } lines = l.ToArray(); } else if (Type == eList.ChordList) //standard chords { Text = "Show Chords"; string fmt = "{0,-8} {1,-8} {2,-8} {3,-4} {4,-24}"; lines = new string[ChordAnalysis.USToTemplate.Values.Count + 1]; lines[0] = string.Format(fmt, "Name", "Name", "Name", "Rank", "Notes"); for (int i = 0; i < ChordAnalysis.FileSeqToTemplate.Values.Count; i++) { ChordAnalysis.clsTemplate t = ChordAnalysis.FileSeqToTemplate.Values[i]; string notes = ""; //root note for (int j = 0; j < 12; j++) { if (t.PC[j]) { notes += NoteName.ToSharpFlat(NoteName.GetNoteName(0, 0, j)) + ' '; } } List <string> names = ChordAnalysis.GetSynonyms(t); string name0 = names[0]; string name1 = (names.Count > 1) ? names[1] : ""; string name2 = (names.Count > 2) ? names[2] : ""; lines[i + 1] = String.Format(fmt, name0, name1, name2, t.Rank, notes); } } else { LogicError.Throw(eLogicError.X048); lines = new string[] { "Invalid Show Type" }; } txtList.Lines = lines; txtList.Select(0, 0); } //method
internal void CreateNodes() { //* always start at C (fixed keyboard allows for modulation) //* change solfa during modulation or kbtrans //* XYPC.PC = displayed PC - same as frmSC Space = HalfSpace * 2; //int pc = (Key == null) ? 0 : Key.KeyNote; int pc = 0; //C int y = 0; int ypos = HalfSpace; XYPC.Clear(); DictXYPC.Clear(); //* initialize PC and DictPC int xpos = HalfSpace; while (ypos < picPC.Height - HalfSpace) { List <clsXYPC> listx = new List <clsXYPC>(); int x = 0; while (xpos < picPC.Width - HalfSpace) { clsXYPC xypc = new clsXYPC(x, y, xpos, ypos, pc); listx.Add(xypc); x++; xpos += Space; pc = (pc + 7).Mod12(); //circle of fifths if (!DictXYPC.ContainsKey(pc)) { DictXYPC.Add(pc, xypc); } } XYPC.Add(listx); x = 0; if (y % 2 == 0) { xpos = Space; pc = (listx[0].PC + 3).Mod12(); //minor sixth } else { xpos = HalfSpace; //starting position pc = (listx[0].PC + 8).Mod12(); //minor third } y++; ypos += Space; } //* set key Key = (P.F.MTime == null) ? new clsKeyTicks(0, "major", 0) : P.F.Keys[P.F.CurrentBBT.Ticks, kbtrans : true]; bool[] scalenotes = (Key.Major) ? NoteName.MajScaleNotes : NoteName.MinScaleNotesDown; ScaleNotes = new bool[12]; for (int i = 0; i < 12; i++) { //ScaleNotes[(i + Key.KBTrans_KeyNote).Mod12()] = scalenotes[i]; ScaleNotes[(i + Key.KeyNote).Mod12()] = scalenotes[i]; } picPC.Refresh(); }
private void Apply() { if (KeysList == null) { return; } //if (P.F == null || P.F.CF == null) { // MessageBox.Show("Apply failed - showchords/text file not loaded"); // return; //} if (P.F == null) { MessageBox.Show("Apply failed - no midifile or chordfile loaded"); return; } //P.F.UndoRedoKeys.Update(); clsKeysTicks keys = null; int index = (KeysList.Count > 1) ? GetInertia() : 0; clsKeyTicks prevkey = null; foreach (clsKeyTicks key in KeysList[index].Keys) { if (key == null) { continue; } if (key.IsEquiv(prevkey)) { continue; //same key, different BBT } clsKeyTicks newkey = new clsKeyTicks(key); //if (P.F.CFTxt.Transpose_File != 0) newkey = newkey.Transpose(-P.F.CFTxt.Transpose_File); if (keys == null) { newkey.Ticks = 0; //first key keys = new clsKeysTicks(newkey); } else { keys.Keys.Add(newkey); } prevkey = key; } //P.F.KeysAlt = keys; //SwitchKeys(); P.F._CFKeys = keys; //P.F.CF.SyncEvsToKeys(); //P.F.CF.UndoRedoCF.Update(); //P.F.CF.TransposeMidi(0); //to force enharmonic changes (spelling) P.F.CF?.SetNoteMapFileChanged(); if (P.frmSC != null) { P.frmSC.Refresh(); } if (P.F.frmChordMap != null) { P.F.frmChordMap.RefreshAll(); } }
private void PopulatelvMod(bool headers) { //* create table of key strings string[,] txt = new string[KeysList[0].Keys.Count, KeysList.Count + 1]; string[,] txtx = new string[KeysList[0].Keys.Count, KeysList.Count + 1]; for (int seg = 0; seg < KeysList[0].Keys.Count; seg++) { if (CF != null) { txt[seg, 0] = GetFileKey(seg).KeyStrShort; txtx[seg, 0] = GetFileKey(seg).KeyStrShort; } for (int i = 0; i < KeysList.Count; i++) //for each algorithm type { clsKeyTicks key = KeysList[i].Keys[seg]; if (key != null) { if (seg != key.BBT.Bar) { LogicError.Throw(eLogicError.X034); } txt[seg, i + 1] = key.KeyStrShort; txtx[seg, i + 1] = key.KeyStrShort; } } } //* replace repeated keys with "*" for (int i = 0; i < KeysList.Count + 1; i++) //txtfile and each algorithm type //for (int seg = 1; seg < KeysList[0].Keys.Count - 1; seg++) { // if (txtx[seg, i] == txtx[seg - 1, i] && txtx[seg, i] == txtx[seg + 1, i]) { // txt[seg, i] = "*"; // } //} { for (int seg = 1; seg < KeysList[0].Keys.Count; seg++) { if (txtx[seg, i] == txtx[seg - 1, i]) { txt[seg, i] = "*"; } } } //* load lvmod lvMod.BeginUpdate(); lvMod.Clear(); if (headers) { lvMod.Columns.Add("Bar", 30); foreach (string lbl in KeysLabels) { lvMod.Columns.Add(lbl, 40); } } for (int seg = 0; seg < KeysList[0].Keys.Count; seg++) { List <string> lvstr = new List <string>(); lvstr.Add((seg + 1).ToString()); //bar num lvstr.Add(txt[seg, 0]); //txt file for (int i = 0; i < KeysList.Count; i++) //for each algorithm type { lvstr.Add(txt[seg, i + 1]); } lvMod.Items.Add(new ListViewItem(lvstr.ToArray())); //add segment } lvMod.EndUpdate(); }
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; } }