private Pattern BuildBinaryPattern() { var builder = new PatternInfo.Builder(); builder.BarsCount = 1; builder.BeatsPerBar = 4; builder.UnitsPerBeat = new TimeInUnits(2); builder.SuggestedBpm = 60; // SN --o---o- // BS x---xx-- var sn = new SimpleSoundId("SN", "default", "*"); var bs = new SimpleSoundId("BS", "default", "*"); var result = new Pattern.Builder(); result.PatternInfo = builder.Build(); result.Add(new TimeInUnits(0), bs, Velocity.Medium); result.Add(new TimeInUnits(4), bs, Velocity.Medium); result.Add(new TimeInUnits(5), bs, Velocity.Medium); result.Add(new TimeInUnits(3), bs, Velocity.Medium); result.Add(new TimeInUnits(7), bs, Velocity.Medium); return(result.Build()); }
public static Pattern ToPattern(PatternData data) { var idToSound = new Dictionary <int, ISoundId>(); foreach (var soundData in data.Sounds) { if (idToSound.ContainsKey(soundData.Id)) { throw new PatternParsingException("Duplicate sound id: " + soundData.Id + ". Used by \"" + idToSound[soundData.Id].Name() + "\" and \"" + soundData.Instrument + "." + soundData.Technique + "\""); } idToSound.Add(soundData.Id, new SimpleSoundId(soundData.Instrument, soundData.Technique, soundData.Mark)); } var builder = new Pattern.Builder(data.Sounds.Select(i => idToSound[i.Id]).ToArray()); int index = 0; foreach (var beatData in data.Beats) { var t = new TimeInUnits(beatData.Time); ISoundId sound; if (!idToSound.TryGetValue(beatData.Sound, out sound)) { throw new PatternParsingException("Invalid instrument id for beat #" + index + "(t=" + beatData.Time + ", id=" + beatData.Sound + ")"); } builder.Add(t, sound, new Velocity(beatData.Velocity)); } var patternInfo = new PatternInfo.Builder { BarsCount = data.BarsCount, BeatsPerBar = data.BeatsPerBar, SuggestedBpm = data.SuggestedBpm, UnitsPerBeat = new TimeInUnits(data.TimeUnitsPerBeat) }; builder.PatternInfo = patternInfo.Build(); return(builder.Build()); }