示例#1
0
        private void mnuLoadProject_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = "Beat Projects|*.bproj"
            };

            if (dialog.ShowDialog(this) != true)
            {
                return;
            }

            BeatProject project = BeatProject.Load(dialog.FileName);

            if (File.Exists(project.VideoFile))
            {
                OpenVideo(project.VideoFile, true, false);
            }
            else
            {
                string otherPath = ChangePath(dialog.FileName, project.VideoFile);
                OpenVideo(otherPath, true, false);
            }

            SetCondition(project.SampleCondition);
            BeatBarDuration = TimeSpan.FromSeconds(project.BeatBarDuration);
            BeatBarCenter   = project.BeatBarMidpoint;
            Beats           = new BeatCollection(project.Beats.Select(TimeSpan.FromTicks));
            Bookmarks       = project.Bookmarks.Select(TimeSpan.FromTicks).ToList();

            _projectFile = dialog.FileName;
        }
        /**<summary>Reset this sound so that it will play from the start.</summary>*/
        public void Reset()
        {
            BeatCollection.Enumerator = BeatCollection.GetEnumerator();
            ByteInterval = 0;
            if (Metronome.GetInstance().IsSilentInterval)
            {
                SetSilentInterval(Metronome.GetInstance().AudibleInterval, Metronome.GetInstance().SilentInterval);
            }
            if (Metronome.GetInstance().IsRandomMute)
            {
                randomMuteCountdown = null;
                currentlyMuted      = false;
            }
            if (Layer.Offset > 0)
            {
                SetOffset(
                    BeatCell.ConvertFromBpm(Layer.Offset, this)
                    );
            }
            // TODO: hihat open settings
            HiHatOpenIsMuted = false;
            //HiHatMuteInitiated = false;
            HiHatCycleToMute = 0;
            cycle            = 0;

            // will first muting occur for first sound?
            SetInitialMuting();

            // set stream back to start.
            Position = 0;
        }
        double newGainStep;      // set when Volume changes and takes effect when byte interval resets.

        /**<summary>If a multiply is cued, perform operation on all relevant members at the start of a stream read.</summary>*/
        public void MultiplyByteInterval()
        {
            lock (_multLock)
            {
                if (intervalMultiplyCued)
                {
                    BeatCollection.MultiplyBeatValues();

                    double mult = intervalMultiplyFactor * ByteInterval;
                    ByteInterval     = (int)mult;
                    Layer.Remainder *= intervalMultiplyFactor;
                    Layer.Remainder += mult - ByteInterval;

                    if (Layer.Remainder >= 1)
                    {
                        ByteInterval    += (int)Layer.Remainder;
                        Layer.Remainder -= (int)Layer.Remainder;
                    }

                    // multiply the offset aswell
                    if (hasOffset)
                    {
                        mult             = intervalMultiplyFactor * InitialOffset;
                        InitialOffset    = (int)mult;
                        OffsetRemainder *= intervalMultiplyFactor;
                        OffsetRemainder += mult - InitialOffset;
                    }

                    intervalMultiplyCued = false;
                }
            }
        }
        public override List <ScriptAction> Load(Stream stream)
        {
            BeatCollection beats = BeatCollection.Load(stream);

            return(beats.Select(beat => new BeatScriptAction
            {
                TimeStamp = beat
            }).Cast <ScriptAction>().ToList());
        }
        /**<summary>Perform a cued byte interval multiplication.</summary>*/
        public void MultiplyByteInterval()
        {
            lock (_multLock)
            {
                if (intervalMultiplyCued)
                {
                    BeatCollection.MultiplyBeatValues();

                    double div = ByteInterval / 4;
                    div             *= intervalMultiplyFactor;
                    Layer.Remainder *= intervalMultiplyFactor; // multiply remainder as well
                    Layer.Remainder += div - (int)div;
                    ByteInterval     = (int)div * 4;

                    if (Layer.Remainder >= 1)
                    {
                        ByteInterval    += (int)Layer.Remainder * 4;
                        Layer.Remainder -= (int)Layer.Remainder;
                    }

                    // multiply the offset aswell
                    if (hasOffset)
                    {
                        div              = initialOffset / 4;
                        div             *= intervalMultiplyFactor;
                        offsetRemainder *= intervalMultiplyFactor;
                        offsetRemainder += div - (int)div;
                        initialOffset    = (int)div * 4;
                    }

                    //// do the hihat cutoff interval
                    if (IsHiHatOpen && CurrentHiHatDuration != 0)
                    {
                        div = CurrentHiHatDuration / 4;
                        CurrentHiHatDuration = (int)(div * intervalMultiplyFactor) * 4;
                    }

                    // recalculate the hihat count and byte to cutoff values
                    if (IsHiHatOpen && Layer.HasHiHatClosed)
                    {
                        int countDiff  = HiHatCycleToMute - cycle;
                        int totalBytes = countDiff * 2560 + HiHatByteToMute;
                        totalBytes       = (int)(totalBytes * intervalMultiplyFactor);
                        HiHatCycleToMute = cycle + totalBytes / 2560;
                        HiHatByteToMute  = totalBytes % 2560;
                        HiHatByteToMute -= HiHatByteToMute % 4; // align
                    }

                    intervalMultiplyCued = false;
                }
            }
        }
