This segfault in a nasty way ...

This commit is contained in:
Stepland 2023-04-14 02:28:36 +02:00
parent 8150977ae7
commit 6242202519
6 changed files with 14 additions and 24 deletions

View File

@ -1,5 +1,6 @@
#include "open_music.hpp"
#include <cstddef>
#include <cstdint>
#include <fstream>
#include <algorithm>
@ -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<std::size_t>(current_offset) < m_file.getSampleCount()) && !(current_offset == loopEnd && m_loopSpan.length != 0);
}

View File

@ -20,8 +20,10 @@ struct PreciseSoundStream : public OpenSoundStream {
};
template<class T>
sf::Uint64 time_to_samples(sf::Time position, T sample_rate, T channel_count) {
return ((static_cast<sf::Uint64>(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<std::int64_t>(sample_rate);
const auto signed_channel_count = static_cast<std::int64_t>(channel_count);
return ((static_cast<std::int64_t>(position.asMicroseconds()) * signed_sample_rate * signed_channel_count) + 500000) / 1000000;
};
template<class T>

View File

@ -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

View File

@ -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<sf::Int64, BufferCount> m_bufferSeeks = {0, 0, 0};
};

View File

@ -370,11 +370,7 @@ void EditorState::set_playback_position(std::variant<sf::Time, Fraction> 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();
}
};
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<sf::Time> EditorState::choose_editable_range() {
Interval<sf::Time> 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 {

View File

@ -307,8 +307,8 @@ void LinearView::draw_in_waveform_mode(LinearView::DrawArgs& args) {
const auto frac_chunk_at_cursor = static_cast<std::int64_t>(std::floor(
static_cast<double>(sample_at_cursor) / waveform.channel_count / chunk_sizes.fractional
));
const auto first_chunk = frac_chunk_at_cursor - static_cast<std::int64_t>(sizes.cursor_height);
const auto end_chunk = first_chunk + static_cast<std::int64_t>(work_rect.GetHeight());
const std::int64_t first_chunk = frac_chunk_at_cursor - static_cast<std::int64_t>(sizes.cursor_height);
const std::int64_t end_chunk = first_chunk + static_cast<std::int64_t>(work_rect.GetHeight());
const AffineTransform<float> seconds_to_pixels_proportional {
0,
1,