private static Sample GetNewLibarySample(Module.Sample librarySample)
 {
     return new Sample
     {
         Start = librarySample.Start,
         Length = librarySample.Length,
         Offset = librarySample.Offset,
         Description = librarySample.Key
     };
 }
 public SampleModel(Module.Sample sample, Module.AudioFile audioFile)
 {
     Description = audioFile.Key + "." + sample.Key;
     Sample = sample;
     AudioFile = audioFile;
     Bpm = BpmHelper.GetBpmFromLoopLength(sample.Length);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="module"></param>
        /// <param name="channelPlayer"></param>
        /// <param name="audioFile"></param>
        private void LoadSamples(Module module, AudioPlayer channelPlayer, Module.AudioFile audioFile)
        {
            if (!File.Exists(audioFile.Path)
                && _libraryFolder != ""
                && _libraryFolder.EndsWith("Library")
                && audioFile.Path.Contains("Library"))
            {
                var index = audioFile.Path.IndexOf("Library", StringComparison.Ordinal) + "Libary".Length + 1;
                var path = _libraryFolder + audioFile.Path.Substring(index);
                audioFile.Path = path;
            }

            foreach (var sample in audioFile.Samples)
            {
                var fullSampleKey = audioFile.Key + "." + sample.Key;
                channelPlayer.Load(fullSampleKey, audioFile.Path);
                var section = channelPlayer.AddSection(fullSampleKey,
                    fullSampleKey,
                    sample.Start,
                    sample.Length,
                    sample.Offset,
                    calculateBpmFromLength: true,
                    targetBpm: module.Bpm);

                section.LoopIndefinitely = true;
            }
        }
        public void CreateModule()
        {
            _mainPlayer.UnloadAll();

            Module = new Module
            {
                Bpm = 100,
                AudioFiles = new List<Module.AudioFile>(),
                Channels = new List<Module.Channel>(),
                Patterns = new List<Module.Pattern>(),
                Sequence = new List<string>(),
                Title = ""
            };
        }
 private void LoadAudioFiles(Module module)
 {
     foreach (var channelPlayer in _channelPlayers)
     {
         foreach (var audioFile in module.AudioFiles)
         {
             LoadSamples(module, channelPlayer, audioFile);
         }
     }
 }
        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);
            }
        }
 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);
 }
 private void LoadChannelPlayers(Module module)
 {
     _channelPlayers = new List<AudioPlayer>();
     for (var channelIndex = 0; channelIndex < module.Channels.Count; channelIndex++)
     {
         var channelPlayer = new AudioPlayer();
         Output.AddInputChannel(channelPlayer.Output);
         _channelPlayers.Add(channelPlayer);
     }
 }
        public void LoadModule(Module module)
        {
            Pause();
            _mainPlayer.UnloadAll();
            foreach (var player in _channelPlayers)
            {
                player.UnloadAll();
            }

            _targetBpm = module.Bpm;
            _loopLength = BpmHelper.GetDefaultLoopLength(_targetBpm);

            Module = module;

            LoadChannelPlayers(module);
            LoadAudioFiles(module);
        }