internal int Tick = 0; //base0 absolute //internal clsTSig Filler; internal clsTSigBB(clsMTime mtime, int nn, int dd, int tick, clsTSigBB tsigprev, bool adj) : base(mtime, nn, dd) { //* tsignext is next tsig before any filler insert, or null Tick = tick; if (tsigprev == null) { //Index = 0; Beat = 0; Bar = 0; } else { //Index = tsigprev.Index + 1; int rem; int prevbars = Math.DivRem(Tick - tsigprev.Tick, tsigprev.TicksPerBar, out rem); if (rem != 0) { if (adj) { Tick -= rem; } else { throw new TSigException(); } } Bar = tsigprev.Bar + prevbars; Beat = tsigprev.Beat + prevbars * tsigprev.NN; } }
private clsTSig GetFillerTSig(clsMTime mtime, int ticks) { int rem; int nn = Math.DivRem(ticks * 8, TicksPerQNote, out rem); //num 32nd notes if (rem > 0) { return(null); } int dd = 32; for (; dd >= 2; dd /= 2) { //if (nn == 2) break; if (nn % 2 != 0) { break; //odd number } nn /= 2; } if (nn == 1 && dd == 2) { nn = 2; dd = 4; } //1/2 -> 2/4 else if (nn == 1 && dd == 1) { nn = 2; dd = 2; } //1/1 -> 2/2 //* may not match next tsig (e.g. 2/2 then 4/4, 3/4 then 6/8) return(new clsTSig(mtime, nn, dd)); }
internal clsTSig(clsMTime mtime, int nn, int dd) { MTime = mtime; NN = nn; DD = dd; DDMidi = (int)Math.Log(DD, 2); Txt = new clsNNDD(NN, DD).ToString(); TxtExt = NN.ToString() + '/' + DD.ToString() + " (" + MM.ToString() + ")"; switch (NN) { case 6: MM = 2; break; case 9: MM = 3; break; case 12: MM = 4; break; default: MM = NN; break; } //Tick = tick; TicksPerBeat = (4 * mtime.TicksPerQNote) / dd; TicksPerBar = TicksPerBeat * nn; MidiClocksPerBeat = 96 / DD; //24 midiclocks per quarternote MidiClocksPerBar = (96 * NN) / DD; MidiClocksPerMetClick = (96 * NN) / (DD * MM); }
internal clsBBT(clsMTime mtime, int beats, bool indbeats) { if (!indbeats) { LogicError.Throw(eLogicError.X019); } MTime = mtime; NewBBTBeat(beats); }
internal clsBBT(int beats, bool indbeats) { if (!indbeats) { LogicError.Throw(eLogicError.X018); } MTime = P.F.MTime; NewBBTBeat(beats); }
internal bool IsEquiv(clsMTime mtime) { if (TicksPerQNote != mtime.TicksPerQNote) { return(false); } ; if (!TSigs.SequenceEqual(mtime.TSigs)) { return(false); } return(true); }
internal clsBBT(clsMTime mtime, int bar, int beatrembars, int twelfth) { MTime = mtime; NewBBT(bar, beatrembars, twelfth); }
internal clsBBT(int bar, int beatrembars, int twelfth) { MTime = P.F.MTime; NewBBT(bar, beatrembars, twelfth); }
internal clsBBT(clsMTime mtime, int ticks) { MTime = mtime; NewBBT(ticks); }
internal clsBBT(int ticks) { MTime = P.F.MTime; NewBBT(ticks); }
internal clsMTime(clsMTime mtime) //copy { TicksPerQNote = mtime.TicksPerQNote; TSigs = mtime.TSigs.ToArray(); //copy }
//internal void RemoveTSig(clsBBT bbtlo, clsBBT bbthi) { // //* Validate // if (bbtlo.Bar == bbthi.Bar) return; // if (bbtlo.TicksRemBar != 0) throw new TSigException(); // if (bbthi != null && bbthi.TicksRemBar != 0) throw new TSigException(); // //* create tsig list up to selected area // List<clsTSigBB> list = new List<clsTSigBB>(); // clsTSigBB tsigprev = null; // int index = 0; // for (; index < TSigs.Length; index++) { // clsTSigBB tsig = TSigs[index]; // if (tsig.Tick >= bbtlo.Ticks) break; // list.Add(tsig); // tsigprev = tsig; // } // //* add tsigs after selected area // int ticksdiff = bbthi.Ticks - bbtlo.Ticks; // for (; index < TSigs.Length; index++) { // clsTSigBB tsig = TSigs[index]; // int ticksnext = (index < TSigs.Length - 1) ? TSigs[index + 1].Tick : P.F.MaxBBT.Ticks; // if (ticksnext <= bbthi.Ticks) continue; // int ticksnew = Math.Max(bbtlo.Ticks, tsig.Tick - ticksdiff); // tsig = new clsTSigBB(this, tsig, tsigprev, ticksnew); // list.Add(tsig); // tsigprev = tsig; // } // //* make live // TSigs = list.ToArray(); // CheckTSigs(); //} internal void ChangeTSig(int nn, int dd, clsBBT bbtlo, clsBBT bbthi) { //* Validate if (bbthi == null) { bbthi = P.F.MaxBBT.BBTCopy; } if (bbtlo.Bar == bbthi.Bar) { return; } if (bbtlo.TicksRemBar != 0) { throw new TSigException(); } if (bbthi != null && bbthi.TicksRemBar != 0) { throw new TSigException(); } //* create tsig list up to bbtlo List <clsTSigBB> list = new List <clsTSigBB>(); clsTSigBB tsigprev = null; foreach (clsTSigBB tsig in TSigs) { if (tsig.Tick >= bbtlo.Ticks) { break; } list.Add(tsig); tsigprev = tsig; } //* add new tsig clsTSigBB tsignew; try { tsignew = new clsTSigBB(this, nn, dd, bbtlo.Ticks, tsigprev, adj: false); } catch (TSigException) { return; } list.Add(tsignew); //* terminate or continue bool truncate = bbthi != null && bbthi.Bar == P.F.MaxBBT.Bar; if (bbthi == null || truncate) //truncate { TSigs = list.ToArray(); } else //insert //* set up newmtime { clsMTime newmtime = new clsMTime(TicksPerQNote, TSigs[00].NN, TSigs[0].DD); newmtime.TSigs = list.ToArray(); //up to and incl. new tsig newmtime.CheckTSigs(); //=>TSigException (should not happen) //* filler bar required? clsTSig tsigfiller = null; clsMTime.clsBBT bbttest = new clsBBT(newmtime, bbthi.Ticks); if (bbttest.TicksRemBar > 0) //need a filler bar { tsigfiller = GetFillerTSig(newmtime, bbttest.TicksRemBar); if (tsigfiller == null) { throw new TSigException(); } if (tsigfiller != null) { tsigprev = (list.Count > 0) ? list[list.Count - 1] : null; list.Add(new clsTSigBB(tsigfiller, tsigprev, bbthi.Ticks - tsigfiller.TicksPerBar)); newmtime.TSigs = list.ToArray(); } } //* add tsigs after selected area int index; clsTSigBB tsighi = FindTSigTick(bbthi.Ticks, out index); clsTSigBB newtsighi = new clsTSigBB(newmtime, tsighi, newmtime.TSigs[newmtime.TSigs.Length - 1], bbthi.Ticks); list.Add(newtsighi); for (int i = index + 1; i < TSigs.Length; i++) { clsTSigBB tsignewmtime = new clsTSigBB(newmtime, TSigs[i], list[list.Count - 1], TSigs[i].Tick); list.Add(tsignewmtime); } //* make live newmtime.TSigs = list.ToArray(); TSigs = newmtime.TSigs; } CheckTSigs(); //=>TSigException (should not happen) }
internal clsTSigBB(clsMTime mtime, clsTSig tsigbase, clsTSigBB tsigprev, int tick) : this(mtime, tsigbase.NN, tsigbase.DD, tick, tsigprev, adj : false) { }
internal void DrawBars(Font barfont, Graphics xgr, int height, bool showbeats, int hfactor, int hdiv, int bardiv, int qilo, int qihi, clsMTime mtime) { //return maxbarnum if (bardiv <= 0) { return; } Brush penbrush = new SolidBrush(Color.Black); Pen penbar = new Pen(penbrush, 2); Pen penbeat = new Pen(penbrush, 1); Pen pen; int barnum = -1; int qtimebardiv = -1; //barnum of nearest previous displayable barnum int shownum = -1; string showstring = ""; for (int beat = 0; ; beat++) { pen = penbeat; clsMTime.clsBBT bbt = new clsMTime.clsBBT(mtime, beat, true); int qtime = (bbt.Ticks * P.F.QIPerNote) / (4 * P.F.MTime.TicksPerQNote); if (qtime < qilo) { continue; } if (qtime > qihi) { break; } if (qtime > P.F.MaxBBT.QI) { break; } bool showline = true; barnum = bbt.Bar; if (bbt.BeatsRemBar == 0) //first beat { if (barnum % bardiv == 0) //barnum display option { pen = penbar; qtimebardiv = qtime; shownum = barnum + 1; } } else { if (!showbeats) { showline = false; } } if (showline) { xgr.DrawLine(pen, (qtime * hfactor) / hdiv, 0, (qtime * hfactor) / hdiv, height); } SolidBrush fontbrush = new SolidBrush(Color.Black); //default if (barfont != null && bbt.BeatsRemBar == 0 /*&& barnum % bardiv == 0*/) { //if (Pic.Name == "picNoteMapFile") { // char sectname = P.F.CF.QSections.GetName(qtime); // if (sectname != '*') { // fontbrush = new SolidBrush(P.F.CF.QSections.GetColor(sectname)); // } //} else if (Pic.Name == "pic1" || Pic.Name == "pic2") { //frmCompareNM // char name = P.F.CF.QSections.FirstBarName(bbt); // if (name != '*') showstring = name.ToString(); else showstring = ""; //} if (qtimebardiv < 0) { int barnumdiv = (barnum / bardiv) * bardiv; clsMTime.clsBBT bbtbardiv = new clsMTime.clsBBT(mtime, barnumdiv, 0, 0); qtimebardiv = (bbtbardiv.Ticks * P.F.QIPerNote) / (4 * P.F.MTime.TicksPerQNote); if (shownum < 0) { shownum = barnumdiv + 1; } } string shownumstring = (showstring == "") ? shownum.ToString() : showstring; xgr.DrawString(shownumstring, barfont, fontbrush, (qtimebardiv * hfactor) / hdiv, 0); } } }
internal void PaintMap(clsNoteMap notemap, Forms.frmTrackMap frm, Graphics xgr, int pixlo, int pixhi, clsMTime mtime) { //* frm = frmMultiMap if multimap and showing multiple octaves //* bardiv=0: don't show bars //if (Pic.Name == "picNoteMapCF") Debugger.Break(); //pixlo = 0; //pixhi = NoteMap.GetLengthQTime(); //Brush brushkb = new SolidBrush(Color.FromArgb(200, 200, 200)); Brush brushkb = P.ColorsNoteMap["Keyboard"].Br; int qilo = (pixlo * HDiv) / HFactor; int qihi = (pixhi * HDiv) / HFactor; if (qihi > P.F.MaxBBT.QI) { qihi = P.F.MaxBBT.QI; } //SetPicSize(frm); //call moved to frmMultiMap & frmNoteMap //if (!Loc.IsEmpty) Pic.Location = Loc; Pen penline = new Pen(Color.Black); if (ShowBarNumbers) { int y = BarFont.Height; xgr.DrawLine(penline, 0, y, Width, y); //start } //* draw keyboard if (ShowKB) { int hi = 12; if (!OneOct) { hi = Octaves * 12; //if (frm != null) hi = frm.Octaves[Trk] * 12; //frmMultiMap //else hi = P.F.frmNoteMap.Octaves * 12; //frmNoteMap } for (int o = 0; o < hi; o += 12) { int kbxlo = pixlo, kbxhi = pixhi; int[] offset = new int[] { 1, 3, 6, 8, 10 }; xgr.FillRectangle(brushkb, kbxlo, GetY(o + offset[0], PixPerNote), kbxhi, PixPerNote); //C# xgr.FillRectangle(brushkb, kbxlo, GetY(o + offset[1], PixPerNote), kbxhi, PixPerNote); //E- //xgr.DrawLine(penline, kbxlo, GetY(o+4), kbxhi, GetY(4)); //E|F xgr.FillRectangle(brushkb, kbxlo, GetY(o + offset[2], PixPerNote), kbxhi, PixPerNote); //F# xgr.FillRectangle(brushkb, kbxlo, GetY(o + offset[3], PixPerNote), kbxhi, PixPerNote); //G# xgr.FillRectangle(brushkb, kbxlo, GetY(o + offset[4], PixPerNote), kbxhi, PixPerNote); //B- } } //* draw notes //Color color = Color.Black; int pwval = 8192; //for (int qtime = 0; qtime < NoteMap.GetLengthQTime(); qtime++) { for (int qtime = qilo; qtime < qihi; qtime++) { //if (qtime >= notemap.GetLengthQTime()) break; if (qtime >= P.F.MaxBBT.QI) { break; } //pwval = GetPW(qilo, pwval, qtime); //if (frm != null) pwval = ((clsNoteMapMidi)notemap).PB[Trk][qtime]; if (frm != null) { pwval = ((clsNoteMapMidi)notemap).GetPB(Trk, qtime); } //if (pwval != 8192) color = Color.SkyBlue; else color = Color.Black; DrawChord(notemap, xgr, frm, pwval, qtime, HDiv, PixPerNote); } //draw bars // height was GetY(-1, pixpernote); DrawBars(BarFont, xgr, Height, ShowBeats, HFactor, HDiv, BarDivMod, qilo, qihi, mtime); }