private int MapNote(clsChordEvTimed nextplaychord, eDir dir, int i) { int mindiffpos = 99, mindiffposj = -1; int mindiffneg = 99, mindiffnegj = -1; int diff = -999; int j; //* calculate min interval (diff) up and down (pos/neg) for each note of next chord for (j = 0; j < nextplaychord.Chord.Length; j++) //for each note in next 3,4 note chord { diff = GetDiff(Chord[i], nextplaychord.Chord[j]); //positive if 2nd param highest if (diff == 0) //ignore dir - always choose if same note //nextnote[Chord[i]] = nextplaychord.Chord[j]; { break; } else if (diff > 0 && mindiffpos > diff) //next is up { mindiffpos = diff; mindiffposj = j; } else if (diff < 0 && mindiffneg > -diff) //next is down { mindiffneg = -diff; mindiffnegj = j; } } //* determine up true/false based on mindiffneg/pos and required direction (Dir) bool up = true; //true if mindiffpos is to be used (else mindiffneg) if (diff != 0) { switch (dir) { case eDir.Null: //choose min interval up = (mindiffneg >= mindiffpos); break; case eDir.UpSoft: //use smallest interval - up if equal up = (mindiffneg >= mindiffpos); break; case eDir.DownSoft: //use smallest interval - down if equal up = (mindiffneg > mindiffpos); break; case eDir.UpHard: //always go up (if not same note) up = true; break; case eDir.DownHard: //always go down (if not same note) up = false; break; default: LogicError.Throw(eLogicError.X029); up = true; break; } } //* calculate mindiffj int mindiffj; if (diff == 0) { mindiffj = j; } else if (mindiffposj == -1) { mindiffj = mindiffnegj; } else if (mindiffnegj == -1) { mindiffj = mindiffposj; } else if (up) { mindiffj = mindiffposj; } else { mindiffj = mindiffnegj; } return(nextplaychord.Chord[mindiffj]); }
/* * private void ShowText(string text) { * P.F.frmShowChords.lblTest.Text = text; * P.F.frmShowChords.lblTest.Refresh(); * } */ /* private static int MapNext_TextCount = 0; //for testing */ internal void MapNext(clsChordEvTimed nextplaychord, int pitch, int kb, int callcount) { //* create kbmap from this ((previous) playchord) //* select nearest notes //* pitch and key used by GetDir to calculate mapping for hypothetical chord (size = chordsize) if (nextplaychord.Status == eStatus.Play) { return; } /* bool initial = false; //temp (testing) */ if (pitch < 0 || kb < 0) //initial (called from paint event) { if (nextplaychord.Status != eStatus.Initial) { return; //initial - already done } pitch = PitchMid; kb = KBMid; /* initial = true; //temp testing */ } eDir dir = GetDir(pitch, kb); #if Debug string text = ""; if (dir == eDir.Null) { text = "Null"; } else if (dir == eDir.DownSoft) { text = "down"; } else if (dir == eDir.UpSoft) { text = "up"; } else if (dir == eDir.DownHard) { text = "DOWN"; } else if (dir == eDir.UpHard) { text = "UP"; } if (!initial) { P.F.frmShowChords.BeginInvoke(dShowText, text + ++MapNext_TextCount); } #endif nextplaychord.InitKBMap(); int[] nextnote = new int[12]; //nextnote[thischordnote%12] = nextchordnote%12 for (int i = 0; i < 12; i++) { nextnote[i] = -99; } for (int i = 0; i < Chord.Length; i++) //for each note in this 3,4 note chord { nextnote[Chord[i]] = MapNote(nextplaychord, dir, i); } //* calculate KBMap from nextnote[] for (int k = KBLo; k <= KBHi; k++) { nextplaychord.KBMap[k] = SetKBMap(nextnote, k); } nextplaychord.Status = eStatus.Preplay; }