public void StemDirectionTest() { var chord = new ChordSection(new List <NoteViewModel>() { new NoteViewModel(Notes.C1), new NoteViewModel(Notes.E1), new NoteViewModel(Notes.G1), }); Assert.That(chord.MajorityRelation(Clef.Bass), Is.EqualTo(Relation.Lower)); chord = new ChordSection(new List <NoteViewModel>() { new NoteViewModel(Notes.D2), new NoteViewModel(Notes.F2), new NoteViewModel(Notes.A3), }); Assert.That(chord.MajorityRelation(Clef.Bass), Is.EqualTo(Relation.Higher)); chord = new ChordSection(new List <NoteViewModel>() { new NoteViewModel(Notes.B2), new NoteViewModel(Notes.D2), new NoteViewModel(Notes.F2), }); Assert.That(chord.MajorityRelation(Clef.Bass), Is.EqualTo(Relation.Equal)); }
public void AddSection(NoteSection section, int left) { var notesInSection = new List <NoteViewModel>(); foreach (var note in section.AllNotes.OrderBy(x => x.Id)) { var currentNoteY = NotesIndexInClef(note); var newNote = CreateNoteAtIndex(note, left, currentNoteY); _createdNotes.Add(newNote); notesInSection.Add(newNote); } if (notesInSection.Count > 1) { var chord = new ChordSection(notesInSection); Sections.Add(chord); CorrectPositionsOfChordNotes(chord); } else { Sections.Add(new NoteSection(notesInSection)); } AddLedgerLines(Sections.Last(), left); AddNoteStems(Sections.Last()); }
private bool ChordIsOutsideStaff(Clef clef, ChordSection chord) { var high = chord.Highest(clef); var low = chord.Lowest(clef); var indexes = new List <int>() { NotesIndexInClef(high.Note), NotesIndexInClef(low.Note) }; //TODO yes this does make notes say C1 and C3 would return true, but hey that will never happen, we can assume that a chord will never have notes on opposite sides of the stem var isInsideStaff = indexes.Any(x => !IsOutsideLedger(x)); return(!isInsideStaff); }
public void HasIntervalTests() { var chord = new ChordSection(new List <NoteViewModel>() { new NoteViewModel(Notes.C2), // new NoteViewModel(Notes.D2), //Second new NoteViewModel(Notes.C1), //Octave }); Assert.That(chord.HasInterval(ChordSection.Interval.Second, Clef.Bass), Is.True); Assert.That(chord.HasInterval(ChordSection.Interval.Fifth, Clef.Bass), Is.False); Assert.That(chord.HasInterval(ChordSection.Interval.Octave, Clef.Bass), Is.True); }
public void ChordTests() { var chord = new ChordSection(new List <NoteViewModel>() { new NoteViewModel(Notes.C2), new NoteViewModel(Notes.C1), new NoteViewModel(Notes.D2), }); Assert.That(chord.Lowest(Clef.Bass).Note, Is.EqualTo(Notes.C1)); Assert.That(chord.Highest(Clef.Treble).Note, Is.EqualTo(Notes.D2)); Assert.That(chord.Highest(Clef.Bass).Note, Is.EqualTo(Notes.D2)); }
private void CorrectPositionsOfChordNotes(ChordSection chord) { if (chord.HasInterval(ChordSection.Interval.Second, ActiveClef)) { var first = chord.FirstNoteInSecond(ActiveClef); var notesFromBottom = chord.Notes.OrderBy(x => Notes.NotesInClef(ActiveClef).IndexOf(x.Note)).ToList(); var idx = notesFromBottom.IndexOf(first); var snd = notesFromBottom[(idx + 1) % chord.Notes.Count]; snd.X += NudgeWidth; notesFromBottom.Remove(snd); notesFromBottom.Remove(first); var amountToDisplace = idx > 0 ? NudgeWidth : 0; foreach (var note in notesFromBottom) { note.X += amountToDisplace; } } }
public List <NoteSection> GetNoteSections() { if (FavorChords) { return(CreateLinearChordSection()); } return(CreateRandomSections(_length)); return(new List <NoteSection>() { //Top and bottom 2nd chords ChordSection.Build(Notes.A1, Notes.B1), ChordSection.Build(Notes.G2, Notes.A3), ChordSection.Build(Notes.E2, Notes.F2), ChordSection.Build(Notes.E1, Notes.F1), //Triads spanning the clef ChordSection.Build(Notes.A2, Notes.C2, Notes.E2), ChordSection.Build(Notes.A2, Notes.C2, Notes.E2).Transpose(2), ChordSection.Build(Notes.A2, Notes.C2, Notes.E2).Transpose(4), ChordSection.Build(Notes.A2, Notes.C2, Notes.E2).Transpose(6), ChordSection.Build(Notes.A2, Notes.C2, Notes.E2).Transpose(-2), ChordSection.Build(Notes.A2, Notes.C2, Notes.E2).Transpose(-4), ChordSection.Build(Notes.A2, Notes.C2, Notes.E2).Transpose(-6), //Fifths ChordSection.Build(Notes.C2, Notes.G2), ChordSection.Build(Notes.C2, Notes.G2).Transpose(-1), ChordSection.Build(Notes.C2, Notes.G2).Transpose(-2), ChordSection.Build(Notes.C2, Notes.G2).Transpose(-4), //Triads with 2nd ChordSection.Build(Notes.A1, Notes.B1, Notes.G1), ChordSection.Build(Notes.A1, Notes.B1, Notes.G1).Transpose(4), ChordSection.Build(Notes.G2, Notes.A3, Notes.C2), }); }
private void AddNoteStems(ChordSection chord) { var stem = CreateStemForChord(chord); var outerNote = stem.StemDirection == Stem.Direction.Down ? chord.Lowest(ActiveClef) : chord.Highest(ActiveClef); var connectingNote = stem.StemDirection == Stem.Direction.Down ? chord.Highest(ActiveClef) : chord.Lowest(ActiveClef); //TODO fix, this fixes offset when stem is going upp ,which causes it to reach to far since it starts at top of note int GetHeightCorrectedWithOffset(Stem xstem) { var idx = xstem.StemDirection == Stem.Direction.Down ? 8 : 6; return(idx * NoteHeight); } if (chord.HasInterval(ChordSection.Interval.Second, ActiveClef)) { connectingNote.StemX = chord.FirstNoteInSecond(ActiveClef).X + stem.PosX(); } else { connectingNote.StemX = connectingNote.X + stem.PosX(); } connectingNote.StemY = connectingNote.Y + stem.Start(); connectingNote.StemEnd = outerNote.Y; outerNote.StemX = connectingNote.StemX; outerNote.StemY = outerNote.Y; var length = Math.Abs(NotesIndexInClef(outerNote.Note)) > 5 ? 3 * NoteHeight : GetHeightCorrectedWithOffset(stem); if (ChordIsOutsideStaff(ActiveClef, chord)) { var idx = Math.Abs(NotesIndexInClef(outerNote.Note) - 1); length = idx * NoteHeight; } outerNote.StemEnd = outerNote.StemY + (stem.StemDirection == Stem.Direction.Down ? length : -length); }
private Stem CreateStemForChord(ChordSection chord) { var stem = new Stem(); if (chord.EqualFromMid(ActiveClef)) { stem.StemDirection = Stem.Direction.Down; } else { stem.StemDirection = chord.MajorityRelation(ActiveClef) == Relation.Lower ? Stem.Direction.Up : Stem.Direction.Down; } if (chord.HasInterval(ChordSection.Interval.Second, ActiveClef)) { stem.HorizontalOrientaion = Stem.Horizontal.Mid; } else { stem.HorizontalOrientaion = stem.StemDirection == Stem.Direction.Down ? Stem.Horizontal.Left : Stem.Horizontal.Right; } return(stem); }