private static RhythmSegmentVoice InstantializeVoice(RhythmSegmentVoice voice) { var instance = voice.Clone(); instance.ClearRange(); return(instance); }
public bool ValueEquals(RhythmSegmentVoice other) { if (other == null) { return(false); } return(other.Beats.Count == this.Beats.Count && this.Beats.Where((b, i) => !b.ValueEquals(other.Beats[i])).Any()); }
public bool ToDocumentElement(TablatureContext context, ILogger logger, VoicePart voicePart, out RhythmSegmentVoice voice) { voice = new RhythmSegmentVoice(voicePart) { Range = this.Range }; context.CurrentVoice = voice; foreach (var beat in this.Beats) { Beat documentBeat; if (!beat.ToDocumentElement(context, logger, voice, out documentBeat)) { return(false); } voice.Beats.Add(documentBeat); } // try to fill voice with rests if insufficient notes fed var duration = this.GetDuration(); if (duration < this.ExpectedDuration) { BaseNoteValue[] factors; if (!BaseNoteValues.TryFactorize(this.ExpectedDuration - duration, out factors)) { logger.Report(LogLevel.Error, this.Range, Messages.Error_InconsistentVoiceDurationCannotBeFilledWithRest); return(false); } logger.Report(LogLevel.Suggestion, this.Range, Messages.Suggestion_InconsistentVoiceDuration); foreach (var factor in factors) { var beat = new Beat() { NoteValue = new NoteValue(factor), IsRest = true, Notes = new BeatNote[0] }; context.CurrentVoice.IsTerminatedWithRest = true; voice.Beats.Add(beat); } } return(true); }
private void ArrangeBeatsAndNotes(RhythmSegmentVoice voice) { foreach (var beat in voice.Beats) { var previousBeat = _previousBeats[voice.Part]; if (previousBeat != null) { previousBeat.NextBeat = beat; beat.PreviousBeat = previousBeat; } _previousBeats[voice.Part] = beat; } }
public bool ToDocumentElement(TablatureContext context, ILogger logger, RhythmSegmentVoice ownerVoice, out Beat beat) { beat = new Beat() { Range = this.Range, StrumTechnique = this.StrumTechnique?.Value ?? (StrumTechniqueEnum?)this.ChordStrumTechnique?.Value ?? StrumTechniqueEnum.None, Accent = this.Accent?.Value ?? Core.MusicTheory.BeatAccent.Normal, HoldAndPause = this.HoldAndPause?.Value ?? Core.MusicTheory.HoldAndPause.None, Ornament = this.Ornament?.Value ?? Core.MusicTheory.Ornament.None, NoteRepetition = this.NoteRepetition?.Value ?? Core.MusicTheory.NoteRepetition.None, EffectTechniqueParameter = this.OrnamentParameter?.Value ?? default(double), IsRest = this.Rest != null, IsTied = this.Tie != null, TiePosition = this.TiePosition?.Value, PreConnection = this.PreConnection?.Value ?? PreBeatConnection.None, PostConnection = this.PostConnection?.Value ?? PostBeatConnection.None, NoteValue = this.NoteValue.ToNoteValue(), VoicePart = ownerVoice.Part, IsForceBeamStart = this.ForceBeamStart != null, IsForceBeamEnd = this.ForceBeamEnd != null }; if (!this.Validate(context, logger, beat)) { return(false); } var notes = new List <BeatNote>(); foreach (var note in this.Notes) { BeatNote documentNote; if (!note.ToDocumentElement(context, logger, ownerVoice.Part, out documentNote)) { return(false); } documentNote.OwnerBeat = beat; notes.Add(documentNote); ownerVoice.LastNoteOnStrings[documentNote.String] = documentNote; } beat.Notes = notes.ToArray(); ownerVoice.IsTerminatedWithRest = beat.IsRest; return(true); }
private void AppendAndArrangeVoice(RhythmSegmentVoice voice, BeatArranger beatArranger) { if (voice == null) { return; } foreach (var beat in voice.Beats) { beatArranger.AddBeat(beat); } var barVoice = _bar.GetVoice(voice.Part); voice.LastNoteOnStrings.CopyTo(barVoice.LastNoteOnStrings, 0); barVoice.IsTerminatedWithRest = voice.IsTerminatedWithRest; }
private void CreateArrangedBarBeats(ICollection <Beat> beats, RhythmSegmentVoice voice) { if (voice == null) { return; // todo: insert rest? } if (voice.Beats.Count == 0) { // todo: insert rest? } var position = PreciseDuration.Zero; foreach (var beat in voice.Beats) { beat.Position = position; beats.Add(beat); position += beat.GetDuration(); } }