private void LoadSample(string file) { var lengthInSeconds = AudioStreamHelper.GetLength(file); var bpm = BpmHelper.GetBpmFromLoopLength(lengthInSeconds); var sample = new Sample { Filename = file, Description = (Path.GetFileNameWithoutExtension(file) + "").Replace(_folder, "").Replace("\\", ""), IsAtonal = true, IsPrimaryLoop = true, Gain = 0, LoopMode = LoopMode.FullLoop, Length = lengthInSeconds, TrackLength = (decimal)lengthInSeconds, Offset = 0, Start = 0, Key = "", Bpm = bpm, Tags = new List <string>(), TrackArtist = (Path.GetDirectoryName(file) + "").Replace(_folder, "").Replace("\\", ""), TrackTitle = (Path.GetFileNameWithoutExtension(file) + "").Replace(_folder, "").Replace("\\", ""), }; lock (_samples) { _samples.Add(sample); } }
public List <Track> GetDuplicateButDifferentShufflerTracks() { var duplicateButDifferentTracks = new List <Track>(); var duplicateTracksByTitle = Tracks .Where(track => track.IsShufflerTrack) .GroupBy(track => track.Description) .Where(group => group.Count() > 1) .ToList(); foreach (var duplicateTrackByTitle in duplicateTracksByTitle) { var tracks = duplicateTrackByTitle.ToList(); foreach (var track in tracks) { track.FullLength = Convert.ToDecimal(AudioStreamHelper.GetLength(track.Filename)); } var duplicateTracksByLength = tracks .GroupBy(track => track.FullLength) .ToList(); if (duplicateTracksByLength.Count > 1) { duplicateButDifferentTracks.AddRange(duplicateTracksByLength.SelectMany(x => x)); } } return(duplicateButDifferentTracks.OrderBy(x => x.Description).ToList()); }
/// <summary> /// Calculates the length track and saves it in the tag data /// </summary> /// <param name="track">The track.</param> public static void UpdateLength(Track track) { var length = decimal.Round(Convert.ToDecimal(AudioStreamHelper.GetLength(track.Filename)), 3); if (length == decimal.Round(track.FullLength, 3)) { return; } track.Length = length; track.FullLength = length; SaveTrack(track); }
public void LinkLoopSampleToTrack(string loopKey, Track track) { var filename = Path.Combine(LoopFolder, loopKey); if (!File.Exists(filename) || track == null) { return; } var length = AudioStreamHelper.GetLength(filename); var attributes = AutomationAttributesHelper.GetAutomationAttributes(track.Description); var description = Path.GetFileNameWithoutExtension(filename) .Replace("_", " ") .Replace("-", " ") .Replace(".", " "); attributes.LoopSamples.Add(new TrackSample { Description = description, IsExternalLoop = true, Key = loopKey, Length = length, IsLooped = true, Start = 0 }); AutomationAttributesHelper.SaveAutomationAttributes(track.Description, attributes); if (track == CurrentTrack || track == NextTrack) { Task.Run(() => { _samplePlayer.LoadSamples(CurrentTrack, NextTrack); OnTrackSamplesChanged?.Invoke(this, EventArgs.Empty); }); } }