示例#6
0
        private void btnLoadBeatsFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = "Text Files|*.txt"
            };

            if (dialog.ShowDialog(this) != true)
            {
                return;
            }

            Beats    = BeatCollection.Load(dialog.FileName);
            Duration = Beats.Max();
            UpdateHeatMap();
        }
示例#7
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string[] paths = txtPath.Text.Split(';');

            string[] files = paths.SelectMany(path => Directory.EnumerateFiles(path, "*.funscript", SearchOption.AllDirectories)).ToArray();

            List <ScriptStats> stats  = new List <ScriptStats>();
            FunScriptLoader    loader = new FunScriptLoader();

            foreach (string textFile in files)
            {
                try
                {
                    var collection = new BeatCollection(loader.Load(textFile).Select(l => l.TimeStamp));

                    var chapters = GetChapters(collection);
                    if (chapters == null || chapters.Count < 1)
                    {
                        continue;
                    }

                    TimeSpan duration = chapters.Aggregate(TimeSpan.Zero, (total, current) => total + (current.Last() - current.First()));
                    double   bpm      = chapters.Sum(c => c.Count - 1) / duration.TotalMinutes;

                    stats.Add(new ScriptStats
                    {
                        Beats           = collection.ToList(),
                        Bpm             = bpm,
                        ContentDuration = duration,
                        File            = textFile
                    });
                }
                catch
                {
                }
            }

            stats = stats.OrderByDescending(s => s.Bpm).ToList();

            int pos = 0;

            foreach (var stat in stats)
            {
                pos++;
                Debug.WriteLine($"[*] {stat.Bpm:f0} BMP, {stat.ContentDuration:h\\:mm\\:ss}, {System.IO.Path.GetFileNameWithoutExtension(stat.File)}");
            }
        }
示例#8
0
        private void btnStretchExecute_Click(object sender, RoutedEventArgs e)
        {
            TimeSpan durationFrom = _stretchFromEnd - _stretchFromBegin;
            TimeSpan durationTo   = _stretchToEnd - _stretchToBegin;

            if (durationTo <= TimeSpan.Zero || durationFrom <= TimeSpan.Zero)
            {
                return;
            }

            double   factor = durationTo.Divide(durationFrom);
            TimeSpan shift  = _stretchToBegin - _stretchFromBegin.Multiply(factor);

            //TimeSpan newBegin = _stretchFromBegin.Multiply(factor) + shift;
            //TimeSpan newEnd = _stretchFromEnd.Multiply(factor) + shift;

            var newbeats = _originalBeats.Scale(factor).Shift(shift);

            Beats = new BeatCollection(newbeats);
        }
示例#9
0
        private void mnuLoadProject_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = "Beat Projects|*.bproj"
            };

            if (dialog.ShowDialog(this) != true)
            {
                return;
            }

            BeatProject project = BeatProject.Load(dialog.FileName);

            OpenVideo(project.VideoFile);
            SetCondition(project.SampleCondition);
            BeatBarDuration = project.BeatBarDuration;
            BeatBarCenter   = project.BeatBarMidpoint;
            Beats           = new BeatCollection(project.Beats.Select(TimeSpan.FromTicks));
            Bookmarks       = project.Bookmarks.Select(TimeSpan.FromTicks).ToList();
        }
示例#10
0
        private List <List <TimeSpan> > GetChapters(BeatCollection timeStamps)
        {
            TimeSpan gapDuration = TimeSpan.FromSeconds(10);

            if (timeStamps.Count < 2)
            {
                return(null);
            }

            int chapterBegin = int.MinValue;
            int chapterEnd   = int.MinValue;

            List <List <TimeSpan> > chapters = new List <List <TimeSpan> >();

            for (int index = 0; index < timeStamps.Count; index++)
            {
                if (chapterBegin == int.MinValue)
                {
                    chapterBegin = index;
                    chapterEnd   = index;
                }
                else if (timeStamps[index] - timeStamps[chapterEnd] < gapDuration)
                {
                    chapterEnd = index;
                }
                else
                {
                    chapters.Add(GetRange(timeStamps, chapterBegin, chapterEnd));

                    chapterBegin = index;
                    chapterEnd   = index;
                }
            }

            if (chapterBegin != int.MinValue && chapterEnd != int.MinValue)
            {
                chapters.Add(GetRange(timeStamps, chapterBegin, chapterEnd));
            }

            return(chapters);
        }
 /**<summary>Reset state to default values.</summary>*/
 public void Reset()
 {
     freqEnum.Reset(); //= Frequencies.Values.GetEnumerator();
     BeatCollection.Enumerator = BeatCollection.GetEnumerator();
     ByteInterval   = 0;
     previousSample = 0;
     Gain           = Volume;
     if (Metronome.GetInstance().IsSilentInterval)
     {
         SetSilentInterval(Metronome.GetInstance().AudibleInterval, Metronome.GetInstance().SilentInterval);
     }
     if (Metronome.GetInstance().IsRandomMute)
     {
         randomMuteCountdown = null;
         currentlyMuted      = false;
     }
     if (Layer.Offset > 0)
     {
         SetOffset(
             BeatCell.ConvertFromBpm(Layer.Offset, this)
             );
     }
 }
示例#12
0
 private void SetAllBeats(IEnumerable <TimeSpan> beats)
 {
     _originalBeats = new BeatCollection(beats);
     Beats          = _originalBeats.Duplicate();
 }
示例#13
0
 private void LoadBeatsFile(string filename)
 {
     SetAllBeats(BeatCollection.Load(filename));
 }