| using System;
using System.Collections.Generic;
public class ParallelMusicElement: MusicElement{
private List<MusicElement> elements;
public ParallelMusicElement(MusicElement[] elements){
this.elements = new List<MusicElement>(elements);
}
// Factory method:
public static MusicElement
MakeParallelMusicElement(params MusicElement[] elements){
return new ParallelMusicElement(elements);
}
public override TimedNote[] Linearize(int startTime){
int time = startTime;
List<TimedNote> result = new List<TimedNote>();
foreach(MusicElement me in elements){
result.AddRange(me.Linearize(time));
time = startTime;
}
return result.ToArray();
}
public override int Duration{
get{
int result = 0;
foreach(MusicElement me in elements){
result = Math.Max(result, me.Duration);
}
return result;
}
}
public override MusicElement Transpose(int levels){
List<MusicElement> transposedElements = new List<MusicElement>();
foreach(MusicElement me in elements)
transposedElements.Add(me.Transpose(levels));
return new ParallelMusicElement(transposedElements.ToArray());
}
} |