public static StringTuning GetTuningForNote(MusicalNote note, Temperament temperament) { MusicalNote newNote; switch (temperament) { default: case Temperament.Equal: newNote = MusicalNote.EqualNote(note.NoteName, note.Octave); break; case Temperament.Just: newNote = MusicalNote.JustNote(note.NoteName, note.Octave); break; } var offset = new PitchValue(); if (temperament == Temperament.ThidellFormula) { offset = PitchValue.FromCents(NoteConverter.ThidellFormulaChromaticOffsets[(int)newNote.NoteName]); //if (newNote.NoteName == NoteName.E && newNote.Octave == 2) // offset = PitchValue.FromCents(-2); //else if (newNote.NoteName == NoteName.D && newNote.Octave == 3) // offset = PitchValue.FromCents(2); //else if (newNote.NoteName == NoteName.G && newNote.Octave == 3) // offset = PitchValue.FromCents(4); //else if (newNote.NoteName == NoteName.B && newNote.Octave == 3) // offset = PitchValue.FromCents(-1); if (newNote.NoteName == NoteName.E && newNote.Octave == 4) { offset = PitchValue.FromCents(-1); } } else if (temperament == Temperament.DieWohltemperirte) { offset = PitchValue.FromCents(NoteConverter.DieWohltemperirteChromaticOffsets[(int)newNote.NoteName]); //if (newNote.NoteName == NoteName.E && newNote.Octave == 2) // offset = PitchValue.FromCents(-2); //else if (newNote.NoteName == NoteName.D && newNote.Octave == 3) // offset = PitchValue.FromCents(2); //else if (newNote.NoteName == NoteName.G && newNote.Octave == 3) // offset = PitchValue.FromCents(3.9); //else if (newNote.NoteName == NoteName.E && newNote.Octave == 4) // offset = PitchValue.FromCents(-2); } return(new StringTuning(newNote, offset)); }
public static StringTuning Deserialize(XElement elem) { var tuning = new StringTuning( MusicalNote.CreateNote( //(NoteName)Enum.Parse(typeof(NoteName), elem.Attribute("Note").Value), //elem.GetIntAttribute("Octave"), //(IntonationMethod)Enum.Parse(typeof(IntonationMethod), elem.Attribute("Intonation").Value) elem.ReadAttribute("Note", NoteName.C), elem.ReadAttribute("Octave", 4), elem.ReadAttribute("Intonation", IntonationMethod.EqualTempered) ) ); tuning.PitchOffset = PitchValue.FromCents(elem.ReadAttribute("CentsOffset", 0d)); //if (elem.HasAttribute("CentsOffset", out XAttribute centsAttr)) // tuning.PitchOffset = PitchValue.FromCents(double.Parse(centsAttr.Value)); return(tuning); }