From 6242202519ef0d76ccf50574ccbc038df10abda0 Mon Sep 17 00:00:00 2001 From: Stepland <10530295-Buggyroom@users.noreply.gitlab.com> Date: Fri, 14 Apr 2023 02:28:36 +0200 Subject: [PATCH] This segfault in a nasty way ... --- src/custom_sfml_audio/open_music.cpp | 3 ++- src/custom_sfml_audio/precise_sound_stream.hpp | 6 ++++-- src/custom_sfml_audio/synced_sound_streams.cpp | 12 ------------ src/custom_sfml_audio/synced_sound_streams.hpp | 2 +- src/editor_state.cpp | 11 +++++------ src/widgets/linear_view.cpp | 4 ++-- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/custom_sfml_audio/open_music.cpp b/src/custom_sfml_audio/open_music.cpp index 65dc0fd..ec6ebfd 100644 --- a/src/custom_sfml_audio/open_music.cpp +++ b/src/custom_sfml_audio/open_music.cpp @@ -1,5 +1,6 @@ #include "open_music.hpp" +#include #include #include #include @@ -166,7 +167,7 @@ bool OpenMusic::onGetData(SoundStream::Chunk& data) { current_offset += data.sampleCount; // Check if we have stopped obtaining samples or reached either the EOF or the loop end point - return (data.sampleCount != 0) && (current_offset < m_file.getSampleCount()) && !(current_offset == loopEnd && m_loopSpan.length != 0); + return (data.sampleCount != 0) && (static_cast(current_offset) < m_file.getSampleCount()) && !(current_offset == loopEnd && m_loopSpan.length != 0); } diff --git a/src/custom_sfml_audio/precise_sound_stream.hpp b/src/custom_sfml_audio/precise_sound_stream.hpp index 5af7a33..69ab379 100644 --- a/src/custom_sfml_audio/precise_sound_stream.hpp +++ b/src/custom_sfml_audio/precise_sound_stream.hpp @@ -20,8 +20,10 @@ struct PreciseSoundStream : public OpenSoundStream { }; template -sf::Uint64 time_to_samples(sf::Time position, T sample_rate, T channel_count) { - return ((static_cast(position.asMicroseconds()) * sample_rate * channel_count) + 500000) / 1000000; +std::int64_t time_to_samples(sf::Time position, T sample_rate, T channel_count) { + const auto signed_sample_rate = static_cast(sample_rate); + const auto signed_channel_count = static_cast(channel_count); + return ((static_cast(position.asMicroseconds()) * signed_sample_rate * signed_channel_count) + 500000) / 1000000; }; template diff --git a/src/custom_sfml_audio/synced_sound_streams.cpp b/src/custom_sfml_audio/synced_sound_streams.cpp index ed1d5d2..9503cf8 100644 --- a/src/custom_sfml_audio/synced_sound_streams.cpp +++ b/src/custom_sfml_audio/synced_sound_streams.cpp @@ -21,18 +21,6 @@ #include "imgui.h" #include "precise_sound_stream.hpp" -#ifdef _MSC_VER - #pragma warning(disable: 4355) // 'this' used in base member initializer list -#endif - -#if defined(__APPLE__) - #if defined(__clang__) - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - #elif defined(__GNUC__) - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" - #endif -#endif - void InternalStream::clear_queue() { // Get the number of buffers still in the queue diff --git a/src/custom_sfml_audio/synced_sound_streams.hpp b/src/custom_sfml_audio/synced_sound_streams.hpp index 8edcdb6..344f36b 100644 --- a/src/custom_sfml_audio/synced_sound_streams.hpp +++ b/src/custom_sfml_audio/synced_sound_streams.hpp @@ -34,7 +34,7 @@ struct Buffers { // Format of the internal sound buffers sf::Int32 m_format = 0; // Number of samples processed since beginning of the stream - sf::Uint64 m_samplesProcessed = 0; + std::int64_t m_samplesProcessed = 0; // If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation. std::array m_bufferSeeks = {0, 0, 0}; }; diff --git a/src/editor_state.cpp b/src/editor_state.cpp index 3c39721..1b03e13 100644 --- a/src/editor_state.cpp +++ b/src/editor_state.cpp @@ -370,11 +370,7 @@ void EditorState::set_playback_position(std::variant newPosi previous_playback_position = playback_position; playback_position = newPosition; const auto now = current_time(); - if (now >= sf::Time::Zero and now < editable_range.end) { - audio.setPlayingOffset(now); - } else { - stop(); - } + audio.setPlayingOffset(now); }; sf::Time EditorState::get_precise_playback_position() { @@ -1170,6 +1166,7 @@ void EditorState::display_timing_menu() { if (chart_state) { chart_state->density_graph.should_recompute = true; } + reload_editable_range(); } } ImGui::End(); @@ -1394,8 +1391,10 @@ void EditorState::reload_editable_range() { Interval EditorState::choose_editable_range() { Interval new_range{sf::Time::Zero, sf::Time::Zero}; if (music.has_value()) { - // If there is music, allow editing up to the end, but no further + // If there is music, allow editing from beat zero (which might be at + // a negative time in seconds) and up to the end, but no further // You've put notes *after* the end of the music ? fuck 'em. + new_range += applicable_timing->time_at(0); new_range += (**music).getDuration(); return new_range; } else { diff --git a/src/widgets/linear_view.cpp b/src/widgets/linear_view.cpp index caed2d4..6991e48 100644 --- a/src/widgets/linear_view.cpp +++ b/src/widgets/linear_view.cpp @@ -307,8 +307,8 @@ void LinearView::draw_in_waveform_mode(LinearView::DrawArgs& args) { const auto frac_chunk_at_cursor = static_cast(std::floor( static_cast(sample_at_cursor) / waveform.channel_count / chunk_sizes.fractional )); - const auto first_chunk = frac_chunk_at_cursor - static_cast(sizes.cursor_height); - const auto end_chunk = first_chunk + static_cast(work_rect.GetHeight()); + const std::int64_t first_chunk = frac_chunk_at_cursor - static_cast(sizes.cursor_height); + const std::int64_t end_chunk = first_chunk + static_cast(work_rect.GetHeight()); const AffineTransform seconds_to_pixels_proportional { 0, 1,