public static List <MIDNote> GetNotesFromChord(MIDNote n, List <Event> notes) { var chord = new List <MIDNote> { n }; var index = notes.IndexOf(n); for (var i = index + 1; i < notes.Count; i++) { var n2 = notes[i] as MIDNote; if (n2 != null && notes[i].tick - n.tick == 0) { chord.Add(n2); } if (n2 != null && notes[i].tick - n.tick != 0) { break; } } for (var i = index - 1; i >= 0; i--) { var n2 = notes[i] as MIDNote; if (n2 != null && notes[i].tick - n.tick == 0) { chord.Add(n2); } if (n2 != null && notes[i].tick - n.tick != 0) { break; } } return(chord); }
private static bool IsChord(MIDNote n, List <Event> notes) { var index = notes.IndexOf(n); if (index == 0) { for (var i = 1; i < notes.Count; i++) { var n2 = notes[i] as MIDNote; if (n2 != null) { return(notes[i].tick - n.tick == 0); } } } if (index == notes.Count - 1) { for (var i = notes.Count - 2; i >= 0; i--) { var n2 = notes[i] as MIDNote; if (n2 != null) { return(notes[i].tick - n.tick == 0); } } } bool check = false; for (var i = index + 1; i < notes.Count; i++) { var n2 = notes[i] as MIDNote; if (n2 != null && notes[i].tick - n.tick == 0) { check = true; } if (n2 != null && notes[i].tick - n.tick != 0) { break; } } if (check) { return(check); } for (var i = index - 1; i >= 0; i--) { var n2 = notes[i] as MIDNote; if (n2 != null && notes[i].tick - n.tick == 0) { check = true; } if (n2 != null && notes[i].tick - n.tick != 0) { break; } } return(check); }
private bool IsPartOfBrokenChord(MIDNote n, List <Event> notes) { if (n == null) { return(false); } if (notes[0] == n) { return(false); } var previousNote = GetPreviousNote(n, notes); return(previousNote != null && previousNote.tick != n.tick && previousNote.tick + previousNote.sus > n.tick); }
public static MIDNote GetNextNote(MIDNote n, List <Event> notes) { if (notes[notes.Count - 1] == n) { return(null); } for (var i = notes.IndexOf(n) + 1; i < notes.Count; i++) { var previousNote = notes[i] as MIDNote; if (previousNote != null && n.tick - previousNote.tick != 0) { return(notes[i] as MIDNote); } } return(null); }
public static MIDNote GetPreviousNote(MIDNote n, List <Event> notes) { if (notes[0] == n) { return(null); } for (var i = notes.IndexOf(n) - 1; i >= 0; i--) { var previousNote = notes[i] as MIDNote; if (previousNote != null && n.tick - previousNote.tick != 0) { return(notes[i] as MIDNote); } } return(null); }
private static long GetNextNoteDiff(MIDNote n, List <Event> notes) { if (notes.IndexOf(n) == notes.Count - 1) { return(1); } for (int i = notes.IndexOf(n) + 1; i < notes.Count; i++) { var nextNote = notes[i] as MIDNote; if (nextNote != null) { return(notes[i].tick - n.tick); } } return(1); }
private static bool SameNoteAsPrevious(MIDNote n, List <Event> notes, List <NoteSection> openNotes) { if (notes.IndexOf(n) == 0) { return(false); } for (int i = notes.IndexOf(n) - 1; i >= 0; i--) { var n2 = notes[i] as MIDNote; if (n2 != null) { return(!IsChord(n2, notes) && n2.note == n.note); } } return(false); }
private static bool IsTap(MIDNote n, List <NoteSection> tap) { bool check = false; foreach (NoteSection t in tap) { if (t.tick > n.tick) { break; } if (n.tick >= t.tick && n.tick < (t.tick + t.sus)) { check = true; break; } } return(check); }
private static long GetPreviousNoteDiff(MIDNote n, List <Event> notes) { if (notes[0] == n) { return(192); } else { for (int i = notes.IndexOf(n) - 1; i >= 0; i--) { var previousNote = notes[i] as MIDNote; if (previousNote != null && n.tick - previousNote.tick != 0) { return(n.tick - previousNote.tick); } } } return(192); }
private static bool IsForcedKeys(MIDNote n, List <Event> notes) { var tickDiff = GetPreviousNoteDiff(n, notes); if (tickDiff > hopoThresh) { return(false); } if (!IsChord(n, notes) && ContainsNoteFromPreviousChord(n, notes)) { return(true); } if (!IsChord(n, notes)) { return(false); } return(!SameChordAsPrevious(n, notes)); }
private static bool ContainsNoteFromPreviousChord(MIDNote n, List <Event> notes) { var previousChord = new List <MIDNote>(); MIDNote previousNote = null; for (var i = notes.IndexOf(n) - 1; i >= 0; i--) { previousNote = notes[i] as MIDNote; if (previousNote != null) { break; } } if (!IsChord(previousNote, notes)) { return(false); } previousChord = GetNotesFromChord(previousNote, notes); /*while(true) { * if (notes.IndexOf(previousNote) == 0) * break; * if (previousNote != null && previousNote.tick-notes[(notes.IndexOf(previousNote)-1)].tick != 0) * break; * previousNote = notes[(notes.IndexOf(previousNote)-1)] as Note; * if (previousNote != null) * previousChord.Add(previousNote); * }*/ foreach (var n2 in previousChord) { if (n2.note == n.note) { return(true); } } return(false); }
private List <Event> FixBrokenChords(List <Event> notes, int sec) { var fixedNotes = new List <Event>(); foreach (var n in notes) { fixedNotes.Add(n); if (IsPartOfBrokenChord(n as MIDNote, fixedNotes)) { var previousNote = GetPreviousNote(n as MIDNote, fixedNotes); var previousIndex = fixedNotes.IndexOf(previousNote); var previousTick = previousNote.tick; for (var j = previousIndex; j >= 0; j--, previousNote = fixedNotes[j] as MIDNote) { //j >= 0 && previousNote.tick == previousTick; - old code incase something goes unexpectedly wrong if (previousNote != null) { if (previousNote.tick != previousTick) { break; } var tickDiff = n.tick - previousNote.tick; if (tickDiff < 96L) { tickDiff = 0; } fixedNotes[j] = new MIDNote(previousNote.note, previousNote.tick, tickDiff); fixedNotes.Add(new MIDNote(previousNote.note, n.tick, n.sus)); if (n.tick - previousTick <= 64) { switch (sec) { case 0: xGuitarForceHOPO = AddForceHopoIfNecessary(n.tick, xGuitarForceHOPO, xGuitarForceStrum); break; case 1: hGuitarForceHOPO = AddForceHopoIfNecessary(n.tick, hGuitarForceHOPO, hGuitarForceStrum); break; case 2: mGuitarForceHOPO = AddForceHopoIfNecessary(n.tick, mGuitarForceHOPO, mGuitarForceStrum); break; case 3: eGuitarForceHOPO = AddForceHopoIfNecessary(n.tick, eGuitarForceHOPO, eGuitarForceStrum); break; case 4: xBassForceHOPO = AddForceHopoIfNecessary(n.tick, xBassForceHOPO, xBassForceStrum); break; case 5: hBassForceHOPO = AddForceHopoIfNecessary(n.tick, hBassForceHOPO, hBassForceStrum); break; case 6: mBassForceHOPO = AddForceHopoIfNecessary(n.tick, mBassForceHOPO, mBassForceStrum); break; case 7: eBassForceHOPO = AddForceHopoIfNecessary(n.tick, eBassForceHOPO, eBassForceStrum); break; case 8: break; default: throw new Exception("Invalid diff/instr. value(smaller than 0 or greater than 8)"); } } if (previousNote.tick != previousTick) { break; } } if (j == 0) { break; } } } } return(fixedNotes); }
private static bool SameChordAsPrevious(MIDNote n, List <Event> notes) { if (!IsChord(n, notes)) { return(false); } var previousNote = new MIDNote(0, -1, 0); for (var i = notes.IndexOf(n) - 1; i >= 0; i--) { previousNote = notes[i] as MIDNote; if (previousNote != null && n.tick - previousNote.tick != 0) { break; } } if (!IsChord(previousNote, notes)) { return(false); } //if the current note isnt a chord it returns false //else it looks for the previous note - if it also isnt a chord, it returns false again var currentChord = GetNotesFromChord(n, notes); var previousChord = GetNotesFromChord(previousNote, notes); if (currentChord.Count != previousChord.Count) { return(false); } //it gets the respective chords and compares their length - if they dont match they cannot be the same chord var count = currentChord.Count; //OLD CODE, LEAVING THIS INCASE NEW ONE FAILS /*bool[] check1 = new bool[count], check2 = new bool[count]; * for (var i = 0; i < count; i++) { * for (var j = 0; j < count; j++) { * if (check2[j]) break; * if (currentChord[i].note == previousChord[j].note) { * check1[i] = true; check2[j] = true; break; * } * } * if (!check1[i]) return false; * } * //tries to find the note from the current chord in the previous chord. * //stores whether it's been found or not in 2 arrays (one for each chord). * //if the notes match somewhere both their positions are marked as true on their respective arrays * for (var i = 0; i < count; i++) * if (!check1[i] || !check2[i]) return false; * //checks if ALL of the notes were found - if they werent then they arent the same chord * //if it didnt fail until here then it means both chords are the same*/ for (var i = 0; i < count; i++) { if (currentChord[i].note != previousChord[i].note) { return(false); } } return(true); }
bool IsForced(MIDNote n, List <Event> notes, List <NoteSection> forceHOPO, List <NoteSection> forceStrum, List <NoteSection> openNotes) { bool check = false; long tickDiff = GetPreviousNoteDiff(n, notes); if (tickDiff <= hopoThresh && !IsChord(n, notes) && !SameNoteAsPrevious(n, notes, openNotes)) { if ((ContainsNoteFromPreviousChord(n, notes)) || (IsTap(n, openNotes))) { //applies harmonix's post-chord ho/po logic //this means that this note contains a note from the previous chord //therefore it's a strum, unless it's forced otherwise //so, look on forceHOPO //also works when forcing open notes as strum by default //unless forced otherwise ofc check = true; foreach (var hopo in forceHOPO) { if (hopo.tick > n.tick) { break; } if (n.tick >= hopo.tick && n.tick < (hopo.tick + hopo.sus)) { check = false; break; } } } else { //regular HOPO - look on forceStrum foreach (var s in forceStrum) { if (s.tick > n.tick) { break; } if (n.tick >= s.tick && n.tick < (s.tick + s.sus)) { check = true; break; } } } if ((tickDiff > 64 && tickDiff <= 96)) { check = !check; } } else /*if (tickDiff > hopoThresh || IsChord(n, notes) || SameNoteAsPrevious(n, notes))*/ { //not HOPO - look on forceHOPO foreach (var hopo in forceHOPO) { if (hopo.tick > n.tick) { break; } if (n.tick >= hopo.tick && n.tick < (hopo.tick + hopo.sus)) { check = true; if ((SameNoteAsPrevious(n, notes, openNotes) || SameChordAsPrevious(n, notes))) { check = false; break; } if (IsChord(n, notes)) { check = false; } break; } } if ((tickDiff > 32 && tickDiff <= 64) && !IsChord(n, notes) && !SameNoteAsPrevious(n, notes, openNotes)) { check = !check; } } return(check); }