LoginSignup
0
0

More than 5 years have passed since last update.

ニコニコ生放送にて、30分で作った音楽プレイヤー

Last updated at Posted at 2014-06-07

20140607-204055-179.png

Main.cpp

//音楽プレイヤー
# include <Siv3D.hpp>

void Main()
{
    Graphics::SetBackground(Palette::White);

    const Sound sound = Dialog::OpenSound();

    sound.play();

    Circle playButton(Window::Center(), 30);

    Circle sliderToggle(20);

    const Point sliderStartPos{ 100, 100 };

    const Point sliderEndPos{ 540, 100 };

    const Vec2 sliderDelta = sliderEndPos - sliderStartPos;

    bool isDraggingSlider = false;

    while (System::Update())
    {
        if (playButton.leftClicked)
        {
            if (sound.isPlaying)
            {
                sound.pause();
            }
            else
            {
                sound.play();
            }
        }

        if (sliderToggle.leftClicked)
        {
            isDraggingSlider = true;

            sound.pause();
        }

        if (isDraggingSlider)
        {
            const double length = sliderEndPos.x - sliderStartPos.x;

            const double offset = Clamp(static_cast<double>(Mouse::Pos().x - sliderStartPos.x),0.0, length);

            const double value = offset / length;

            sound.setPosSec(value * sound.lengthSec);
        }

        if (Input::MouseL.released)
        {
            isDraggingSlider = false;

            sound.play();
        }

        sliderToggle.setPos((sound.posSec / sound.lengthSec) * sliderDelta + sliderStartPos);

        if (sound.isPlaying)
        {
            Waving::FFT(sound);
        }


        const float* p = Waving::FFTBuffer();

        for (int i = 0; i < 320; ++i)
        {
            RectF(i * 2, Window::Height(), 2, -Pow(p[i], 0.6f) * 1000).draw(HSV(240 - i));
        }


        playButton.draw(playButton.mouseOver ? Palette::Lightcoral : Palette::Gray);

        Line(sliderStartPos, sliderEndPos).draw(10, Palette::Gray);

        sliderToggle.draw(sliderToggle.mouseOver ? Palette::Lightcoral : Palette::Gray);
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0