private static void AppendSharpKey(StringBuilder sb, TuneElement tuneElement) { var note = tuneElement as Note; if (note != null && note.IsSharp) { sb.Append(KeyToggleSharp); } }
private static void AppendNoteOrPause(StringBuilder sb, TuneElement tuneElement) { var note = tuneElement as Note; if (note != null) { sb.Append(keypressConverter.ToString(note.Pitch)); } else if (tuneElement is Pause) { sb.Append(KeyPause); } }
private static Scales AppendScaleKey(StringBuilder sb, TuneElement tuneElement, Scales previousScale) { var note = tuneElement as Note; if (note != null && note.Scale != previousScale) { var currentScale = previousScale; do { currentScale = currentScale.Increase(); sb.Append(KeyIncreaseScale); } while (currentScale != note.Scale); previousScale = currentScale; } return(previousScale); }
protected override Tune InternalParse(string s) { var tuneElements = new List <TuneElement>(); var regex = new Regex(TuneElementPattern, RegexOptions.IgnoreCase); foreach (Match match in regex.Matches(s)) { var duration = DurationConverter.Parse(match.Groups[1].Value); TuneElement tuneElement = null; if (match.Groups[2].Value == Pause) { tuneElement = new Pause(duration); } else { var pitch = PitchConverter.Parse(match.Groups[2].Value); var scale = Scales.Four; var scaleString = match.Groups[4].Value; if (!string.IsNullOrWhiteSpace(scaleString)) { int scaleInt; if (int.TryParse(scaleString, out scaleInt)) { scale = ScaleConverter.Parse((scaleInt + OffsetScale).ToString(CultureInfo.InvariantCulture)); } } tuneElement = new Note(pitch, scale, duration); } tuneElement.Dotted = match.Groups[3].Value == Dot; tuneElements.Add(tuneElement); } return(new Tune(tuneElements)); }
private static Durations AppendDurationKey(StringBuilder sb, TuneElement tuneElement, Durations previousDuration) { if (tuneElement.Duration != previousDuration) { var currentDuration = previousDuration; do { if (currentDuration > tuneElement.Duration) { currentDuration = currentDuration.Increase(); sb.Append(KeyIncreaseDuration); } else { currentDuration = currentDuration.Decrease(); sb.Append(KeyDecreaseDuration); } } while (currentDuration != tuneElement.Duration); previousDuration = currentDuration; } return(previousDuration); }
public NokiaComposerTuneElementWithLength(TuneElement tuneElement) { TuneElement = tuneElement; }
protected override Tune InternalParse(string s) { Durations previousDuration = DefaultDuration; Scales previousScale = DefaultScale; TuneElement currentTuneElement = null; var tuneElementList = new List <TuneElement>(); var regex = new Regex(TuneElementPattern); foreach (Match item in regex.Matches(s)) { bool dotted = false; string key = string.Empty; ReadKey(item, ref dotted, ref key); if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } var currentNote = currentTuneElement as Note; switch (key) { case KeyA: case KeyB: case KeyC: case KeyD: case KeyE: case KeyF: case KeyG: if (currentTuneElement != null) { tuneElementList.Add(currentTuneElement); } var pitch = keypressConverter.Parse(key); currentTuneElement = new Note(pitch, previousScale, previousDuration); currentTuneElement.Dotted = dotted; break; case KeyPause: currentTuneElement = new Pause(previousDuration); currentTuneElement.Dotted = dotted; break; case KeyDecreaseDuration: previousDuration = previousDuration.Decrease(); currentTuneElement.Duration = previousDuration; break; case KeyIncreaseDuration: previousDuration = previousDuration.Increase(); currentTuneElement.Duration = previousDuration; break; case KeyIncreaseScale: if (currentNote != null) { currentNote.Scale = currentNote.Scale.Increase(); } break; case KeyToggleSharp: if (currentNote != null) { currentNote.ToggleSharp(); } break; default: throw new ArgumentOutOfRangeException(key); } } tuneElementList.Add(currentTuneElement); var tune = new Tune(tuneElementList); return(tune); }