pinready 0.27.8

Cross-platform configurator and launcher supporting the adoption of Visual Pinball 10.8.1 — for testers and early adopters, not a replacement for a stable production setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
use super::*;

impl App {
    pub(super) fn render_audio_page(&mut self, ui: &mut egui::Ui) {
        theme::page_header(ui, &t!("audio_heading"), Some(&t!("audio_intro")));
        theme::section(
            ui,
            &t!("audio_device_assignment"),
            Some(&t!("audio_devices_intro")),
            |ui| {
                // 3-jack repurposing tip — shown for all modes (stereo users may
                // want to upgrade). OS-specific tool name + link to a README
                // with details + screenshots.
                #[cfg(target_os = "linux")]
                let (tool, url) = (
                    "hdajackretask",
                    "https://github.com/Le-Syl21/PinReady/tree/main/audiomapping_linux",
                );
                #[cfg(target_os = "windows")]
                let (tool, url) = (
                    "Realtek HD Audio Manager",
                    "https://github.com/Le-Syl21/PinReady/tree/main/audiomapping_windows",
                );
                #[cfg(target_os = "macos")]
                let (tool, url) = (
                    "Audio MIDI Setup",
                    "https://github.com/Le-Syl21/PinReady/tree/main/audiomapping_mac",
                );
                ui.horizontal_wrapped(|ui| {
                    ui.colored_label(
                        theme::pal(ui.ctx()).warning,
                        t!("audio_3jack_tip", tool = tool),
                    );
                    ui.hyperlink_to(t!("audio_3jack_tip_more_info"), url);
                });
                ui.add_space(8.0);

                // Device assignment

                egui::Grid::new("audio_devices")
                    .min_col_width(150.0)
                    .show(ui, |ui| {
                        ui.horizontal(|ui| {
                            ui.label(t!("audio_backglass"));
                            help_marker(ui, &t!("audio_device_bg_hint"));
                        });
                        egui::ComboBox::from_id_salt("device_bg")
                            .selected_text(if self.audio.device_bg.is_empty() {
                                t!("audio_default_device").to_string()
                            } else {
                                self.audio.device_bg.clone()
                            })
                            .show_ui(ui, |ui| {
                                ui.selectable_value(
                                    &mut self.audio.device_bg,
                                    String::new(),
                                    t!("audio_default_device"),
                                );
                                for dev in &self.audio.available_devices {
                                    ui.selectable_value(
                                        &mut self.audio.device_bg,
                                        dev.clone(),
                                        dev,
                                    );
                                }
                            });
                        ui.end_row();

                        ui.horizontal(|ui| {
                            ui.label(t!("audio_playfield"));
                            help_marker(ui, &t!("audio_device_pf_hint"));
                        });
                        egui::ComboBox::from_id_salt("device_pf")
                            .selected_text(if self.audio.device_pf.is_empty() {
                                t!("audio_default_device").to_string()
                            } else {
                                self.audio.device_pf.clone()
                            })
                            .show_ui(ui, |ui| {
                                ui.selectable_value(
                                    &mut self.audio.device_pf,
                                    String::new(),
                                    t!("audio_default_device"),
                                );
                                for dev in &self.audio.available_devices {
                                    ui.selectable_value(
                                        &mut self.audio.device_pf,
                                        dev.clone(),
                                        dev,
                                    );
                                }
                            });
                        ui.end_row();
                    });

                // Auto-detect the playfield device's native channel count and
                // pre-select the matching Sound3D mode. Stereo → mode 1 (rear
                // stereo). 5.1 → mode 3 (surround front at lockbar). 7.1 →
                // mode 5 (SSF new). The user can still override with the
                // radio buttons below.
                //
                // Two trigger conditions:
                //   1. The user picks a different playfield device (run again).
                //   2. The ini didn't provide a `Sound3D` value (typically a
                //      first-install with no ini yet) — fall back to detection
                //      so the user lands on a sensible default instead of the
                //      hard-coded FrontStereo enum default. Cleared after the
                //      first run so we don't keep overriding the user's later
                //      manual radio-button picks.
                let device_changed = self.audio.device_pf != self.audio.prev_device_pf;
                let need_first_detect = !self.audio.sound_3d_from_ini;
                if device_changed || need_first_detect {
                    self.audio.prev_device_pf = self.audio.device_pf.clone();
                    self.audio.sound_3d_from_ini = true;
                    if let Some(channels) =
                        AudioConfig::detect_native_channels(&self.audio.device_pf)
                    {
                        let suggested = AudioConfig::recommended_sound_3d_mode(channels);
                        log::info!(
                            "Audio: device '{}' reports {} channels → suggesting Sound3D mode {:?}",
                            self.audio.device_pf,
                            channels,
                            suggested
                        );
                        self.audio.sound_3d_mode = suggested;
                    }
                }
            },
        );

        // Sound3D mode, and the wiring it asks for
        theme::section(
            ui,
            &t!("audio_output_mode"),
            Some(&t!("audio_mode_intro")),
            |ui| {
                help_marker(ui, &t!("audio_mode_help"));
                for mode in Sound3DMode::all() {
                    let hint = match *mode {
                        Sound3DMode::FrontStereo => t!("audio_mode_front_stereo_hint"),
                        Sound3DMode::RearStereo => t!("audio_mode_rear_stereo_hint"),
                        Sound3DMode::SurroundRearLockbar => t!("audio_mode_surround_rear_hint"),
                        Sound3DMode::SurroundFrontLockbar => t!("audio_mode_surround_front_hint"),
                        Sound3DMode::SsfLegacy => t!("audio_mode_ssf_legacy_hint"),
                        Sound3DMode::SsfNew => t!("audio_mode_ssf_new_hint"),
                    };
                    ui.radio_value(&mut self.audio.sound_3d_mode, *mode, t!(mode.label()))
                        .on_hover_text(hint);
                }

                // Wiring guide based on selected mode
                ui.add_space(10.0);
                theme::field_label(ui, &t!("audio_wiring_required"));
                ui.add_space(4.0);

                match self.audio.sound_3d_mode {
                    Sound3DMode::FrontStereo | Sound3DMode::RearStereo => {
                        ui.label(t!("audio_card_stereo"));
                        ui.label(format!("  {}", t!("audio_wiring_stereo_front")));
                        ui.label(format!("  {}", t!("audio_wiring_stereo_no_spatial")));
                    }
                    Sound3DMode::SurroundRearLockbar => {
                        ui.label(t!("audio_card_51"));
                        ui.label(format!("  {}", t!("audio_wiring_51_front_top")));
                        ui.label(format!("  {}", t!("audio_wiring_51_rear_bottom")));
                        ui.label(format!("  {}", t!("audio_wiring_51_center_sub")));
                        ui.label(format!("  {}", t!("audio_wiring_51_bg_separate")));
                    }
                    Sound3DMode::SurroundFrontLockbar => {
                        ui.label(t!("audio_card_51"));
                        ui.label(format!("  {}", t!("audio_wiring_51_front_bottom")));
                        ui.label(format!("  {}", t!("audio_wiring_51_rear_top")));
                        ui.label(format!("  {}", t!("audio_wiring_51_center_sub")));
                        ui.label(format!("  {}", t!("audio_wiring_51_bg_separate")));
                    }
                    Sound3DMode::SsfLegacy | Sound3DMode::SsfNew => {
                        ui.label(t!("audio_card_71"));
                        ui.add_space(4.0);
                        egui::Grid::new("wiring_grid")
                            .striped(true)
                            .min_col_width(120.0)
                            .show(ui, |ui| {
                                ui.strong(t!("audio_wiring_col_output"));
                                ui.strong(t!("audio_wiring_col_channel"));
                                ui.strong(t!("audio_wiring_col_connection"));
                                ui.end_row();

                                ui.label(t!("audio_wiring_71_green"));
                                ui.label(t!("audio_wiring_71_green_ch"));
                                ui.label(t!("audio_wiring_71_green_conn"));
                                ui.end_row();

                                ui.label(t!("audio_wiring_71_black"));
                                ui.label(t!("audio_wiring_71_black_ch"));
                                ui.label(t!("audio_wiring_71_black_conn"));
                                ui.end_row();

                                ui.label(t!("audio_wiring_71_grey"));
                                ui.label(t!("audio_wiring_71_grey_ch"));
                                ui.label(t!("audio_wiring_71_grey_conn"));
                                ui.end_row();

                                ui.label(t!("audio_wiring_71_orange"));
                                ui.label(t!("audio_wiring_71_orange_ch"));
                                ui.label(t!("audio_wiring_71_orange_conn"));
                                ui.end_row();
                            });
                        ui.add_space(4.0);
                        ui.label(t!("audio_wiring_note"));
                    }
                }
            },
        );

        // Volumes
        theme::section(ui, &t!("audio_volumes"), None, |ui| {
            egui::Grid::new("audio_volumes")
                .min_col_width(150.0)
                .show(ui, |ui| {
                    ui.horizontal(|ui| {
                        ui.label(t!("audio_music_volume"));
                        help_marker(ui, &t!("audio_music_volume_hint"));
                    });
                    ui.add(egui::Slider::new(&mut self.audio.music_volume, 0..=100).suffix("%"));
                    ui.end_row();

                    ui.horizontal(|ui| {
                        ui.label(t!("audio_sound_volume"));
                        help_marker(ui, &t!("audio_sound_volume_hint"));
                    });
                    ui.add(egui::Slider::new(&mut self.audio.sound_volume, 0..=100).suffix("%"));
                    ui.end_row();
                });
        });

        // === Tests audio ===
        theme::section(
            ui,
            &t!("audio_section_test"),
            Some(&t!("audio_section_test_intro")),
            |ui| {
                theme::field_label(ui, &t!("audio_test_music"));
                ui.add_space(4.0);
                ui.horizontal(|ui| {
                    let music_label = if self.audio.music_looping {
                        "[Stop]"
                    } else {
                        "[Play]"
                    };
                    if ui
                        .button(music_label)
                        .on_hover_text(t!("audio_test_music_btn_hint"))
                        .clicked()
                    {
                        self.audio.music_looping = !self.audio.music_looping;
                        if let Some(tx) = &self.audio_cmd_tx {
                            if self.audio.music_looping {
                                self.audio.music_pan = 0.0;
                                let _ = tx.send(AudioCommand::StartMusic {
                                    path: "music.ogg".to_string(),
                                });
                            } else {
                                let _ = tx.send(AudioCommand::StopMusic);
                            }
                        }
                    }
                    if self.audio.music_looping {
                        ui.label(t!("audio_pan"));
                        let pan_slider = egui::Slider::new(&mut self.audio.music_pan, -1.0..=1.0)
                            .custom_formatter(|v, _| {
                                if v < -0.8 {
                                    t!("audio_pan_left").to_string()
                                } else if v <= 0.2 {
                                    t!("audio_pan_center").to_string()
                                } else {
                                    t!("audio_pan_right").to_string()
                                }
                            });
                        let response = ui
                            .add_sized([ui.available_width(), 20.0], pan_slider)
                            .on_hover_text(t!("audio_pan_hint"));
                        if response.changed() {
                            // Fire on every value change (mid-drag, keyboard, click on
                            // rail) instead of only on `drag_stopped`. The audio thread
                            // pushes the music in short chunks and smooths the applied
                            // pan toward the last-received target, so the music keeps
                            // playing continuously and the balance follows the cursor
                            // in real time without any restart-from-zero pop.
                            if let Some(tx) = &self.audio_cmd_tx {
                                let _ = tx.send(AudioCommand::SetMusicPan {
                                    pan: self.audio.music_pan,
                                });
                            }
                        }
                    }
                });

                ui.add_space(12.0);
                theme::field_label(ui, &t!("audio_test_speakers"));
                ui.add_space(4.0);
                ui.label(t!("audio_speakers_hint"));
                ui.add_space(4.0);

                // Layout adapts to the selected Sound3D mode:
                //   - Surround / SSF (4+ speakers): full square with Top/Bottom
                //     Left/Right buttons + ball sweeps top→bottom and left→right.
                //   - Stereo (2 channels): only Left / Right buttons + a single
                //     ball sweep left→right. The front↔lockbar dimension doesn't
                //     exist so hiding those buttons keeps the UI honest.
                let stereo = self.audio.sound_3d_mode.is_stereo();
                let btn_w = 140.0;
                let btn_h = 30.0;
                let gap = 20.0;

                // Row 1: Left / Right (labelled "Top" in surround mode where a
                // symmetric bottom pair exists below).
                let (left_label, right_label) = if stereo {
                    (t!("audio_left").to_string(), t!("audio_right").to_string())
                } else {
                    (
                        t!("audio_top_left").to_string(),
                        t!("audio_top_right").to_string(),
                    )
                };
                ui.horizontal(|ui| {
                    ui.add_space(gap);
                    if ui
                        .add_sized([btn_w, btn_h], egui::Button::new(left_label))
                        .on_hover_text(t!("audio_speaker_test_hint"))
                        .clicked()
                        && let Some(tx) = &self.audio_cmd_tx
                    {
                        let _ = tx.send(AudioCommand::PlayOnSpeaker {
                            path: "ball_roll.ogg".to_string(),
                            target: audio::SpeakerTarget::TopLeft,
                        });
                    }
                    ui.add_space(gap * 2.0);
                    if ui
                        .add_sized([btn_w, btn_h], egui::Button::new(right_label))
                        .on_hover_text(t!("audio_speaker_test_hint"))
                        .clicked()
                        && let Some(tx) = &self.audio_cmd_tx
                    {
                        let _ = tx.send(AudioCommand::PlayOnSpeaker {
                            path: "ball_roll.ogg".to_string(),
                            target: audio::SpeakerTarget::TopRight,
                        });
                    }
                });

                // Row 2: Ball test buttons (centered).
                // Top→bottom test only makes sense with a front/rear pair.
                ui.add_space(4.0);
                if !stereo {
                    ui.horizontal(|ui| {
                        ui.add_space(gap + btn_w / 2.0);
                        if ui
                            .add_sized(
                                [btn_w + gap, btn_h],
                                egui::Button::new(t!("audio_ball_top_bottom").to_string()),
                            )
                            .on_hover_text(t!("audio_ball_top_bottom_hint"))
                            .clicked()
                            && let Some(tx) = &self.audio_cmd_tx
                        {
                            let _ = tx.send(AudioCommand::PlayBallSequence {
                                path: "ball_roll.ogg".to_string(),
                                from: audio::SpeakerTarget::TopBoth,
                                to: audio::SpeakerTarget::BottomBoth,
                                hold_start_ms: 1500,
                                fade_ms: 3000,
                                hold_end_ms: 1500,
                            });
                        }
                    });
                }
                ui.horizontal(|ui| {
                    ui.add_space(gap + btn_w / 2.0);
                    if ui
                        .add_sized(
                            [btn_w + gap, btn_h],
                            egui::Button::new(t!("audio_ball_left_right").to_string()),
                        )
                        .on_hover_text(t!("audio_ball_left_right_hint"))
                        .clicked()
                        && let Some(tx) = &self.audio_cmd_tx
                    {
                        let _ = tx.send(AudioCommand::PlayBallSequence {
                            path: "ball_roll.ogg".to_string(),
                            from: audio::SpeakerTarget::LeftBoth,
                            to: audio::SpeakerTarget::RightBoth,
                            hold_start_ms: 1500,
                            fade_ms: 3000,
                            hold_end_ms: 1500,
                        });
                    }
                });
                ui.add_space(4.0);

                // Row 3: Bottom Left / Bottom Right — surround only.
                if !stereo {
                    ui.horizontal(|ui| {
                        ui.add_space(gap);
                        if ui
                            .add_sized(
                                [btn_w, btn_h],
                                egui::Button::new(t!("audio_bottom_left").to_string()),
                            )
                            .on_hover_text(t!("audio_speaker_test_hint"))
                            .clicked()
                            && let Some(tx) = &self.audio_cmd_tx
                        {
                            let _ = tx.send(AudioCommand::PlayOnSpeaker {
                                path: "ball_roll.ogg".to_string(),
                                target: audio::SpeakerTarget::BottomLeft,
                            });
                        }
                        ui.add_space(gap * 2.0);
                        if ui
                            .add_sized(
                                [btn_w, btn_h],
                                egui::Button::new(t!("audio_bottom_right").to_string()),
                            )
                            .on_hover_text(t!("audio_speaker_test_hint"))
                            .clicked()
                            && let Some(tx) = &self.audio_cmd_tx
                        {
                            let _ = tx.send(AudioCommand::PlayOnSpeaker {
                                path: "ball_roll.ogg".to_string(),
                                target: audio::SpeakerTarget::BottomRight,
                            });
                        }
                    });
                }
            },
        );
    }
}