From e3dcadd5dd9bde8511df5e9d31f331a27da62859 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Mon, 29 Jun 2026 14:01:22 +0900 Subject: [PATCH] Allow the volume dialog to work without VolumeValancer When a game defines no VolumeValancer[], fall back to two generic channels so BGM and sound effects can be adjusted independently. Volume controls are now always available, so drop the conditional menu handling. --- po/POTFILES.in | 1 + po/ja.gmo | Bin 1772 -> 858 bytes po/ja.po | 8 +++++++ src/menu_sdl.c | 6 ++--- src/music.h | 4 ++++ src/music_private.h | 4 +--- src/pcm.sdlmixer.c | 6 ++--- src/volume.c | 55 ++++++++++++++++++-------------------------- src/volume.h | 10 +++----- src/win/menubar.c | 2 -- 10 files changed, 45 insertions(+), 51 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 2653840..f076a09 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1 +1,2 @@ ./src/menu_sdl.c +./src/volume.c diff --git a/po/ja.gmo b/po/ja.gmo index 765caeccce1494374c24af948a62dfc5819ae0bb..eb33d464bc718062a75f1002444006a993d87988 100644 GIT binary patch delta 557 zcmXxfO-ma=7zgmjW)q{WRNJFHjBULch@qG!P^wMDLs=~KrI%iob*!l|o4UKwf)L%o z)|ca=?IEbpmVzP{f`_)Dhkk*AM-dUGNf87;g8s+E2OfSqJNtiT_O#_7R5-e&trF@6 z`VM*)-G)9yt6~jA0oVaUuoDJh7t~-3s%#wIglTvU4#O7s0^Wuks{A{sa&z!u0~Kfi z59)y5NT~sTU=!SjDsTwfp{#pef8UOf`tB}lglN!#~zu-dC5C-i{QXr6@`7mlWG{ zvbH4WKS^(e{_lDJe!ln5gNesy<=wOLHdU5?RM(3q8zrh1=PF;msXJBIK2&x-k`zTL SwxswfMOlhXtT(O}i*y0=pMli? literal 1772 zcmZ{iT}&KR6vwYxtFHA6>vyg5;zMI*U095`tsmP3(v>a{prpQeSuV@K?#yQ94xw+| z9k5Umtr$dWV_OTQ7E7r{EoHSP>WfV@K5Oj5b(cOg;n_F;XLhzUK~Lt+@1Aq-x%ZrN z&tG+0W*Fo-j2#%;?_g{fxb05-Aj{z0;3e>W@LO;z_#?Ol`~`dn{0-a&UJrOP;6EVw zZN00?I*|771ZjU541v3Y^;Yl!=v^RO+1sE7ra^pcEU-@moC5EI{auj!J_7Nvv-sTu zo(C!ZF9ZAKfF+RP{~=iaIp8&L2sQW}q&)Y)c{`W@Dei+H*#|)lv_QK5Sis`}=RnGD z2_(N&@L}*;p#KRz3jHSd3`mC(cYt(W6Sx!H3*uuu;9x)ttb=_7B)`ePJ`a-r7a&q# z-vs)VfIop0*RR3)AAx=yMB2X4y(CX!P|S~DJcaQr#^V^&CnOJ6;n$a9p!=T2pz}%S zJ?IVS9VsS?m*idyswvf+m(jfl_-?FE8E>%pRlX*ZfP54hNa>M zwdeb_^dPsn#2V=vO0qc_gpd-B!!x3L*vPY#X9bBp;2py z#-a@`L|%zRuu<<4BL-c&d0%~FtT9sEx1T#w@3Fb*WVy8Ln3mX=Y>TJjT8iUhL)-J; zfxH&l&&`aBQtLf}=VIEMJkL$xi2rv;B~vXMm8cI#LJ7;1!o>B5^2kGqQTbv%%MEk4 z|Fn*fuO8@W)tffv1-bG`Kbt=aUg*$1pL zvs^wrS00})AN_c)Ra!+})OnING;#uFcNXZqyLndnrtL3Q~rV3;JH^FY4TU{?rmdDTCSeUNfr3y=` zaJ6z`vV3%ft&N=~td}mXmlhF{Z$zJO4&;RLP{Vn@jHi@$OnIOC^;^MZ7jYS@%zjp0 kI*tM`style->size.y + ctx->style->padding * 2; int w = 200; // `rows` rows with (rows - 1) inter-row gaps, plus the window's body padding. @@ -100,7 +98,7 @@ static bool menu_build(mu_Context *ctx, modal *modal) { if (mu_checkbox(ctx, _("Mouse Auto Move"), &warp)) nact->ags.mouse_warp_enabled = warp; - if (has_volume && mu_button(ctx, _("Volume"))) { + if (mu_button(ctx, _("Volume"))) { keep_open = false; st->action = MENU_ACTION_VOLUME; } diff --git a/src/music.h b/src/music.h index 33c1f24..bde4c13 100644 --- a/src/music.h +++ b/src/music.h @@ -36,6 +36,10 @@ enum MixDevice { MIX_PCM }; +// Volume valancer channels. +#define BGM_VOLVAL_CH 0 // BGM is always mapped to this channel. +#define SE_VOLVAL_CH 1 // Sound-effect channel used when the game defines no VolumeValancer. + /* init and exit */ bool mus_init(int audio_buffer_size); void mus_exit(void); diff --git a/src/music_private.h b/src/music_private.h index 0e21b3e..9e7045a 100644 --- a/src/music_private.h +++ b/src/music_private.h @@ -23,6 +23,7 @@ #define __MUSIC_PRIVATE_H__ #include "portab.h" +#include "music.h" #include "bgm.h" #include "cdrom.h" #include "midi.h" @@ -31,9 +32,6 @@ #include "music_pcm.h" #include "ald_manager.h" -// The volume valancer channel that BGM is mapped to. -#define BGM_VOLVAL_CH 0 - struct _musprvdat { bool midi_valid; bool pcm_valid; diff --git a/src/pcm.sdlmixer.c b/src/pcm.sdlmixer.c index 241e92b..2349005 100644 --- a/src/pcm.sdlmixer.c +++ b/src/pcm.sdlmixer.c @@ -181,7 +181,7 @@ bool muspcm_load_no(int slot, int no) { int ch = WAIMIXCH(no); prv.vol_pcm_sub[slot] = ch < 0 ? 0: ch; } else { - prv.vol_pcm_sub[slot] = 0; + prv.vol_pcm_sub[slot] = SE_VOLVAL_CH; } return load_chunk(slot, chunk); @@ -209,7 +209,7 @@ bool muspcm_load_mixlr(int slot, int noL, int noR) { if (chunk == NULL) { return false; } - prv.vol_pcm_sub[slot] = 0; + prv.vol_pcm_sub[slot] = SE_VOLVAL_CH; return load_chunk(slot, chunk); } @@ -221,7 +221,7 @@ bool muspcm_load_data(int slot, uint8_t *buf, uint32_t len) { Mix_Chunk *chunk = Mix_LoadWAV_RW(SDL_RWFromConstMem(buf, len), 1); if (!chunk) return false; - prv.vol_pcm_sub[slot] = 0; + prv.vol_pcm_sub[slot] = SE_VOLVAL_CH; return load_chunk(slot, chunk); } diff --git a/src/volume.c b/src/volume.c index e515bef..239ea85 100644 --- a/src/volume.c +++ b/src/volume.c @@ -45,15 +45,8 @@ struct volume_channel { static int vval_max; // 最大チャンネル番号 static struct volume_channel vval[MAXVOLCH]; -static bool vval_available; - -bool volume_available(void) { - return vval_available; -} static void apply_volume(void) { - if (!vval_available) return; - int vol[MAXVOLCH] = {0}; for (int i = 0; i < MAXVOLCH; i++) { vol[i] = vval[i].mute ? 0 : vval[i].vol; @@ -62,28 +55,34 @@ static void apply_volume(void) { } // 初期化 -bool volume_init(void) { - FILE *fp; - char s[256], s1[256]; +void volume_init(void) { int i, vol[MAXVOLCH] = {0}; char fn[256]; + int nvalancer = 0; - if (nact->files.init == NULL) return false; - - if (NULL == (fp = fopen(nact->files.init, "r"))) return false; - - while (fgets(s, 255, fp) != NULL) { - s1[0] = '\0'; - sscanf(s, "VolumeValancer[%d] = \"%s", &i, s1); - if (s1[0] == '\0') continue; - if (i >= MAXVOLCH || i < 0) continue; - s1[strlen(s1)-1] = '\0'; // remove last '"' - vval[i].label = sjis2utf(s1); - vval_max = max(vval_max, i); - //WARNING("VolumeValancer[%d] = %s", i, vval[i].label); + FILE *fp = nact->files.init ? fopen(nact->files.init, "r") : NULL; + if (fp) { + char s[256], s1[256]; + while (fgets(s, 255, fp) != NULL) { + s1[0] = '\0'; + sscanf(s, "VolumeValancer[%d] = \"%s", &i, s1); + if (s1[0] == '\0') continue; + if (i >= MAXVOLCH || i < 0) continue; + s1[strlen(s1)-1] = '\0'; // remove last '"' + vval[i].label = sjis2utf(s1); + vval_max = max(vval_max, i); + nvalancer++; + } + fclose(fp); } - if (vval_max <= 0) return false; + if (nvalancer == 0) { + // No VolumeValancer[] is defined (or there is no System39.ini). Fall back + // to two generic channels that control BGM and sound effects separately. + vval[BGM_VOLVAL_CH].label = strdup(_("BGM")); + vval[SE_VOLVAL_CH].label = strdup(_("Sound effects")); + vval_max = SE_VOLVAL_CH; + } // Volume.sav があればそれを読み込む snprintf(fn, sizeof(fn) -1, "%s/Volume.sav", nact->files.save_path); @@ -101,10 +100,6 @@ bool volume_init(void) { } // どちらにしても music server に送る mus_vol_set_valance(vol, MAXVOLCH); - - vval_available = vval_max > 0; - - return true; } // Volume Valance をセーブ @@ -112,8 +107,6 @@ void volume_save(void) { int vol[MAXVOLCH] = {0}; char fn[256]; - if (!vval_available) return; - for (int i = 0; i < MAXVOLCH; i++) { vol[i] = vval[i].vol; } @@ -203,8 +196,6 @@ static bool volume_build(mu_Context *ctx, modal *modal) { } void volume_dialog_open(void) { - if (!vval_available) - return; struct volume_state st = { .base = { .build = volume_build, .handler = modal_default_handler }, }; diff --git a/src/volume.h b/src/volume.h index b7c0c4e..4170ba1 100644 --- a/src/volume.h +++ b/src/volume.h @@ -25,17 +25,13 @@ #include -// Reads System39.ini / Volume.sav and applies the volumes. Returns true if the -// game defines any volume channels. -bool volume_init(void); +// Reads System39.ini / Volume.sav and applies the volumes. +void volume_init(void); // Saves the current volumes to Volume.sav (called at exit). void volume_save(void); -// True if the loaded game defines any volume channels. -bool volume_available(void); - -// Opens the modal volume controller dialog. No-op if no channels are defined. +// Opens the modal volume controller dialog. void volume_dialog_open(void); #endif /* __VOLUME_H__ */ diff --git a/src/win/menubar.c b/src/win/menubar.c index 8c50f87..77a5055 100644 --- a/src/win/menubar.c +++ b/src/win/menubar.c @@ -86,8 +86,6 @@ void win_menu_init(void) { // Let SDL recalc the window size, taking menu height into account. SDL_SetWindowSize(gfx_window, view_w, view_h); CheckMenuItem(hmenu, ID_OPTION_MOUSE_MOVE, MF_BYCOMMAND | MFS_CHECKED); - if (!volume_available()) - EnableMenuItem(hmenu, ID_OPTION_SOUND, MF_BYCOMMAND | MF_GRAYED); } void win_menu_onSysWMEvent(SDL_SysWMmsg* msg) {