Example #1
0
        public void CreateRandomBeatmap(AudioAnalyzer analyzer)
        {
            if (!File.Exists(this.filePath))
            {
                Console.WriteLine("Error: File not found.(" + this.filePath + ")");
                return;
            }

            if (beatmapOccupied)
            {
                Console.WriteLine("Error: Beatmap already occupied with HitObjects, Clear all objects before continuing");
                return;
            }

            Console.WriteLine("Generating Random Beatmap. Appending to file..." + this.filePath);

            using (var osuFile = new StreamWriter(this.filePath, true))
            {
                int numCircles = 0;

                // Basic Beatmap Creation
                var prevPoint = PlayField.GetRandomPointInside();
                currentTimingPoint = (timingPoints.Count > 0) ? timingPoints[0] : null;
                float timestamp = (float)offset;

                // for (float timestamp = (float)offset; timestamp < songLength; timestamp += mpb)
                while (timestamp < songLength)
                {
                    Vector2 pos      = Vector2.Zero;
                    float   x        = RandomHelper.Range(Beatmap.PlayField.Left, Beatmap.PlayField.Right + 1);
                    float   y        = RandomHelper.Range(Beatmap.PlayField.Top, Beatmap.PlayField.Bottom + 1);
                    bool    newCombo = false;

                    if (currentTimingPoint != null)
                    {
                        currentTimingPoint = TimingPoint.UpdateCurrentTimingPoint((int)timestamp, timingPoints, currentTimingPoint);
                    }

                    //Gets a point on a circle whose center lies at the previous point.
                    do
                    {
                        float radius = RandomHelper.Range(30f, maxNoteDistance);                        //<---- This could be a function of bpm, i.e. time-distance relation between beats

                        pos = prevPoint + RandomHelper.OnCircle(prevPoint, radius);
                    } while (!PlayField.Contains(pos));


                    ////EXAMPLE USE CASE
                    double threshold = Double.Parse("-10");
                    var    peakData  = analyzer.CreatePeakDataAt((int)timestamp, 10000);
                    Console.WriteLine(peakData.ToString());
                    if (peakData.value < threshold)
                    {
                        //Continue without adding a beat here if no sound was detected.
                        timestamp += AddTime(NoteDuration.Half);
                        continue;
                    }


                    ////END EXAMPLE
                    // Determine if new Combo is needed
                    if (currentComboLength > comboChangeFlag)
                    {
                        newCombo           = true;
                        currentComboLength = currentComboLength % comboChangeFlag;
                    }

                    if (currentBeat % beatsPerMeasure == 0)
                    {
                        // Generate a random slider.
                        var    sliderType     = EnumHelper.GetRandom <SliderCurveType>();                 //sliderTypes[rnd.Next(0, 3)];
                        float  sliderTimespan = (RandomHelper.NextFloat < 0.5f) ? difficulty.sliderTimestamp1 : difficulty.sliderTimestamp2;
                        string sliderData     = GetSliderData(pos, (int)timestamp, HitObjectType.Slider,
                                                              HitObjectSoundType.None, sliderType, 1, sliderVelocity * currentTimingPoint.SliderVelocityMultiplier, RandomHelper.Range(minSliderCurves, maxSliderCurves + 1), sliderTimespan);

                        osuFile.WriteLine(sliderData);

                        numCircles++;

                        timestamp          += AddTime(sliderTimespan * 2);
                        currentBeat        += sliderTimespan * 2;
                        currentComboLength += sliderTimespan * 2;
                    }
                    else
                    {
                        HitObjectType hitType = (newCombo) ? HitObjectType.NormalNewCombo : HitObjectType.Normal;

                        // Test patterns!
                        if (RandomHelper.NextFloat < 0.12)
                        {
                            Triple triple = new Triple(PlayField.Center, (int)timestamp, HitObjectSoundType.None, prevPoint, mpb, difficulty);
                            osuFile.WriteLine(triple.SerializeForOsu());

                            currentComboLength += triple.totalLength;
                            timestamp          += AddTime(triple.totalLength);
                            currentBeat        += triple.totalLength;

                            prevPoint = PlayField.Center;
                        }

                        else
                        {
                            string circleData = GetHitCircleData(new Vector2(x, y), (int)timestamp, hitType,
                                                                 HitObjectSoundType.None, prevPoint);

                            osuFile.WriteLine(circleData);

                            numCircles++;

                            currentComboLength += difficulty.baseCircleTimestamp;
                            timestamp          += AddTime(difficulty.baseCircleTimestamp);
                            currentBeat        += difficulty.baseCircleTimestamp;

                            prevPoint = new Vector2(x, y);
                        }
                    }
                }

                Console.WriteLine("Number of circles " + numCircles);
            }
        }
