Only show the very first BPM in the Adjust Sync Menu

This commit is contained in:
Stepland 2023-07-08 15:58:11 +02:00
parent 8e9c075287
commit 03eb055464
3 changed files with 21 additions and 7 deletions

View File

@ -243,6 +243,14 @@ namespace better {
return Timing{{{bpm, 0}}, -1 * offset}; return Timing{{{bpm, 0}}, -1 * offset};
}; };
Timing::keys_by_beats_type::const_iterator Timing::cbegin() const {
return events_by_beats.cbegin();
}
Timing::keys_by_beats_type::const_iterator Timing::cend() const {
return events_by_beats.cend();
}
void Timing::reconstruct(const std::vector<BPMAtBeat>& events, const Decimal& offset) { void Timing::reconstruct(const std::vector<BPMAtBeat>& events, const Decimal& offset) {
reload_events_from(events); reload_events_from(events);
set_offset(offset); set_offset(offset);

View File

@ -94,6 +94,9 @@ namespace better {
static Timing load_from_memon_1_0_0(const nlohmann::json& json); static Timing load_from_memon_1_0_0(const nlohmann::json& json);
static Timing load_from_memon_legacy(const nlohmann::json& metadata); static Timing load_from_memon_legacy(const nlohmann::json& metadata);
keys_by_beats_type::const_iterator cbegin() const;
keys_by_beats_type::const_iterator cend() const;
template<typename Callback> template<typename Callback>
void for_each_event_between(const Fraction& first, const Fraction& last, const Callback& cb) const { void for_each_event_between(const Fraction& first, const Fraction& last, const Callback& cb) const {
const auto first_element = events_by_beats.lower_bound(bpm_event_type{first, 0, 1}); const auto first_element = events_by_beats.lower_bound(bpm_event_type{first, 0, 1});

View File

@ -1144,15 +1144,12 @@ void EditorState::display_history() {
void EditorState::display_sync_menu() { void EditorState::display_sync_menu() {
if (ImGui::Begin("Adjust Sync", &show_sync_menu, ImGuiWindowFlags_AlwaysAutoResize)) { if (ImGui::Begin("Adjust Sync", &show_sync_menu, ImGuiWindowFlags_AlwaysAutoResize)) {
auto bpm = std::visit( auto intial_bpm = applicable_timing->cbegin()->get_bpm();
[&](const auto& pos){return applicable_timing->bpm_at(pos);},
playback_position
);
ImGui::PushItemWidth(-70.0f); ImGui::PushItemWidth(-70.0f);
if (feis::InputDecimal("Initial BPM", &bpm, ImGuiInputTextFlags_EnterReturnsTrue)) { if (feis::InputDecimal("Initial BPM", &intial_bpm, ImGuiInputTextFlags_EnterReturnsTrue)) {
if (bpm > 0) { if (intial_bpm > 0) {
auto new_timing = *applicable_timing; auto new_timing = *applicable_timing;
new_timing.insert(better::BPMAtBeat{bpm, current_snaped_beats()}); new_timing.insert(better::BPMAtBeat{intial_bpm, new_timing.cbegin()->get_beats()});
replace_applicable_timing_with(new_timing); replace_applicable_timing_with(new_timing);
} }
} }
@ -1243,6 +1240,9 @@ void EditorState::display_sync_menu() {
} }
ImGui::EndChild(); ImGui::EndChild();
} }
if (loading) {
ImGui::BeginDisabled();
}
if (ImGui::Button("Guess BPM", {ImGui::GetContentRegionAvail().x * 0.5f, 0.0f})) { if (ImGui::Button("Guess BPM", {ImGui::GetContentRegionAvail().x * 0.5f, 0.0f})) {
const auto path = full_audio_path(); const auto path = full_audio_path();
tempo_candidates.reset(); tempo_candidates.reset();
@ -1250,6 +1250,9 @@ void EditorState::display_sync_menu() {
tempo_candidates_loader = std::async(std::launch::async, guess_tempo, *path); tempo_candidates_loader = std::async(std::launch::async, guess_tempo, *path);
} }
} }
if (loading) {
ImGui::EndDisabled();
}
ImGui::SameLine(); ImGui::SameLine();
const bool tempo_candidate_was_selected_before_pressing = selected_tempo_candidate.has_value(); const bool tempo_candidate_was_selected_before_pressing = selected_tempo_candidate.has_value();
if (not tempo_candidate_was_selected_before_pressing) { if (not tempo_candidate_was_selected_before_pressing) {