|
|
@ -23,6 +23,9 @@ EditorState::~EditorState()
|
|
|
|
|
|
|
|
|
|
|
|
void EditorState::input(const sf::Event& event)
|
|
|
|
void EditorState::input(const sf::Event& event)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (event.key.code == sf::Keyboard::Space && event.type == sf::Event::KeyReleased)
|
|
|
|
|
|
|
|
_music.isPaused() ? _music.play() : _music.pause();
|
|
|
|
|
|
|
|
|
|
|
|
_group->input(event);
|
|
|
|
_group->input(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -38,19 +41,57 @@ void EditorState::draw() const
|
|
|
|
|
|
|
|
|
|
|
|
void EditorState::enter()
|
|
|
|
void EditorState::enter()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_music.openFromFile("Uta-test.flac");
|
|
|
|
|
|
|
|
_music.setVolume(5);
|
|
|
|
|
|
|
|
|
|
|
|
auto& group = _group;
|
|
|
|
auto& group = _group;
|
|
|
|
auto& music = _music;
|
|
|
|
auto& music = _music;
|
|
|
|
auto& editor = _editor;
|
|
|
|
auto& editor = _editor;
|
|
|
|
|
|
|
|
|
|
|
|
_music->openFromFile("Uta-test.flac");
|
|
|
|
_bpm_calculator = std::make_shared<BPMCalculator>();
|
|
|
|
_music->setVolume(5);
|
|
|
|
auto& bpm_calculator = _bpm_calculator;
|
|
|
|
|
|
|
|
|
|
|
|
_bpm_calculator = std::make_shared<BPMCalculator>(_music);
|
|
|
|
|
|
|
|
std::shared_ptr<BPMCalculatorWidget> bpm_widget = std::make_shared<BPMCalculatorWidget>(_bpm_calculator, _font);
|
|
|
|
std::shared_ptr<BPMCalculatorWidget> bpm_widget = std::make_shared<BPMCalculatorWidget>(_bpm_calculator, _font);
|
|
|
|
bpm_widget->init(_editor);
|
|
|
|
|
|
|
|
|
|
|
|
auto button_start = std::make_shared<PushButton>("Start", _font);
|
|
|
|
|
|
|
|
auto button_stop = std::make_shared<PushButton>("Stop", _font);
|
|
|
|
|
|
|
|
auto button_apply = std::make_shared<PushButton>("Apply", _font);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button_start->setCallback([bpm_calculator, button_start, button_stop, &music]()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
music.play();
|
|
|
|
|
|
|
|
bpm_calculator->start();
|
|
|
|
|
|
|
|
button_start->setVisibility(false);
|
|
|
|
|
|
|
|
button_stop->setVisibility(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button_stop->setCallback([bpm_calculator, button_start, button_stop, &music]()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
music.stop();
|
|
|
|
|
|
|
|
bpm_calculator->stop();
|
|
|
|
|
|
|
|
button_start->setVisibility(true);
|
|
|
|
|
|
|
|
button_stop->setVisibility(false);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button_apply->setCallback([&editor, bpm_calculator]()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
BPMSection section;
|
|
|
|
|
|
|
|
section.bpm = bpm_calculator->fetchApproximatedInfo().BPM;
|
|
|
|
|
|
|
|
section.fraction = 2;
|
|
|
|
|
|
|
|
section.offset_start = bpm_calculator->getStartingOffset();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editor->insertBPMSection(std::move(section));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BPMCalculatorWidget::Init bpm_widget_init;
|
|
|
|
|
|
|
|
bpm_widget_init.stop = button_stop;
|
|
|
|
|
|
|
|
bpm_widget_init.apply = button_apply;
|
|
|
|
|
|
|
|
bpm_widget_init.start = button_start;
|
|
|
|
|
|
|
|
bpm_widget_init.current_time = [&music]() -> microsec { return music.fetchOffset(); };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bpm_widget->init(std::move(bpm_widget_init));
|
|
|
|
const auto bpm_widget_callback = [&group, bpm_widget=bpm_widget, &music]()
|
|
|
|
const auto bpm_widget_callback = [&group, bpm_widget=bpm_widget, &music]()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
music->stop();
|
|
|
|
music.stop();
|
|
|
|
bpm_widget->setVisibility(false);
|
|
|
|
bpm_widget->setVisibility(false);
|
|
|
|
group->unblock();
|
|
|
|
group->unblock();
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -113,14 +154,14 @@ void EditorState::enter()
|
|
|
|
editor->draw();
|
|
|
|
editor->draw();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
callbacks.onInput = [&editor](const sf::Event& event)
|
|
|
|
callbacks.onInput = [&editor, &music](const sf::Event& event)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
editor->input(PlayerInput{0, event});
|
|
|
|
editor->input(PlayerInput{music.fetchOffset(), event});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
callbacks.onUpdate = [&editor](const sf::Time& dt)
|
|
|
|
callbacks.onUpdate = [&editor, &music](const sf::Time& dt)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
editor->update(dt);
|
|
|
|
editor->update(UpdateData{music.fetchOffset(), dt});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
auto editor_widget = std::make_shared<EditorWidget>(std::move(callbacks));
|
|
|
|
auto editor_widget = std::make_shared<EditorWidget>(std::move(callbacks));
|
|
|
|