Example #2
0
        // Creates a random beatmap. This APPENDS to the current file.
        // TODO: Need to make sure we are not overwriting other data, and starting from the correct location.
        public void CreateRandomBeatmap()
        {
            if (!File.Exists(this.filePath))
            {
                Console.WriteLine("Error: File not found.(" + this.filePath + ")");
                return;
            }

            Console.WriteLine("Generating Random Beatmap. Appending to file..." + this.filePath);

            using (var osuFile = new StreamWriter(this.filePath, true))
            {
                int numCircles = 0;

                // Basic Beatmap Creation
                var prevPoint = Vector2.NegativeOne;

                float timestamp = (float)offset;
                // for (float timestamp = (float)offset; timestamp < songLength; timestamp += mpb)
                while (timestamp < songLength)
                {
                    float x        = RandomHelper.Range(Beatmap.PlayField.Left, Beatmap.PlayField.Right + 1);
                    float y        = RandomHelper.Range(Beatmap.PlayField.Top, Beatmap.PlayField.Bottom + 1);
                    bool  newCombo = false;

                    // Determine if new Combo is needed
                    if (currentComboLength > comboChangeFlag)
                    {
                        newCombo           = true;
                        currentComboLength = currentComboLength % comboChangeFlag;
                    }
                    Console.WriteLine("currentBeat" + currentBeat);

                    /*
                     * float getBeatType = RandomHelper.NextFloat;
                     * if (getBeatType < 0.05f)
                     * {
                     *  timestamp += AddTime(NoteDuration.Quarter);
                     *  currentBeat += NoteDuration.Quarter;
                     *  continue;
                     * }
                     */

                    if (currentBeat % beatsPerMeasure == 0)
                    {
                        // Generate a random slider. // Test Random Slider Durations
                        var           sliderType = EnumHelper.GetRandom <SliderCurveType>();
                        HitObjectType hitType    = (newCombo) ? HitObjectType.SliderNewCombo : HitObjectType.Slider;

                        float  sliderTimespan = (RandomHelper.NextFloat < 0.5f) ? difficulty.sliderTimestamp1 : difficulty.sliderTimestamp2;
                        string sliderData     = GetSliderData(new Vector2(x, y), (int)timestamp, hitType,
                                                              HitObjectSoundType.None, sliderType, 1, sliderVelocity, RandomHelper.Range(minSliderCurves, maxSliderCurves + 1), sliderTimespan);

                        osuFile.WriteLine(sliderData);

                        numCircles++;

                        timestamp          += AddTime(sliderTimespan * 2);
                        currentBeat        += sliderTimespan * 2;
                        currentComboLength += sliderTimespan * 2;
                    }
                    else
                    {
                        HitObjectType hitType = (newCombo) ? HitObjectType.NormalNewCombo : HitObjectType.Normal;

                        // Test patterns!
                        if (RandomHelper.NextFloat < 0.12)
                        {
                            Triple triple = new Triple(PlayField.Center, (int)timestamp, HitObjectSoundType.None, prevPoint, mpb, difficulty);
                            osuFile.WriteLine(triple.SerializeForOsu());

                            currentComboLength += triple.totalLength;
                            timestamp          += AddTime(triple.totalLength);
                            currentBeat        += triple.totalLength;

                            prevPoint = PlayField.Center;
                        }

                        else
                        {
                            string circleData = GetHitCircleData(new Vector2(x, y), (int)timestamp, hitType,
                                                                 HitObjectSoundType.None, prevPoint);

                            osuFile.WriteLine(circleData);

                            numCircles++;

                            currentComboLength += difficulty.baseCircleTimestamp;
                            timestamp          += AddTime(difficulty.baseCircleTimestamp);
                            currentBeat        += difficulty.baseCircleTimestamp;

                            prevPoint = new Vector2(x, y);
                        }
                    }

                    // New Combo
                }

                Console.WriteLine("Number of circles " + numCircles);
            }
        }