public void MergeSamples(Module.AudioFile audioFile, List <Module.Sample> samples) { var newSampleKeys = samples.Select(x => x.Key).ToList(); audioFile.Samples.RemoveAll(x => newSampleKeys.Contains(x.Key)); audioFile.Samples.AddRange(samples); UpdateAudioFile(audioFile); }
/// <summary> /// /// </summary> /// <param name="module"></param> /// <param name="channelPlayer"></param> /// <param name="audioFile"></param> private static void LoadSamples(Module module, AudioPlayer channelPlayer, Module.AudioFile audioFile) { foreach (var sample in audioFile.Samples) { var fullSampleKey = audioFile.Key + "." + sample.Key; channelPlayer.Load(fullSampleKey, audioFile.Path); channelPlayer.AddSection(fullSampleKey, fullSampleKey, sample.Start, sample.Length, sample.Offset, calculateBpmFromLength: true, targetBpm: module.Bpm); } }
public void UpdateAudioFile(Module.AudioFile audioFile) { Pause(); Module.AudioFiles.RemoveAll(x => x.Key == audioFile.Key); Module.AudioFiles.Add(audioFile); foreach (var channelPlayer in _channelPlayers) { var existingSampleKeys = channelPlayer.GetStreamKeys().Where(x => x.StartsWith(audioFile.Key + ".")).ToList(); foreach (var sampleKey in existingSampleKeys) { channelPlayer.Unload(sampleKey); } LoadSamples(Module, channelPlayer, audioFile); } }