Exemplo n.º 1
0
        private void AddSample(string sampleName, double start, double length)
        {
            var sample = new Sample
            {
                Description = sampleName
            };

            if (LibraryTrack != null)
            {
                TrackSampleLibrary.UpdateSampleFromTrack(sample, LibraryTrack);
            }

            Samples.Add(sample);
            CurrentSample           = sample;
            trackWave.CurrentSample = sample;
            trackWave.Samples       = Samples;

            sample.Start  = start;
            sample.Length = length;
            sample.Bpm    = BpmHelper.GetBpmFromLoopLength(sample.Length);

            RefreshTrackWavePositions();

            BindData();
        }
        public void AddSample(string sampleKey, string path, double start, double length, double offset, bool loopIndefinitely = true)
        {
            _sampleKeys.Add(sampleKey);

            if (_targetBpm == int.MinValue)
            {
                _targetBpm = BpmHelper.GetBpmFromLoopLength(length);
            }

            AudioPlayer channelPlayer;

            if (_sampleKeys.Count > _channelPlayers.Count)
            {
                channelPlayer = new AudioPlayer();
                _mixer.AddInputChannel(channelPlayer.Output);
                _channelPlayers.Add(channelPlayer);
            }
            else
            {
                channelPlayer = _channelPlayers[_sampleKeys.Count - 1];
            }

            channelPlayer.UnloadAll();
            channelPlayer.Load(sampleKey, path);
            var section = channelPlayer.AddSection(sampleKey,
                                                   sampleKey,
                                                   start,
                                                   length,
                                                   offset,
                                                   calculateBpmFromLength: true,
                                                   targetBpm: _targetBpm);

            section.LoopIndefinitely = loopIndefinitely;
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        private decimal CalculateSampleBpm()
        {
            var length = cmbSampleLength.Seconds;
            var start  = txtSampleStartPosition.Seconds;

            if (length == 0D)
            {
                return(0M);
            }

            if (GetLoopModeFromDropdown() == LoopMode.FullLoop)
            {
                return(BpmHelper.GetBpmFromLoopLength(length));
            }

            var samples = Samples.Where(x => x.LoopMode == LoopMode.FullLoop).ToList();

            samples.Remove(CurrentSample);

            if (!samples.Any())
            {
                return(Track.Bpm);
            }

            var firstSample = samples
                              .OrderByDescending(x => Math.Abs(start - x.Start))
                              .FirstOrDefault();

            return(firstSample?.Bpm ?? 100M);
        }
        public List <Sample> GetMixSectionsAsSamples(Track track)
        {
            var bassTrack = BassPlayer.LoadTrackAndAudio(track.Filename);
            var samples   = new List <Sample>();

            var fadeIn = new Sample
            {
                Description = "FadeIn",
                Start       = bassTrack.SamplesToSeconds(bassTrack.FadeInStart),
                Length      = bassTrack.FadeInLengthSeconds,
                Bpm         = BpmHelper.GetBpmFromLoopLength(bassTrack.FadeInLengthSeconds),
                Gain        = bassTrack.Gain
            };

            UpdateSampleFromTrack(fadeIn, track);

            samples.Add(fadeIn);

            var fadeOut = new Sample
            {
                Description = "FadeOut",
                Start       = bassTrack.SamplesToSeconds(bassTrack.FadeOutStart),
                Length      = bassTrack.FadeOutLengthSeconds,
                Bpm         = BpmHelper.GetBpmFromLoopLength(bassTrack.FadeOutLengthSeconds),
                Gain        = bassTrack.Gain
            };

            UpdateSampleFromTrack(fadeOut, track);

            samples.Add(fadeOut);

            BassPlayer.UnloadTrackAudioData(bassTrack);

            return(samples);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Sets the BPM values.
        /// </summary>
        private void SetBpmValues()
        {
            if (_bindingData)
            {
                return;
            }

            var fadeInLength = BpmHelper.GetDefaultLoopLength(Track.TagBpm);

            if (cmbCustomFadeInLength.Seconds != 0D)
            {
                fadeInLength = cmbCustomFadeInLength.Seconds;
            }
            var startBpm = BpmHelper.GetBpmFromLoopLength(fadeInLength);

            lblStartBPM.Text = startBpm.ToString("0.00");

            var fadeOutLength = BpmHelper.GetDefaultLoopLength(Track.TagBpm);

            if (cmbCustomFadeOutLength.Seconds != 0D)
            {
                fadeOutLength = cmbCustomFadeOutLength.Seconds;
            }
            var endBpm = BpmHelper.GetBpmFromLoopLength(fadeOutLength);

            lblEndBPM.Text = endBpm.ToString("0.00");

            PopulateVolumeDropDown(cmbPreFadeInStartVolume);
        }
Exemplo n.º 7
0
        public void SetSectionBpm(string streamKey, string sectionKey, decimal bpm = 0,
                                  bool calculateBpmFromLength = false, decimal targetBpm = 0)
        {
            var audioStream = GetAudioStream(streamKey);

            if (audioStream == null)
            {
                return;
            }

            var audioSection = GetAudioSection(streamKey, sectionKey);

            if (audioSection == null)
            {
                return;
            }

            if (calculateBpmFromLength)
            {
                var length = audioStream.SamplesToSeconds(audioSection.End.Position - audioSection.Start.Position);
                audioSection.Bpm = BpmHelper.GetBpmFromLoopLength(length);
            }
            else if (bpm != 0)
            {
                audioSection.Bpm = bpm;
            }
            else if (audioSection.Bpm != 0)
            {
                audioSection.Bpm = 100;
            }

            audioSection.TargetBpm = targetBpm;
        }
Exemplo n.º 8
0
        private double GetAdjustedSampleLenth(string streamKey, string sampleKey)
        {
            var audioFile = Module.AudioFiles.FirstOrDefault(x => x.Key == streamKey);
            var sample    = audioFile?.Samples.FirstOrDefault(x => x.Key == sampleKey);

            if (sample == null)
            {
                return(0);
            }

            var bpm = BpmHelper.GetBpmFromLoopLength(sample.Length);

            return(BpmHelper.GetAdjustedAudioLength(sample.Length, bpm, Module.Bpm));
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Gets the BPM of the sample
        /// </summary>
        public decimal CalculateBpm(Track track = null)
        {
            if (track == null || IsExternalLoop)
            {
                return(BpmHelper.GetBpmFromLoopLength(Length));
            }
            if (Key == "PreFadeIn")
            {
                return(track.StartBpm);
            }
            if (Length != 0 && IsLooped)
            {
                return(BpmHelper.GetBpmFromLoopLength(Length));
            }

            return(track.Bpm);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Loads the shuffler details for a track
        /// </summary>
        /// <param name="track">The track.</param>
        public static Dictionary <string, string> LoadShufflerDetails(Track track)
        {
            //if(track.Title.Contains("Escobar"))
            //    DebugHelper.WriteLine("Stop");

            track.Key = KeyHelper.ParseKey(track.Key);

            track.IsShufflerTrack = ExtenedAttributesHelper.HasExtendedAttributes(track.Description);

            if (!track.IsShufflerTrack)
            {
                return(null);
            }

            var attributes = ExtenedAttributesHelper.GetExtendedAttributes(track.Description);


            if (attributes.ContainsKey("Rank"))
            {
                track.Rank = ConversionHelper.ToInt(attributes["Rank"], 1);
            }

            decimal start = 0;

            if (attributes.ContainsKey("FadeIn"))
            {
                start = ConversionHelper.ToDecimal(attributes["FadeIn"], start);
            }
            var end = track.Length;

            if (attributes.ContainsKey("FadeOut"))
            {
                end = ConversionHelper.ToDecimal(attributes["FadeOut"], end);
            }
            var length = end - start;

            var inLoopCount = 0;

            if (attributes.ContainsKey("StartLoopCount"))
            {
                inLoopCount = ConversionHelper.ToInt(attributes["StartLoopCount"], inLoopCount);
            }

            decimal inLoopLength = 0;

            if (attributes.ContainsKey("FadeInLengthInSeconds"))
            {
                inLoopLength = ConversionHelper.ToDecimal(attributes["FadeInLengthInSeconds"]);
            }
            if (inLoopLength > 0)
            {
                track.StartBpm = BpmHelper.GetBpmFromLoopLength(Convert.ToDouble(inLoopLength));
            }

            inLoopCount = inLoopCount - 1;
            if (inLoopCount > 0)
            {
                length = length + inLoopCount * inLoopLength;
            }

            decimal skipLength = 0;

            if (attributes.ContainsKey("SkipLengthInSeconds"))
            {
                skipLength = ConversionHelper.ToDecimal(attributes["SkipLengthInSeconds"]);
            }
            if (skipLength > 0)
            {
                length = length - skipLength;
            }

            track.PowerDown = false;
            if (attributes.ContainsKey("PowerDown"))
            {
                track.PowerDown = ConversionHelper.ToBoolean(attributes["PowerDown"]);
            }

            if (attributes.ContainsKey("Key"))
            {
                track.Key = KeyHelper.ParseKey(attributes["Key"]);
            }

            decimal outLoopLength = 0;

            if (attributes.ContainsKey("FadeOutLengthInSeconds"))
            {
                outLoopLength = ConversionHelper.ToDecimal(attributes["FadeOutLengthInSeconds"], 0);
            }
            if (outLoopLength > 0)
            {
                track.EndBpm = BpmHelper.GetBpmFromLoopLength(Convert.ToDouble(outLoopLength));
            }

            track.Length = length;

            if (attributes.ContainsKey("StartBPM"))
            {
                track.StartBpm = BpmHelper.NormaliseBpm(ConversionHelper.ToDecimal(attributes["StartBPM"], track.Bpm));
            }
            if (attributes.ContainsKey("EndBPM"))
            {
                track.EndBpm = BpmHelper.NormaliseBpm(ConversionHelper.ToDecimal(attributes["EndBPM"], track.Bpm));
            }

            track.Bpm = BpmHelper.GetAdjustedBpmAverage(track.StartBpm, track.EndBpm);

            return(attributes);
        }