Skip to content

Commit

Permalink
Don't round loop_offset on import + Use double for loop_offset consis…
Browse files Browse the repository at this point in the history
…tently
  • Loading branch information
MJacred committed Feb 2, 2024
1 parent 9adb7c7 commit 7d11755
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions editor/import/audio_stream_import_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void AudioStreamImportSettingsDialog::edit(const String &p_path, const String &p
beats_edit->set_value(beats);
beats_enabled->set_pressed(beats > 0);
loop->set_pressed(config_file->get_value("params", "loop", false));
loop_offset->set_value(config_file->get_value("params", "loop_offset", 0));
loop_offset->set_value(double(config_file->get_value("params", "loop_offset", 0)));
bar_beats_edit->set_value(config_file->get_value("params", "bar_beats", 4));

List<String> keys;
Expand Down Expand Up @@ -517,7 +517,7 @@ void AudioStreamImportSettingsDialog::_settings_changed() {

void AudioStreamImportSettingsDialog::_reimport() {
params["loop"] = loop->is_pressed();
params["loop_offset"] = loop_offset->get_value();
params["loop_offset"] = double(loop_offset->get_value());
params["bpm"] = bpm_enabled->is_pressed() ? double(bpm_edit->get_value()) : double(0);
params["beat_count"] = (bpm_enabled->is_pressed() && beats_enabled->is_pressed()) ? int(beats_edit->get_value()) : int(0);
params["bar_beats"] = (bpm_enabled->is_pressed()) ? int(bar_beats_edit->get_value()) : int(4);
Expand All @@ -543,7 +543,7 @@ AudioStreamImportSettingsDialog::AudioStreamImportSettingsDialog() {
loop_hb->add_child(memnew(Label(TTR("Offset:"))));
loop_offset = memnew(SpinBox);
loop_offset->set_max(10000);
loop_offset->set_step(0.001);
loop_offset->set_disallow_step_rounding(true);
loop_offset->set_suffix("sec");
loop_offset->set_tooltip_text(TTR("Loop offset (from beginning). Note that if BPM is set, this setting will be ignored."));
loop_offset->connect("value_changed", callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));
Expand Down
2 changes: 1 addition & 1 deletion modules/minimp3/audio_stream_mp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AudioStreamMP3 : public AudioStream {
int channels = 1;
float length = 0.0;
bool loop = false;
float loop_offset = 0.0;
double loop_offset = 0.0;
void clear_data();

double bpm = 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/minimp3/resource_importer_mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Ref<AudioStreamMP3> ResourceImporterMP3::import_mp3(const String &p_path) {

Error ResourceImporterMP3::import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
bool loop = p_options["loop"];
float loop_offset = p_options["loop_offset"];
double loop_offset = p_options["loop_offset"];
double bpm = p_options["bpm"];
float beat_count = p_options["beat_count"];
float bar_beats = p_options["bar_beats"];
Expand Down
7 changes: 6 additions & 1 deletion scene/gui/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void Range::_set_value_no_signal(double p_val) {
return;
}

if (shared->step > 0) {
if (shared->step > 0 && !shared->skip_step_rounding) {
p_val = Math::round((p_val - shared->min) / shared->step) * shared->step + shared->min;
}

Expand Down Expand Up @@ -167,6 +167,10 @@ void Range::set_step(double p_step) {
shared->emit_changed("step");
}

void Range::set_disallow_step_rounding(bool disallow) {
shared->skip_step_rounding = disallow;
}

void Range::set_page(double p_page) {
double page_validated = CLAMP(p_page, 0, shared->max - shared->min);
if (shared->page == page_validated) {
Expand Down Expand Up @@ -258,6 +262,7 @@ void Range::unshare() {
nshared->max = shared->max;
nshared->val = shared->val;
nshared->step = shared->step;
nshared->skip_step_rounding = shared->skip_step_rounding;
nshared->page = shared->page;
nshared->exp_ratio = shared->exp_ratio;
nshared->allow_greater = shared->allow_greater;
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Range : public Control {
double min = 0.0;
double max = 100.0;
double step = 1.0;
bool skip_step_rounding = false;
double page = 0.0;
bool exp_ratio = false;
bool allow_greater = false;
Expand Down Expand Up @@ -78,6 +79,7 @@ class Range : public Control {
void set_min(double p_min);
void set_max(double p_max);
void set_step(double p_step);
void set_disallow_step_rounding(bool disallow);
void set_page(double p_page);
void set_as_ratio(double p_value);

Expand Down

0 comments on commit 7d11755

Please sign in to comment.