public async static Task <MidiPlayer> LoadConfig(MidiConfig config, StepperMotor[] motors, bool fillParts) { if (config == null) { return(null); } MidiPlayer midiPlayer = new MidiPlayer(); midiPlayer.Config = config; MidiTrackPlayer[] midiTracks = new MidiTrackPlayer[motors.Length]; int partNum = 0; for (int i = 0; i < motors.Length; i++) { midiTracks[i] = new MidiTrackPlayer(motors[i]); if (partNum >= config.TrackXmlPaths.Length) { if (fillParts) { partNum = 0; } else { break; } } if (config.TrackXmlPaths[partNum] != null) { await midiTracks[i].LoadMidiTrack(config.TrackXmlPaths[partNum]); midiPlayer.Tracks.Add(midiTracks[i]); if (partNum < config.OctaveOffsets.Length) { motors[i].OctaveOffset = midiTracks[i].OctaveOffset = config.OctaveOffsets[partNum]; } } partNum++; } midiPlayer.PlaySpeed = config.PlaySpeed; return(midiPlayer); }
public async static Task <MidiPlayer> LoadTrackConfigs(double speed = 1, params TrackConfig[] configs) { MidiPlayer player = new MidiPlayer(); player.PlaySpeed = speed; foreach (TrackConfig config in configs) { MidiTrackPlayer track = new MidiTrackPlayer(config.Motors); await track.LoadMidiTrack(config.XmlPath); track.OctaveOffset = config.OctaveOffset; player.Tracks.Add(track); foreach (StepperMotor motor in config.Motors) { motor.OctaveOffset = config.OctaveOffset; } } return(player); }