public TimeSignature(string input) { var parts = input.Split("/"); if (int.TryParse(parts[0], out var top) && int.TryParse(parts[1], out var bottom)) { Top = top; Bottom = bottom; if (Top % 3 == 0 && (Bottom > 4 || Top > 3)) { MeterType = MeterType.Compound; Beats = Top / 3; var subBeat = Durations.All().FirstOrDefault(d => d.TimeSymbol == bottom && d.Dots == 0); BeatDuration = Durations.All().FirstOrDefault(d => d.CommonTimeBeatLength == (subBeat.CommonTimeBeatLength * 3)); } else if (Top % 2 == 1) { MeterType = MeterType.Mixed; Beats = ((Top % 3) / 2) + (Top / 3); BeatDuration = null; } else { MeterType = MeterType.Simple; Beats = Top; BeatDuration = Durations.All().FirstOrDefault(d => d.TimeSymbol == bottom && d.Dots == 0); } } else { throw new UnrecognizedTimeSignatureException(); } }
public TimeSignature(int top, int bottom) { try { Top = top; Bottom = bottom; if (Top % 3 == 0 && (Bottom > 4 || Top > 3)) { MeterType = MeterType.Compound; Beats = Top / 3; var subBeat = Durations.All().FirstOrDefault(d => d.TimeSymbol == bottom && d.Dots == 0); BeatDuration = Durations.All().FirstOrDefault(d => d.CommonTimeBeatLength == (subBeat.CommonTimeBeatLength * 3)); } else if (Top % 2 == 1) { MeterType = MeterType.Mixed; Beats = ((Top % 3) / 2) + (Top / 3); BeatDuration = null; } else { MeterType = MeterType.Simple; Beats = Top; BeatDuration = Durations.All().FirstOrDefault(d => d.TimeSymbol == bottom && d.Dots == 0); } } catch { throw new UnknownTimeSignatureException(); } }