Skip to content

Commit d78c202

Browse files
authored
Add Force stereo for 2SID setting (#18)
1 parent e761c26 commit d78c202

4 files changed

Lines changed: 67 additions & 12 deletions

File tree

src/config.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub struct Config {
3131
pub last_songlength_file: Option<String>,
3232
/// Last directory used for playlists.
3333
pub last_playlist_dir: Option<String>,
34+
/// Force stereo mirroring for 2SID tunes (duplicate SID1 writes to SID2).
35+
/// When enabled, 2SID tunes play in mono-stereo mode instead of true dual-SID.
36+
pub force_stereo_2sid: bool,
3437
}
3538

3639
impl Default for Config {
@@ -46,6 +49,7 @@ impl Default for Config {
4649
last_songlength_dir: None,
4750
last_songlength_file: None,
4851
last_playlist_dir: None,
52+
force_stereo_2sid: false,
4953
}
5054
}
5155
}
@@ -155,6 +159,9 @@ impl Config {
155159
if val != "null" {
156160
config.last_playlist_dir = strip_json_string(val);
157161
}
162+
} else if let Some(rest) = line.strip_prefix("\"force_stereo_2sid\"") {
163+
let val = rest.trim().trim_start_matches(':').trim();
164+
config.force_stereo_2sid = val == "true";
158165
}
159166
}
160167

@@ -181,7 +188,8 @@ impl Config {
181188
" \"last_sid_dir\": {},\n",
182189
" \"last_songlength_dir\": {},\n",
183190
" \"last_songlength_file\": {},\n",
184-
" \"last_playlist_dir\": {}\n",
191+
" \"last_playlist_dir\": {},\n",
192+
" \"force_stereo_2sid\": {}\n",
185193
"}}\n",
186194
),
187195
self.skip_rsid,
@@ -194,6 +202,7 @@ impl Config {
194202
fmt_opt(&self.last_songlength_dir),
195203
fmt_opt(&self.last_songlength_file),
196204
fmt_opt(&self.last_playlist_dir),
205+
self.force_stereo_2sid,
197206
)
198207
}
199208

src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,11 @@ impl App {
612612
self.config.save();
613613
}
614614

615+
Message::ToggleForceStereo2sid => {
616+
self.config.force_stereo_2sid = !self.config.force_stereo_2sid;
617+
self.config.save();
618+
}
619+
615620
Message::DefaultSongLengthChanged(val) => {
616621
self.default_length_text = val.clone();
617622
// Parse and apply the value
@@ -965,7 +970,8 @@ impl App {
965970
self.selected = Some(idx);
966971
self.scroll_to_current = true;
967972

968-
let force_stereo = std::env::args().any(|a| a == "--stereo");
973+
let force_stereo =
974+
self.config.force_stereo_2sid || std::env::args().any(|a| a == "--stereo");
969975
let sid4_addr = parse_sid4_from_args();
970976

971977
let _ = self.cmd_tx.send(PlayerCmd::Play {

src/player/mod.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ fn setup_playback(
726726
sid_file: SidFile,
727727
path: PathBuf,
728728
song: u16,
729-
_force_stereo: bool,
729+
force_stereo: bool,
730730
sid4_addr: u16,
731731
is_rsid: bool,
732732
bridge: &mut Option<Box<dyn SidDevice>>,
@@ -749,22 +749,35 @@ fn setup_playback(
749749
// Always use stereo mode — mono tunes get mirrored to both channels
750750
// so sound comes from both speakers.
751751
let use_stereo = true;
752-
let mono_mode = !is_multi;
753-
let mirror_mono = mono_mode; // always mirror single-SID tunes
754-
755-
let mapper = SidMapper::new(&sid_bases);
752+
// force_stereo: treat 2SID tunes as mono (mirror SID1 to both channels,
753+
// ignoring the second SID). Only applies to exactly 2-SID tunes;
754+
// 3SID/4SID tunes always use their native multi-SID layout.
755+
let force_mono_2sid = force_stereo && num_sids == 2;
756+
let mono_mode = !is_multi || force_mono_2sid;
757+
let mirror_mono = mono_mode; // mirror single-SID tunes (and forced-stereo 2SID)
758+
759+
// When forcing stereo on a 2SID tune, use only the base SID for mapping
760+
let mapper = if force_mono_2sid {
761+
SidMapper::new(&sid_bases[..1])
762+
} else {
763+
SidMapper::new(&sid_bases)
764+
};
756765
let frame_us = header.frame_us();
757766
let cycles_per_frame = if header.is_pal {
758767
PAL_CYCLES_PER_FRAME
759768
} else {
760769
NTSC_CYCLES_PER_FRAME
761770
};
762771

763-
let sid_type = match num_sids {
764-
1 => "Mono".to_string(),
765-
2 => "2SID Stereo".to_string(),
766-
3 => "3SID".to_string(),
767-
n => format!("{}SID", n),
772+
let sid_type = if force_mono_2sid {
773+
"2SID → Stereo (forced mono)".to_string()
774+
} else {
775+
match num_sids {
776+
1 => "Mono".to_string(),
777+
2 => "2SID Stereo".to_string(),
778+
3 => "3SID".to_string(),
779+
n => format!("{}SID", n),
780+
}
768781
};
769782

770783
let md5 = compute_hvsc_md5(&sid_file);

src/ui/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub enum Message {
7979
// Settings
8080
ToggleSettings,
8181
ToggleSkipRsid,
82+
ToggleForceStereo2sid,
8283
DefaultSongLengthChanged(String),
8384
SonglengthUrlChanged(String),
8485
DownloadSonglength,
@@ -1003,6 +1004,30 @@ pub fn settings_panel<'a>(
10031004

10041005
let rsid_section = column![rsid_label, rsid_toggle, rsid_help].spacing(6);
10051006

1007+
// ── Force stereo for 2SID tunes ──────────────────────────────
1008+
let stereo_2sid_label = text("Force stereo for 2SID tunes:")
1009+
.size(14)
1010+
.color(Color::from_rgb(0.75, 0.77, 0.82));
1011+
1012+
let stereo_2sid_toggle = tool_button(
1013+
if config.force_stereo_2sid {
1014+
"✓ Yes — mirror SID1 to both channels"
1015+
} else {
1016+
"✗ No — true dual-SID (L=SID1, R=SID2)"
1017+
},
1018+
Message::ToggleForceStereo2sid,
1019+
);
1020+
1021+
let stereo_2sid_help = text(
1022+
"When enabled, 2SID tunes ignore the second SID and mirror SID1 to both speakers \
1023+
(same as mono). Disable for true stereo separation on dual-SID hardware.",
1024+
)
1025+
.size(11)
1026+
.color(Color::from_rgb(0.45, 0.47, 0.52));
1027+
1028+
let stereo_2sid_section =
1029+
column![stereo_2sid_label, stereo_2sid_toggle, stereo_2sid_help].spacing(6);
1030+
10061031
// ── Default song length ──────────────────────────────────────
10071032
let length_label = text("Default song length (seconds):")
10081033
.size(14)
@@ -1097,6 +1122,8 @@ pub fn settings_panel<'a>(
10971122
rule::horizontal(1),
10981123
rsid_section,
10991124
rule::horizontal(1),
1125+
stereo_2sid_section,
1126+
rule::horizontal(1),
11001127
length_section,
11011128
rule::horizontal(1),
11021129
dl_section,

0 commit comments

Comments
 (0)