예제 #1
0
        //creates the beatmap using audio detection
        private void createButton_Click(object sender, EventArgs e)
        {
            if (this.mp3FilePath == "" || beatmap == null)
            {
                if (this.mp3FilePath == "")
                {
                    Console.WriteLine("Error:No MP3 selected.");
                }

                if (beatmap == null)
                {
                    Console.WriteLine("Error:No beatmap selected.");
                }

                return;
            }

            this.analyzer = new AudioAnalyzer(this.mp3FilePath, this.beatmap);
            this.beatmap.CreateRandomBeatmap(this.analyzer);
        }
예제 #2
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);
            }
        }