4#define MINIAUDIO_IMPLEMENTATION 1
7#define MA_NO_WEBAUDIO 1
13#define MA_NO_COREAUDIO 1
19 if(ma_engine_init(NULL, &
engine) != MA_SUCCESS) {
29 if(
sound.has_value()) {
30 ma_sound_set_volume(&*
sound, volume);
35 if(
sound.has_value()) {
36 ma_sound_uninit(&*
sound);
41 ma_result result = ma_sound_init_from_file(&
engine, s.
filename.c_str(), 0, NULL, NULL, &*
sound);
42 if(result == MA_SUCCESS) {
44 ma_sound_start(&*
sound);
52 audio.filename =
music_list[track].filename.c_str();
58 int32_t result = int32_t(rand() %
music_list.size());
85 state.sound_ptr = std::make_unique<sound_impl>();
92 state.sound_ptr->music_list.emplace_back(audio);
95 state.sound_ptr->first_music = int32_t(state.sound_ptr->music_list.size()) - 1;
101 state.sound_ptr->music_list.emplace_back(audio);
108 } vanilla_sound_table[] = {
110 { &state.sound_ptr->technology_finished_sound,
NATIVE(
"UI_TechnologyFinished.wav") },
111 { &state.sound_ptr->army_move_sound,
NATIVE(
"GI_InfantryMove.wav") },
112 { &state.sound_ptr->army_select_sound,
NATIVE(
"GI_InfantrySelected.wav") },
113 { &state.sound_ptr->navy_move_sound,
NATIVE(
"UI_SailMove.wav") },
114 { &state.sound_ptr->navy_select_sound,
NATIVE(
"UI_SailSelected.wav") },
115 { &state.sound_ptr->declaration_of_war_sound,
NATIVE(
"DeclarationofWar.wav") },
116 { &state.sound_ptr->chat_message_sound,
NATIVE(
"GI_ChatMessage.wav") },
117 { &state.sound_ptr->error_sound,
NATIVE(
"GI_ErrorBlip.wav") },
118 { &state.sound_ptr->peace_sound,
NATIVE(
"Misc_Peace.wav") },
119 { &state.sound_ptr->army_built_sound,
NATIVE(
"UI_LandUnitFinished.wav") },
120 { &state.sound_ptr->navy_built_sound,
NATIVE(
"UI_NavalUnitFinished.wav") },
121 { &state.sound_ptr->factory_built_sound,
NATIVE(
"Misc_NewFactory.wav") },
122 { &state.sound_ptr->revolt_sound,
NATIVE(
"Misc_revolt.wav") },
123 { &state.sound_ptr->fort_built_sound,
NATIVE(
"Misc_Fortification.wav") },
124 { &state.sound_ptr->railroad_built_sound,
NATIVE(
"Misc_Infrastructure.wav") },
125 { &state.sound_ptr->naval_base_built_sound,
NATIVE(
"Misc_CoalingStation.wav") },
126 { &state.sound_ptr->minor_event_sound,
NATIVE(
"GI_MinorBlip.wav") },
127 { &state.sound_ptr->major_event_sound,
NATIVE(
"Misc_Attention.wav") },
128 { &state.sound_ptr->decline_sound,
NATIVE(
"GI_FailureBlip.wav") },
129 { &state.sound_ptr->accept_sound,
NATIVE(
"GI_SuccessBlip.wav") },
130 { &state.sound_ptr->diplomatic_request_sound,
NATIVE(
"GI_MessageWindow.wav") },
131 { &state.sound_ptr->election_sound,
NATIVE(
"Misc_ElectionHeld.wav") },
132 { &state.sound_ptr->land_battle_sounds[0],
NATIVE(
"Combat_Cavalry_1.wav") },
133 { &state.sound_ptr->land_battle_sounds[1],
NATIVE(
"Combat_Cavalry_2.wav") },
134 { &state.sound_ptr->land_battle_sounds[2],
NATIVE(
"Combat_Cavalry_3.wav") },
135 { &state.sound_ptr->land_battle_sounds[3],
NATIVE(
"Combat_Infantry_1.wav") },
136 { &state.sound_ptr->land_battle_sounds[4],
NATIVE(
"Combat_Infantry_2.wav") },
137 { &state.sound_ptr->land_battle_sounds[5],
NATIVE(
"Combat_Infantry_3.wav") },
138 { &state.sound_ptr->naval_battle_sounds[0],
NATIVE(
"Combat_MajorShip_1.wav") },
139 { &state.sound_ptr->naval_battle_sounds[1],
NATIVE(
"Combat_MajorShip_2.wav") },
140 { &state.sound_ptr->naval_battle_sounds[2],
NATIVE(
"Combat_MajorShip_3.wav") },
141 { &state.sound_ptr->naval_battle_sounds[3],
NATIVE(
"Combat_MinorShip_1.wav") },
142 { &state.sound_ptr->naval_battle_sounds[4],
NATIVE(
"Combat_MinorShip_2.wav") },
143 { &state.sound_ptr->naval_battle_sounds[5],
NATIVE(
"Combat_MinorShip_3.wav") },
146 for(
const auto& e : vanilla_sound_table) {
153 } new_sound_table[] = {
154 { &state.sound_ptr->click_sound,
NATIVE(
"NU_AltClick.wav") },
155 { &state.sound_ptr->click_left_sound,
NATIVE(
"NU_ClickL.wav") },
156 { &state.sound_ptr->click_right_sound,
NATIVE(
"NU_ClickR.wav") },
157 { &state.sound_ptr->console_open_sound,
NATIVE(
"NU_OpenConsole.wav") },
158 { &state.sound_ptr->console_close_sound,
NATIVE(
"NU_CloseConsole.wav") },
159 { &state.sound_ptr->tab_budget_sound,
NATIVE(
"NU_TabBudget.wav") },
160 { &state.sound_ptr->hover_sound,
NATIVE(
"NU_Hover.wav") },
161 { &state.sound_ptr->checkbox_sound,
NATIVE(
"NU_Checkbox.wav") },
162 { &state.sound_ptr->enact_sound,
NATIVE(
"NU_Enact.wav") },
163 { &state.sound_ptr->subtab_sound,
NATIVE(
"NU_Subtab.wav") },
164 { &state.sound_ptr->delete_sound,
NATIVE(
"NU_Delete.wav") },
165 { &state.sound_ptr->autochoose_sound,
NATIVE(
"NU_Autochoose.wav") },
166 { &state.sound_ptr->tab_politics_sound,
NATIVE(
"NU_TabPolitics.wav") },
167 { &state.sound_ptr->tab_diplomacy_sound,
NATIVE(
"NU_TabDiplomacy.wav") },
168 { &state.sound_ptr->tab_military_sound,
NATIVE(
"NU_TabMilitary.wav") },
169 { &state.sound_ptr->tab_population_sound,
NATIVE(
"NU_TabPopulation.wav") },
170 { &state.sound_ptr->tab_production_sound,
NATIVE(
"NU_TabProduction.wav") },
171 { &state.sound_ptr->tab_technology_sound,
NATIVE(
"NU_TabTechnology.wav") },
172 { &state.sound_ptr->tab_military_sound,
NATIVE(
"NU_TabMilitary.wav") },
173 { &state.sound_ptr->event_sound,
NATIVE(
"NU_Event.wav") },
174 { &state.sound_ptr->decision_sound,
NATIVE(
"NU_Decision.wav") },
175 { &state.sound_ptr->pause_sound,
NATIVE(
"NU_Pause.wav") },
176 { &state.sound_ptr->unpause_sound,
NATIVE(
"NU_Unpause.wav") },
177 { &state.sound_ptr->province_select_sounds[0],
NATIVE(
"NU_ProvSelect1.wav") },
178 { &state.sound_ptr->province_select_sounds[1],
NATIVE(
"NU_ProvSelect2.wav") },
179 { &state.sound_ptr->province_select_sounds[2],
NATIVE(
"NU_ProvSelect3.wav") },
180 { &state.sound_ptr->province_select_sounds[3],
NATIVE(
"NU_ProvSelect4.wav") },
183 for(
const auto& e : new_sound_table) {
189 state.sound_ptr->set_volume(state.sound_ptr->effect_sound, v);
192 state.sound_ptr->set_volume(state.sound_ptr->interface_sound, v);
195 state.sound_ptr->set_volume(state.sound_ptr->music, v);
199 if(state.sound_ptr->global_pause)
201 state.sound_ptr->override_sound(state.sound_ptr->effect_sound, s, volume);
204 if(state.sound_ptr->global_pause)
206 state.sound_ptr->override_sound(state.sound_ptr->interface_sound, s, volume);
210 if(state.sound_ptr->music.has_value()) {
211 ma_sound_stop(&*state.sound_ptr->music);
215 if(v > 0.0f && state.sound_ptr->music_list.size() != 0) {
216 if(state.sound_ptr->first_music != -1) {
217 state.sound_ptr->play_music(state.sound_ptr->first_music, v);
219 if(state.sound_ptr->music.has_value()) {
220 ma_sound_start(&*state.sound_ptr->music);
227 if(state.sound_ptr.get()) {
228 state.sound_ptr->global_pause =
true;
229 if(state.sound_ptr->effect_sound.has_value()) {
230 ma_sound_stop(&*state.sound_ptr->effect_sound);
232 if(state.sound_ptr->interface_sound.has_value()) {
233 ma_sound_stop(&*state.sound_ptr->interface_sound);
235 if(state.sound_ptr->music.has_value()) {
236 ma_sound_stop(&*state.sound_ptr->music);
241 if(state.sound_ptr.get()) {
242 state.sound_ptr->global_pause =
false;
243 if(state.sound_ptr->effect_sound.has_value()) {
244 ma_sound_start(&*state.sound_ptr->effect_sound);
246 if(state.sound_ptr->interface_sound.has_value()) {
247 ma_sound_start(&*state.sound_ptr->interface_sound);
249 if(state.sound_ptr->music.has_value()) {
250 ma_sound_start(&*state.sound_ptr->music);
256 if(state.sound_ptr->music_finished()) {
257 state.sound_ptr->play_new_track(state);
264 return state.sound_ptr->click_sound;
267 return state.sound_ptr->click_left_sound;
270 return state.sound_ptr->click_right_sound;
273 return state.sound_ptr->tab_budget_sound;
276 return state.sound_ptr->hover_sound;
279 return state.sound_ptr->checkbox_sound;
282 return state.sound_ptr->enact_sound;
285 return state.sound_ptr->subtab_sound;
288 return state.sound_ptr->delete_sound;
291 return state.sound_ptr->autochoose_sound;
294 return state.sound_ptr->tab_politics_sound;
297 return state.sound_ptr->tab_diplomacy_sound;
300 return state.sound_ptr->tab_military_sound;
303 return state.sound_ptr->tab_population_sound;
306 return state.sound_ptr->tab_production_sound;
309 return state.sound_ptr->tab_technology_sound;
312 return state.sound_ptr->army_select_sound;
315 return state.sound_ptr->army_move_sound;
318 return state.sound_ptr->navy_select_sound;
321 return state.sound_ptr->navy_move_sound;
324 return state.sound_ptr->error_sound;
327 return state.sound_ptr->peace_sound;
330 return state.sound_ptr->army_built_sound;
333 return state.sound_ptr->navy_built_sound;
336 return state.sound_ptr->declaration_of_war_sound;
339 return state.sound_ptr->technology_finished_sound;
342 return state.sound_ptr->factory_built_sound;
345 return state.sound_ptr->election_sound;
348 return state.sound_ptr->revolt_sound;
351 return state.sound_ptr->fort_built_sound;
354 return state.sound_ptr->railroad_built_sound;
357 return state.sound_ptr->naval_base_built_sound;
360 return state.sound_ptr->minor_event_sound;
363 return state.sound_ptr->major_event_sound;
366 return state.sound_ptr->decline_sound;
369 return state.sound_ptr->accept_sound;
372 return state.sound_ptr->diplomatic_request_sound;
375 return state.sound_ptr->chat_message_sound;
378 return state.sound_ptr->console_open_sound;
381 return state.sound_ptr->console_close_sound;
385 return state.sound_ptr->event_sound;
388 return state.sound_ptr->decision_sound;
391 return state.sound_ptr->pause_sound;
394 return state.sound_ptr->unpause_sound;
398 return state.sound_ptr->land_battle_sounds[int32_t(std::rand() % 6)];
401 return state.sound_ptr->naval_battle_sounds[int32_t(std::rand() % 6)];
404 return state.sound_ptr->province_select_sounds[int32_t(std::rand() % 4)];
408 state.sound_ptr->play_new_track(state);
411 state.sound_ptr->play_next_track(state);
414 state.sound_ptr->play_previous_track(state);
418 if(state.sound_ptr->music.has_value())
419 return state.sound_ptr->music_list[state.sound_ptr->current_music].filename;
void set_volume(std::optional< ma_sound > &sound, float volume)
void play_music(int32_t track, float volume)
std::vector< audio_instance > music_list
void play_new_track(sys::state &ws)
void play_previous_track(sys::state &ws)
void play_next_track(sys::state &ws)
std::optional< ma_sound > music
void override_sound(std::optional< ma_sound > &sound, audio_instance &s, float volume)
bool native_has_fixed_suffix_ci(char const *start, char const *end, char const (&t)[N])
std::vector< unopened_file > list_files(directory const &dir, native_char const *extension)
std::vector< directory > list_subdirectories(directory const &dir)
directory open_directory(directory const &dir, native_string_view directory_name)
directory get_root(file_system const &fs)
native_string get_full_name(directory const &f)
std::optional< unopened_file > peek_file(directory const &dir, native_string_view file_name)
audio_instance & get_peace_sound(sys::state &state)
audio_instance & get_minor_event_sound(sys::state &state)
void pause_all(sys::state &state)
audio_instance & get_revolt_sound(sys::state &state)
audio_instance & get_hover_sound(sys::state &state)
void initialize_sound_system(sys::state &state)
audio_instance & get_tab_population_sound(sys::state &state)
void resume_all(sys::state &state)
audio_instance & get_tab_production_sound(sys::state &state)
audio_instance & get_army_built_sound(sys::state &state)
audio_instance & get_event_sound(sys::state &state)
audio_instance & get_decision_sound(sys::state &state)
audio_instance & get_tab_budget_sound(sys::state &state)
audio_instance & get_accept_sound(sys::state &state)
void play_next_track(sys::state &state)
void update_music_track(sys::state &state)
audio_instance & get_technology_finished_sound(sys::state &state)
void change_effect_volume(sys::state &state, float v)
audio_instance & get_enact_sound(sys::state &state)
audio_instance & get_declaration_of_war_sound(sys::state &state)
audio_instance & get_console_open_sound(sys::state &state)
audio_instance & get_console_close_sound(sys::state &state)
audio_instance & get_tab_technology_sound(sys::state &state)
void stop_music(sys::state &state)
audio_instance & get_delete_sound(sys::state &state)
audio_instance & get_unpause_sound(sys::state &state)
audio_instance & get_click_left_sound(sys::state &state)
void change_interface_volume(sys::state &state, float v)
audio_instance & get_random_land_battle_sound(sys::state &state)
audio_instance & get_click_right_sound(sys::state &state)
audio_instance & get_naval_base_built_sound(sys::state &state)
audio_instance & get_tab_politics_sound(sys::state &state)
audio_instance & get_major_event_sound(sys::state &state)
native_string get_current_track_name(sys::state &state)
audio_instance & get_random_province_select_sound(sys::state &state)
audio_instance & get_railroad_built_sound(sys::state &state)
audio_instance & get_navy_move_sound(sys::state &state)
void play_effect(sys::state &state, audio_instance &s, float volume)
audio_instance & get_random_naval_battle_sound(sys::state &state)
audio_instance & get_pause_sound(sys::state &state)
void play_previous_track(sys::state &state)
audio_instance & get_navy_select_sound(sys::state &state)
audio_instance & get_checkbox_sound(sys::state &state)
void start_music(sys::state &state, float v)
audio_instance & get_decline_sound(sys::state &state)
audio_instance & get_election_sound(sys::state &state)
audio_instance & get_navy_built_sound(sys::state &state)
void play_new_track(sys::state &state)
audio_instance & get_army_select_sound(sys::state &state)
audio_instance & get_fort_built_sound(sys::state &state)
void play_interface_sound(sys::state &state, audio_instance &s, float volume)
audio_instance & get_diplomatic_request_sound(sys::state &state)
audio_instance & get_chat_message_sound(sys::state &state)
audio_instance & get_tab_diplomacy_sound(sys::state &state)
audio_instance & get_click_sound(sys::state &state)
audio_instance & get_error_sound(sys::state &state)
audio_instance & get_subtab_sound(sys::state &state)
void change_music_volume(sys::state &state, float v)
audio_instance & get_autochoose_sound(sys::state &state)
audio_instance & get_factory_built_sound(sys::state &state)
audio_instance & get_army_move_sound(sys::state &state)
audio_instance & get_tab_military_sound(sys::state &state)
std::string_view native_string_view
std::string native_string
user_settings_s user_settings