From 71bfa5ba4225dc336383512f047521e180567a74 Mon Sep 17 00:00:00 2001 From: Stepland <10530295-Buggyroom@users.noreply.gitlab.com> Date: Fri, 17 Mar 2023 01:49:34 +0100 Subject: [PATCH] Ok it now fucking works but oh god is it ever slow --- src/config.cpp | 1 - src/editor_state.cpp | 31 +++++++++++++++++++++++-------- src/editor_state.hpp | 2 ++ src/linear_view_mode.cpp | 2 +- src/linear_view_mode.hpp | 4 ++-- src/meson.build | 1 + src/widgets/lane_order.hpp | 4 ++-- src/widgets/linear_view.cpp | 28 +++++++++++++++------------- src/widgets/linear_view.hpp | 2 -- 9 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index f5945f2..f7b0dd4 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -9,7 +9,6 @@ #include #include "linear_view_colors.hpp" -#include "linear_view_mode.hpp" #include "marker.hpp" #include "nowide/fstream.hpp" #include "variant_visitor.hpp" diff --git a/src/editor_state.cpp b/src/editor_state.cpp index d9bb36b..2dc7bc0 100644 --- a/src/editor_state.cpp +++ b/src/editor_state.cpp @@ -728,8 +728,8 @@ void EditorState::display_file_properties() { if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) { ImGui::BeginTooltip(); ImGui::TextUnformatted( - "You must define a time selection in the vertical view first !\n" - "Open up 'View' > 'Vertical View' then use the Tab key to set the start, then the end" + "You must define a time selection in the linear view first !\n" + "Open up 'View' > 'Linear View' then use the Tab key to set the start, then the end" ); ImGui::EndTooltip(); } @@ -980,10 +980,18 @@ void EditorState::display_linear_view() { if (chart_state) { auto header_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.f; ImGui::SetCursorPos({0, header_height}); + const auto waveform = [&, this]() -> std::optional { + const auto full_path = this->full_audio_path(); + if (not full_path) { + return {}; + } else { + return waveform_cache.get(*full_path); + } + }(); LinearView::DrawArgs draw_args { ImGui::GetWindowDrawList(), *chart_state, - waveform_cache.get(song.metadata.audio), + waveform, *applicable_timing, current_exact_beats(), beats_at(editable_range.end), @@ -1409,6 +1417,14 @@ void EditorState::reload_jacket() { } }; +std::optional EditorState::full_audio_path() { + if (not song_path.has_value() or song.metadata.audio.empty()) { + return {}; + } else { + return song_path->parent_path() / song.metadata.audio; + } +} + /* * Reloads music from what's indicated in the "music path" field of the song * Resets the music state in case anything fails @@ -1416,15 +1432,14 @@ void EditorState::reload_jacket() { */ void EditorState::reload_music() { const auto status_before = get_status(); - if (not song_path.has_value() or song.metadata.audio.empty()) { + const auto absolute_music_path = full_audio_path(); + if (not absolute_music_path) { clear_music(); return; } - - const auto absolute_music_path = song_path->parent_path() / song.metadata.audio; try { - music.emplace(std::make_shared(absolute_music_path)); - waveform_cache.async_emplace(song.metadata.audio); + music.emplace(std::make_shared(*absolute_music_path)); + waveform_cache.async_emplace(*absolute_music_path); } catch (const std::exception& e) { clear_music(); } diff --git a/src/editor_state.hpp b/src/editor_state.hpp index 517b229..64e2b5e 100644 --- a/src/editor_state.hpp +++ b/src/editor_state.hpp @@ -259,6 +259,8 @@ private: TimingOrigin timing_origin(); std::filesystem::path assets; + + std::optional full_audio_path(); }; namespace feis { diff --git a/src/linear_view_mode.cpp b/src/linear_view_mode.cpp index 61019f0..1855647 100644 --- a/src/linear_view_mode.cpp +++ b/src/linear_view_mode.cpp @@ -2,7 +2,7 @@ #include "variant_visitor.hpp" -namespace linear_view { +namespace linear_view::mode { Mode load_from_v1_0_0_table(const toml::table& linear_view) { const auto mode_string = linear_view["mode"].value(); if (not mode_string) { diff --git a/src/linear_view_mode.hpp b/src/linear_view_mode.hpp index 231fafc..e0faccb 100644 --- a/src/linear_view_mode.hpp +++ b/src/linear_view_mode.hpp @@ -13,8 +13,8 @@ namespace linear_view { using Mode = std::variant; namespace mode { - linear_view::Mode load_from_v1_0_0_table(const toml::table& linear_view); - void dump_as_v1_0_0(const linear_view::Mode& mode, toml::table& linear_view); + Mode load_from_v1_0_0_table(const toml::table& linear_view); + void dump_as_v1_0_0(const Mode& mode, toml::table& linear_view); } const Mode default_mode = mode::Beats{}; diff --git a/src/meson.build b/src/meson.build index a4c598c..3bfba12 100644 --- a/src/meson.build +++ b/src/meson.build @@ -19,6 +19,7 @@ sources += files( 'imgui_extras.cpp', 'json_decimal_handling.cpp', 'linear_view_colors.cpp', + 'linear_view_mode.cpp', 'linear_view_sizes.cpp', 'ln_marker.cpp', 'long_note_dummy.cpp', diff --git a/src/widgets/lane_order.hpp b/src/widgets/lane_order.hpp index 6d694aa..e44c548 100644 --- a/src/widgets/lane_order.hpp +++ b/src/widgets/lane_order.hpp @@ -41,8 +41,8 @@ namespace linear_view { using LaneOrder = std::variant; namespace lane_order { - linear_view::LaneOrder load_from_v1_0_0_table(const toml::table& linear_view); - void dump_as_v1_0_0(const linear_view::LaneOrder& lane_order, toml::table& linear_view); + LaneOrder load_from_v1_0_0_table(const toml::table& linear_view); + void dump_as_v1_0_0(const LaneOrder& lane_order, toml::table& linear_view); } const LaneOrder default_lane_order = lane_order::Default{}; diff --git a/src/widgets/linear_view.cpp b/src/widgets/linear_view.cpp index f865d00..7f9abe9 100644 --- a/src/widgets/linear_view.cpp +++ b/src/widgets/linear_view.cpp @@ -42,6 +42,7 @@ void SelectionRectangle::reset() { } LinearView::LinearView(std::filesystem::path assets, config::Config& config_) : + mode(config_.linear_view.mode), colors(config_.linear_view.colors), sizes(config_.linear_view.sizes), collision_zone(config_.editor.collision_zone), @@ -273,13 +274,14 @@ void LinearView::draw_in_waveform_mode(LinearView::DrawArgs& args) { ] = args; const auto computed_sizes = linear_view::compute_sizes(window_size, sizes); - if ( - not opt_ref_to_an_opt_waveform - or not opt_ref_to_an_opt_waveform.value().get() - ) { + if (not opt_ref_to_an_opt_waveform) { feis::CenteredText("Loading ..."); return; } + if (not opt_ref_to_an_opt_waveform.value().get()) { + feis::CenteredText("Error while loading waveform"); + } + const auto waveform = opt_ref_to_an_opt_waveform.value().get().value(); if (waveform.channels_per_chunk_size.empty()) { feis::CenteredText("No data ???"); @@ -729,11 +731,11 @@ void LinearView::set_zoom(int newZoom) { } void LinearView::display_settings() { - if (ImGui::Begin("Vertical View Settings", &shouldDisplaySettings)) { - if (ImGui::SliderInt("Zoom##Vertical View Settings", &zoom, -10, 10, "%d")) { + if (ImGui::Begin("Linear View Settings", &shouldDisplaySettings)) { + if (ImGui::SliderInt("Zoom##Linear View Settings", &zoom, -10, 10, "%d")) { set_zoom(zoom); } - if (ImGui::BeginCombo("Mode##Vertical View Settings", mode_name().c_str())) { + if (ImGui::BeginCombo("Mode##Linear View Settings", mode_name().c_str())) { if (ImGui::Selectable( "Beats", std::holds_alternative(mode) @@ -748,7 +750,7 @@ void LinearView::display_settings() { } ImGui::EndCombo(); } - if (ImGui::CollapsingHeader("Notes##Vertical View Settings")) { + if (ImGui::CollapsingHeader("Notes##Linear View Settings")) { ImGui::Checkbox("Colored Quantization", &use_quantization_colors); if (use_quantization_colors) { for (auto& [quant, color] : quantization_colors.palette) { @@ -766,7 +768,7 @@ void LinearView::display_settings() { } } } - if (ImGui::CollapsingHeader("Lanes##Vertical View Settings")) { + if (ImGui::CollapsingHeader("Lanes##Linear View Settings")) { if (ImGui::BeginCombo("Order", lane_order_name().c_str())) { if (ImGui::Selectable( "Default", @@ -800,8 +802,8 @@ void LinearView::display_settings() { LaneOrderPreview(order.lane_to_button); } } - if (ImGui::CollapsingHeader("Colors##Vertical View Settings")) { - if (ImGui::Button("Reset##Colors##Vertical View Settings")) { + if (ImGui::CollapsingHeader("Colors##Linear View Settings")) { + if (ImGui::Button("Reset##Colors##Linear View Settings")) { colors = linear_view::default_colors; } feis::ColorEdit4("Cursor", colors.cursor); @@ -839,8 +841,8 @@ void LinearView::display_settings() { ImGui::TreePop(); } } - if (ImGui::CollapsingHeader("Metrics##Vertical View Settings")) { - if (ImGui::Button("Reset##Metrics##Vertical View Settings")) { + if (ImGui::CollapsingHeader("Metrics##Linear View Settings")) { + if (ImGui::Button("Reset##Metrics##Linear View Settings")) { sizes = linear_view::default_sizes; } ImGui::DragInt("Cursor Height", &sizes.cursor_height); diff --git a/src/widgets/linear_view.hpp b/src/widgets/linear_view.hpp index 54cec4d..b9e5e09 100644 --- a/src/widgets/linear_view.hpp +++ b/src/widgets/linear_view.hpp @@ -41,8 +41,6 @@ const std::map reference_note_colors = {{ }}; const sf::Color reference_note_grey = {134, 110, 116}; - - namespace linear_view { struct ComputedSizes { int x;