public LoopDurationInfo CalculateDuration(int previousCommandDuration) { var loopDurationInfo = new LoopDurationInfo(); int totalDuration = 0; int duration = previousCommandDuration; int startTime = 0; foreach (var c in this.LoopPart.Commands) { if (c is DurationCommand) { duration = c.Command; loopDurationInfo.LoopLastDurationChange = duration; } if (c is NoteCommand) { // this is rediculous. I hope that loops that are reused all have the same duration going into them if they start with notes... c.StartTime = startTime; c.Duration = duration; startTime += duration; totalDuration += duration; } } loopDurationInfo.LoopDuration = totalDuration; return(loopDurationInfo); }
public void FixDurations() { int currentTime = 0; int currentDuration = 0; foreach (var c in Commands) { c.StartTime = currentTime; if (c is DurationCommand) { currentDuration = c.Command; } if (c is NoteCommand) { c.Duration = currentDuration; currentTime += currentDuration; } if (c is CallLoopCommand) { var loop = c as CallLoopCommand; var loopDuration = new LoopDurationInfo(); for (int i = 0; i < loop.LoopCount; ++i) { loopDuration = loop.CalculateDuration(currentDuration); } currentDuration = loopDuration.LoopLastDurationChange; loop.Duration = loopDuration.LoopDuration; currentTime += loopDuration.LoopDuration * loop.LoopCount; } } EndTime = currentTime; }