//Chooses the string based off nothing but pitch, prefers higher string static void ChooseStringBasic(TabStaff tab, Note note) { int pitch = note.Pitch; if (pitch < 40) //unplayable on a 4-string bass { tab.AddNote("#", "#", "#", "#"); } else if (pitch <= 45) { note.Fret = pitch - 40; note.Str = _String.E; } else if (pitch <= 51) { note.Fret = pitch - 45; note.Str = _String.A; } else if (pitch <= 57) { note.Fret = pitch - 50; note.Str = _String.D; } else { note.Fret = pitch - 55; note.Str = _String.G; } tab.AddNote(note); }
//Write the captured list of notes out as a TabStaff object, and then write to file static void WriteTabs(string out_path) { StreamWriter sw = new StreamWriter(out_path); Note prevNote = notes.First(); TabStaff tab = new TabStaff(); foreach (Note note in notes) { //write note into the tab. int restSpace = (note.Time - prevNote.Time) / 3 - 2; if (tab.E.Length + restSpace > MaxStaffLength) { tab.EndStaff(); sw.Write(tab.ToString()); tab = new TabStaff(); } tab.AddRest(restSpace); //ChooseStringBasic(tab, note); ThreeFretSameString(tab, note, prevNote); prevNote = note; } tab.EndStaff(); sw.WriteLine(tab.ToString()); sw.Close(); }
//More than 3 fret difference forces change of string (returning the fret used) static void ThreeFretSameString(TabStaff tab, Note curNote, Note prevNote) { //choose the string / fret combination based off the prevNote's string / fret. if (curNote.Pitch == 40) { curNote.Fret = 0; curNote.Str = _String.E; } else if (curNote.Pitch < prevNote.Pitch && curNote.Pitch == 45) { curNote.Fret = 0; curNote.Str = _String.A; } else if (Math.Abs(curNote.Pitch - prevNote.Pitch) < 3) { curNote.Str = prevNote.Str; curNote.Fret = FindFret(curNote.Str, curNote.Pitch); tab.AddNote(curNote); } else { ChooseStringBasic(tab, curNote); } }