/// <summary>
        ///     Sets the automation sync positions.
        /// </summary>
        /// <param name="track">The track.</param>
        private void SetAutomationSyncPositions(Track track)
        {
            if (track != CurrentTrack) return;

            foreach (var trigger in GetAutomationAttributes(track).TrackFXTriggers)
            {
                trigger.StartSample = track.SecondsToSamples(trigger.Start);
                trigger.EndSample = track.SecondsToSamples(trigger.Start + trigger.Length);
                trigger.StartSyncId = SetTrackSync(track, trigger.StartSample, SyncType.StartTrackFxTrigger);
                trigger.EndSyncId = SetTrackSync(track, trigger.EndSample, SyncType.EndTrackFxTrigger);
            }

            foreach (var trigger in GetCurrentSampleTriggers())
            {
                trigger.StartSample = track.SecondsToSamples(trigger.Start);
                trigger.EndSample = track.SecondsToSamples(trigger.Start + trigger.Length);
                trigger.StartSyncId = SetTrackSync(track, trigger.StartSample, SyncType.StartSampleTrigger);
                trigger.EndSyncId = SetTrackSync(track, trigger.EndSample, SyncType.EndSampleTrigger);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Loads the track audio data.
        /// </summary>
        /// <param name="track">The track to load.</param>
        /// <returns>
        ///     The loaded track
        /// </returns>
        public Track LoadTrackAudioData(Track track)
        {
            // abort if audio data already loaded
            if (track.IsAudioLoaded()) return track;

            // ensure mp3 tag data is loaded
            if (!track.TagDataLoaded) LoadTagData(track);

            DebugHelper.WriteLine("Loading track Audio Data " + track.Description);
            lock (track)
            {
                AudioStreamHelper.LoadAudio(track);

                track.FadeInStart = 0;
                track.FadeInStartVolume = (float) (DefaultFadeInStartVolume/100);
                track.FadeInEndVolume = (float) (DefaultFadeInEndVolume/100);

                track.FadeOutEnd = 0;
                track.FadeOutStartVolume = (float) (DefaultFadeOutStartVolume/100);
                track.FadeOutEndVolume = (float) (DefaultFadeOutEndVolume/100);

                ExtenedAttributesHelper.LoadExtendedAttributes(track);

                if (track.FadeOutStart == 0)
                {
                    if (LimitSongLength && track.LengthSeconds > MaxSongLength)
                    {
                        track.FadeOutStart = track.SecondsToSamples(MaxSongLength - DefaultFadeLength - 1);
                    }
                    else
                    {
                        track.FadeOutStart = track.SecondsToSamples(track.LengthSeconds - DefaultFadeLength - 1);
                    }
                }

                if (track.FadeInEnd == track.FadeInStart || track.FadeInEnd == 0)
                {
                    track.FadeInEnd = track.FadeInStart +
                                      track.SecondsToSamples(BpmHelper.GetBestFitLoopLength(track.StartBpm,
                                          DefaultFadeLength));
                }

                if (track.FadeOutEnd == track.FadeInStart || track.FadeOutEnd == 0)
                {
                    track.FadeOutEnd = track.FadeOutStart +
                                       track.SecondsToSamples(BpmHelper.GetBestFitLoopLength(track.EndBpm,
                                           DefaultFadeLength));
                }

                if (!track.UsePreFadeIn)
                {
                    track.PreFadeInStart = track.FadeInStart;
                    track.PreFadeInStartVolume = 0;
                }
            }

            AddToRecentTracks(track);

            DebugHelper.WriteLine("Finished loading track Audio Data " + track.Description);

            return track;
        }
        /// <summary>
        ///     Loads any attributes stored in a the track comment tag.
        /// </summary>
        /// <param name="track">The track.</param>
        public static void LoadExtendedAttributes(Track track)
        {
            if (track == null) return;
            if (track.Artist == "" || track.Title == "") return;

            DebugHelper.WriteLine("Loading Extended Attributes " + track.Description);

            var attributes = GetExtendedAttributes(track);
            if (attributes.ContainsKey("FadeIn"))
            {
                track.FadeInStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["FadeIn"]));
            }
            if (attributes.ContainsKey("FadeOut"))
            {
                track.FadeOutStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["FadeOut"]));
            }
            if (attributes.ContainsKey("BPMAdjust"))
            {
                track.BpmAdjustmentRatio = ConversionHelper.ToDecimal(attributes["BPMAdjust"]);
            }
            if (attributes.ContainsKey("FadeInLengthInSeconds"))
            {
                track.FadeInEnd = track.FadeInStart +
                                  track.SecondsToSamples(ConversionHelper.ToDouble(attributes["FadeInLengthInSeconds"]));
            }
            if (attributes.ContainsKey("FadeOutLengthInSeconds"))
            {
                track.FadeOutEnd = track.FadeOutStart +
                                   track.SecondsToSamples(ConversionHelper.ToDouble(attributes["FadeOutLengthInSeconds"]));
            }
            if (attributes.ContainsKey("PreFadeInStartVolume"))
            {
                track.PreFadeInStartVolume = ConversionHelper.ToFloat(attributes["PreFadeInStartVolume"])/100;
                track.UsePreFadeIn = true;
            }
            if (attributes.ContainsKey("PreFadeInPosition"))
            {
                track.PreFadeInStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["PreFadeInPosition"]));
                track.UsePreFadeIn = true;
            }
            if (attributes.ContainsKey("PreFadeInStart"))
            {
                track.PreFadeInStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["PreFadeInStart"]));
                track.UsePreFadeIn = true;
            }
            if (attributes.ContainsKey("StartBPM"))
            {
                track.StartBpm = BpmHelper.NormaliseBpm(ConversionHelper.ToDecimal(attributes["StartBPM"]));
            }
            if (attributes.ContainsKey("EndBPM"))
            {
                track.EndBpm = BpmHelper.NormaliseBpm(ConversionHelper.ToDecimal(attributes["EndBPM"]));
            }
            if (attributes.ContainsKey("Duration"))
            {
                if (track.Length == 0) track.Length = (long) (ConversionHelper.ToDouble(attributes["Duration"])*1000);
            }
            if (attributes.ContainsKey("PowerDown"))
            {
                track.PowerDownOnEnd = ConversionHelper.ToBoolean(attributes["PowerDown"]);
                track.PowerDownOnEndOriginal = track.PowerDownOnEnd;
            }
            if (attributes.ContainsKey("StartLoopCount"))
            {
                track.StartLoopCount = ConversionHelper.ToInt(attributes["StartLoopCount"]);
            }
            if (attributes.ContainsKey("EndLoopCount"))
            {
                track.EndLoopCount = ConversionHelper.ToInt(attributes["EndLoopCount"]);
            }
            if (attributes.ContainsKey("SkipStart"))
            {
                track.SkipStart = track.SecondsToSamples(ConversionHelper.ToDouble(attributes["SkipStart"]));
            }
            if (attributes.ContainsKey("SkipLengthInSeconds"))
            {
                track.SkipEnd = track.SkipStart +
                                track.SecondsToSamples(ConversionHelper.ToDouble(attributes["SkipLengthInSeconds"]));
            }
            if (attributes.ContainsKey("Rank"))
            {
                track.Rank = ConversionHelper.ToInt(attributes["Rank"], 1);
            }
            if (attributes.ContainsKey("Key"))
            {
                track.Key = attributes["Key"];
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Sets the track sync positions.
        /// </summary>
        /// <param name="track">The track.</param>
        private void SetTrackSyncPositions(Track track)
        {
            if (track == null) return;

            ClearTrackSyncPositions(track);

            DebugHelper.WriteLine("Set track sync positions " + track.Description);

            // set end track sync
            SetTrackSync(track, 0, SyncType.TrackEnd);

            // set fade-in sync events
            SetTrackSync(track, track.FadeInStart, SyncType.StartFadeIn);
            SetTrackSync(track, track.FadeInEnd, SyncType.EndFadeIn);

            // set fade-out sync events
            SetTrackSync(track, track.FadeOutStart, SyncType.StartFadeOut);
            SetTrackSync(track, track.FadeOutEnd, SyncType.EndFadeOut);

            // set pre-fade-in start (of next track) sync event
            if (NextTrack != null && NextTrack.UsePreFadeIn && track == CurrentTrack)
            {
                var preFadeInLength = track.SecondsToSamples(NextTrack.PreFadeInLengthSeconds);
                SetTrackSync(track, track.FadeOutStart - preFadeInLength, SyncType.StartPreFadeIn);
            }

            // set pre-fade-in start (of previous track) sync event
            if (track == NextTrack && track.UsePreFadeIn)
            {
                var preFadeInLength = CurrentTrack.SecondsToSamples(track.PreFadeInLengthSeconds);
                SetTrackSync(CurrentTrack, CurrentTrack.FadeOutStart - preFadeInLength, SyncType.StartPreFadeIn);
            }

            if (track != CurrentTrack) return;

            SetAutomationSyncPositions(track);
            if (HasExtendedMixAttributes())
            {
                SetTrackSync(PreviousTrack, GetExtendedMixAttributes().FadeEnd, SyncType.EndExtendedMix);
            }

            if (track.HasSkipSection)
            {
                SetTrackSync(track, track.SkipStart, SyncType.StartSkipSection);
            }
        }