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);
}
}