|
|
|
@ -41,12 +41,12 @@ void BPMCalculatorWidget::update(const sf::Time& dt)
|
|
|
|
|
Window::update(dt);
|
|
|
|
|
|
|
|
|
|
const auto beat_info = _bpm_calculator->fetchApproximatedInfo();
|
|
|
|
|
if (beat_info.rate_per_microsecond != 0)
|
|
|
|
|
if (beat_info.BPM != 0)
|
|
|
|
|
{
|
|
|
|
|
_bpm_value.setString(std::to_string(static_cast<int>(beat_info.rate_per_microsecond)));
|
|
|
|
|
_bpm_value.setString(std::to_string(static_cast<int>(beat_info.BPM)));
|
|
|
|
|
|
|
|
|
|
const microsec until_beat = _bpm_calculator->fetchTimeUntilNextBeat();
|
|
|
|
|
const auto time_relation = static_cast<long double>(beat_info.average_interval) / static_cast<long double>(until_beat);
|
|
|
|
|
const auto time_relation = static_cast<long double>(beat_info.interval) / static_cast<long double>(until_beat);
|
|
|
|
|
const auto slider_path_left = _slider->rect().width / time_relation;
|
|
|
|
|
if (slider_path_left < 50)
|
|
|
|
|
{
|
|
|
|
@ -69,6 +69,7 @@ void BPMCalculatorWidget::draw(sf::RenderTarget& target, sf::RenderStates states
|
|
|
|
|
{
|
|
|
|
|
_slider->draw(target, states);
|
|
|
|
|
_button_start->draw(target, states);
|
|
|
|
|
_button_stop->draw(target, states);
|
|
|
|
|
target.draw(_bpm_value, states);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -84,6 +85,10 @@ void BPMCalculatorWidget::setRect(const sf::FloatRect& rect)
|
|
|
|
|
_button_start->setPosition({_window_content.getGlobalBounds().left + rect.width / 7,
|
|
|
|
|
_window_content.getGlobalBounds().top + _window_content.getGlobalBounds().height - 40});
|
|
|
|
|
|
|
|
|
|
_button_stop->setRect(sf::FloatRect{0, 0, rect.width / 10 * 3, 30});
|
|
|
|
|
_button_stop->setPosition({_window_content.getGlobalBounds().left + rect.width / 7,
|
|
|
|
|
_window_content.getGlobalBounds().top + _window_content.getGlobalBounds().height - 40});
|
|
|
|
|
|
|
|
|
|
_bpm_value.setPosition({_window_content.getGlobalBounds().left + rect.width / 8,
|
|
|
|
|
_window_content.getGlobalBounds().top + rect.height / 8 });
|
|
|
|
|
}
|
|
|
|
@ -105,12 +110,35 @@ void BPMCalculatorWidget::init()
|
|
|
|
|
auto& bpm_calculator = _bpm_calculator;
|
|
|
|
|
|
|
|
|
|
_button_start = std::make_shared<PushButton>("Start", _font);
|
|
|
|
|
_button_start->setCallback([bpm_calculator, button_start=_button_start]()
|
|
|
|
|
_button_stop = std::make_shared<PushButton>("Stop", _font);
|
|
|
|
|
|
|
|
|
|
_button_start->setCallback([bpm_calculator, button_start=_button_start, button_stop=_button_stop]()
|
|
|
|
|
{
|
|
|
|
|
bpm_calculator->music()->play();
|
|
|
|
|
bpm_calculator->music()->play(); // Remove when global play/stop available
|
|
|
|
|
bpm_calculator->start();
|
|
|
|
|
button_start->setVisibility(false);
|
|
|
|
|
button_stop->setVisibility(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
_button_stop->setCallback([bpm_calculator, button_start=_button_start, button_stop=_button_stop]()
|
|
|
|
|
{
|
|
|
|
|
bpm_calculator->music()->stop(); // Remove when global play/stop available
|
|
|
|
|
bpm_calculator->stop();
|
|
|
|
|
button_start->setVisibility(true);
|
|
|
|
|
button_stop->setVisibility(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addChild(_button_start);
|
|
|
|
|
addChild(_button_stop);
|
|
|
|
|
|
|
|
|
|
_button_stop->setVisibility(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BPMCalculatorWidget::setVisibility(bool is_visible)
|
|
|
|
|
{
|
|
|
|
|
Window::setVisibility(is_visible);
|
|
|
|
|
|
|
|
|
|
bool can_stop = _bpm_calculator->calculating();
|
|
|
|
|
_button_stop->setVisibility(can_stop);
|
|
|
|
|
_button_start->setVisibility(!can_stop);
|
|
|
|
|
}
|
|
|
|
|