Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/languages/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ ExclusiveMode=Exclusive Mode
AudioSampleRate=Audio Sample Rate
DefaultSuffix= (Default)
MineSounds=Mine Sounds
EvalPreviewMusic=Results Preview Music
GlobalOffsetMs=Global Offset (ms)
GlobalOffset=Global Offset (ms)
AlsaExclusive=Exclusive Mode
Expand Down Expand Up @@ -1503,6 +1504,7 @@ SfxVolumeHelp=Set the sound-effect volume before master volume is applied.
AssistTickVolumeHelp=Set the gameplay Assist Tick volume before master volume is applied.
MusicVolumeHelp=Set the music volume before master volume is applied.
MineSoundsHelp=Play a sound when mines are hit.
EvalPreviewMusicHelp=Play the song's preview music once on the results screen, regardless of pass or fail.
GlobalOffsetHelp=Apply a global audio timing offset in 1 ms steps.
RateModPreservesPitchHelp=Keep pitch constant when rate mods are active.
ReplayGainHelp=Experimental: normalize playback loudness across songs using ReplayGain 2.0 / EBU R 128. Loudness is computed in the background on first play and cached on disk; gain is applied to subsequent playback or live once analysis completes.
Expand Down
4 changes: 4 additions & 0 deletions src/config/load/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ fn load_audio_opts(conf: &SimpleIni, default: Config, cfg: &mut Config) {
.get("Options", "MenuMusic")
.and_then(|v| v.parse::<u8>().ok())
.map_or(default.menu_music, |v| v != 0);
cfg.eval_preview_music = conf
.get("Options", "EvalPreviewMusic")
.and_then(|v| v.parse::<u8>().ok())
.map_or(default.eval_preview_music, |v| v != 0);
cfg.custom_sounds_enabled = conf
.get("Options", "CustomSoundsEnabled")
.and_then(|v| v.parse::<u8>().ok())
Expand Down
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ pub struct Config {
pub visual_delay_seconds: f32,
pub master_volume: u8,
pub menu_music: bool,
pub eval_preview_music: bool,
pub custom_sounds_enabled: bool,
pub music_volume: u8,
// ITGmania PrefsManager "MusicWheelSwitchSpeed" (default 15).
Expand Down Expand Up @@ -529,6 +530,7 @@ impl Default for Config {
visual_delay_seconds: 0.0,
master_volume: 90,
menu_music: true,
eval_preview_music: false,
custom_sounds_enabled: true,
music_volume: 100,
music_wheel_switch_speed: 15,
Expand Down
1 change: 1 addition & 0 deletions src/config/store/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ fn push_default_options(content: &mut String, default: &Config) {
push_line(content, "VisualDelaySeconds", default.visual_delay_seconds);
push_line(content, "MasterVolume", default.master_volume);
push_bool(content, "MenuMusic", default.menu_music);
push_bool(content, "EvalPreviewMusic", default.eval_preview_music);
push_bool(
content,
"CustomSoundsEnabled",
Expand Down
1 change: 1 addition & 0 deletions src/config/store/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ fn push_saved_options(
push_line(content, "VisualDelaySeconds", cfg.visual_delay_seconds);
push_line(content, "MasterVolume", cfg.master_volume);
push_bool(content, "MenuMusic", cfg.menu_music);
push_bool(content, "EvalPreviewMusic", cfg.eval_preview_music);
push_bool(content, "CustomSoundsEnabled", cfg.custom_sounds_enabled);
push_bool(content, "MineHitSound", cfg.mine_hit_sound);
push_line(content, "MusicVolume", cfg.music_volume);
Expand Down
11 changes: 11 additions & 0 deletions src/config/update/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ pub fn update_menu_music(enabled: bool) {
save_without_keymaps();
}

pub fn update_eval_preview_music(enabled: bool) {
{
let mut cfg = lock_config();
if cfg.eval_preview_music == enabled {
return;
}
cfg.eval_preview_music = enabled;
}
save_without_keymaps();
}

pub fn update_software_renderer_threads(threads: u8) {
{
let mut cfg = lock_config();
Expand Down
28 changes: 28 additions & 0 deletions src/screens/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@ pub struct State {
menu_lr_undo: [i8; MAX_PLAYERS],
favorite_code: crate::screens::favorite_code::FavoriteCodeTracker,
test_input_state: test_input::State,
preview_music_started: bool,
}

impl Clone for State {
Expand Down Expand Up @@ -2014,6 +2015,7 @@ impl Clone for State {
menu_lr_undo: self.menu_lr_undo,
favorite_code: self.favorite_code.clone(),
test_input_state: self.test_input_state.clone(),
preview_music_started: self.preview_music_started,
}
}
}
Expand Down Expand Up @@ -2607,6 +2609,7 @@ pub fn init(gameplay_results: Option<gameplay::State>) -> State {
menu_lr_undo: [0; MAX_PLAYERS],
favorite_code: Default::default(),
test_input_state: test_input::State::default(),
preview_music_started: false,
}
}

Expand Down Expand Up @@ -2759,6 +2762,7 @@ pub fn init_from_score_info(
menu_lr_undo: [0; MAX_PLAYERS],
favorite_code: Default::default(),
test_input_state: test_input::State::default(),
preview_music_started: false,
}
}

Expand Down Expand Up @@ -2936,6 +2940,8 @@ pub fn update(state: &mut State, dt: f32) {
state.screen_elapsed += dt;
}

maybe_start_preview_music(state);

online::lobbies::poll_reconnect();
online::lobbies::update_machine_state_sides_with_stats(
"ScreenEvaluationStage",
Expand Down Expand Up @@ -3212,6 +3218,28 @@ pub(crate) fn all_joined_players_failed(state: &State) -> bool {
any
}

fn maybe_start_preview_music(state: &mut State) {
if state.preview_music_started {
return;
}
state.preview_music_started = true;

if !crate::config::get().eval_preview_music {
return;
}
let Some(si) = state.score_info.iter().flatten().next() else {
return;
};
if let Some((path, cut)) = crate::screens::select_music::compute_preview_cut(&si.song) {
let rate = if si.music_rate.is_finite() && si.music_rate > 0.0 {
si.music_rate
} else {
1.0
};
crate::engine::audio::play_music(path, cut, false, rate);
}
}

#[inline(always)]
const fn stage_in_stinger_texture_key(failed: bool, disqualified: bool) -> Option<&'static str> {
if failed || disqualified {
Expand Down
3 changes: 3 additions & 0 deletions src/screens/options/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ pub(super) fn apply_submenu_choice_delta(
SubRowId::MineSounds => {
config::update_mine_hit_sound(new_index == 1);
}
SubRowId::EvalPreviewMusic => {
config::update_eval_preview_music(new_index == 1);
}
SubRowId::RateModPreservesPitch => {
config::update_rate_mod_preserves_pitch(new_index == 1);
}
Expand Down
1 change: 1 addition & 0 deletions src/screens/options/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub enum ItemId {
SndAssistTickVolume,
SndMusicVolume,
SndMineSounds,
SndEvalPreviewMusic,
SndGlobalOffset,
SndRateModPitch,
SndReplayGain,
Expand Down
1 change: 1 addition & 0 deletions src/screens/options/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum SubRowId {
AssistTickVolume,
MusicVolume,
MineSounds,
EvalPreviewMusic,
GlobalOffset,
RateModPreservesPitch,
ReplayGain,
Expand Down
6 changes: 6 additions & 0 deletions src/screens/options/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,12 @@ pub fn init() -> State {
SubRowId::MineSounds,
usize::from(cfg.mine_hit_sound),
);
set_choice_by_id(
&mut state.sub[SubmenuKind::Sound].choice_indices,
SOUND_OPTIONS_ROWS,
SubRowId::EvalPreviewMusic,
usize::from(cfg.eval_preview_music),
);
set_choice_by_id(
&mut state.sub[SubmenuKind::Sound].choice_indices,
SOUND_OPTIONS_ROWS,
Expand Down
17 changes: 17 additions & 0 deletions src/screens/options/submenus/sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ pub(in crate::screens::options) const SOUND_OPTIONS_ROWS: &[SubRow] = &[
],
inline: true,
},
SubRow {
id: SubRowId::EvalPreviewMusic,
label: lookup_key("OptionsSound", "EvalPreviewMusic"),
choices: &[
localized_choice("Common", "Off"),
localized_choice("Common", "On"),
],
inline: true,
},
SubRow {
id: SubRowId::GlobalOffset,
label: lookup_key("OptionsSound", "GlobalOffset"),
Expand Down Expand Up @@ -181,6 +190,14 @@ pub(in crate::screens::options) const SOUND_OPTIONS_ITEMS: &[Item] = &[
"MineSoundsHelp",
))],
},
Item {
id: ItemId::SndEvalPreviewMusic,
name: lookup_key("OptionsSound", "EvalPreviewMusic"),
help: &[HelpEntry::Paragraph(lookup_key(
"OptionsSoundHelp",
"EvalPreviewMusicHelp",
))],
},
Item {
id: ItemId::SndGlobalOffset,
name: lookup_key("OptionsSound", "GlobalOffset"),
Expand Down
2 changes: 1 addition & 1 deletion src/screens/select_music.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ fn default_preview_start(song: &SongData, total_len: f64) -> f64 {
sec_at_beat(song, i_beat)
}

fn compute_preview_cut(song: &SongData) -> Option<(std::path::PathBuf, audio::Cut)> {
pub(crate) fn compute_preview_cut(song: &SongData) -> Option<(std::path::PathBuf, audio::Cut)> {
let path = song.music_path.clone()?;
let mut start = song.sample_start.unwrap_or(0.0) as f64;
let mut length = song.sample_length.unwrap_or(0.0) as f64;
Expand Down