Passagen, Übungsmodus, Stimmfinder-Überarbeitung, Gerätedesign, Metronom und Akkorde

- Passagenwahl, Original-Kurve, Spulen/Üben und Pause
- Startseite, Klartext-Oberfläche, Stimmfinder mit Stimmtyp-Vorschlag
- Gerätedesign (Regler, Schalter, LED) und Metronom (frei/songsynchron, Tap)
- Akkorderkennung aus der Begleitung, Akkordleiste und -karte
- zweiter Song als Chart

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 13:38:27 +01:00
parent a5fdab8b49
commit 4112f88e54
29 changed files with 6367 additions and 622 deletions

View File

@ -2,6 +2,9 @@
mod calib_view;
mod chart_view;
mod gear;
mod home_view;
mod metro_view;
mod review_view;
mod roll;
mod voice_view;
@ -26,7 +29,7 @@ use voice_view::Wizard;
const FLOOR_DB: f32 = -60.0;
const PEAK_HOLD_DECAY_DB_PER_S: f32 = 20.0;
/// Höhe unterhalb der Piano-Roll (Steuerung, Pegel, Einstellungskopf).
const BELOW_ROLL_PX: f32 = 170.0;
const BELOW_ROLL_PX: f32 = 200.0;
/// Verlauf, der für Anzeige und Nachführung vorgehalten wird.
const HISTORY_S: f64 = 30.0;
const SIM_RATE_HZ: f64 = 100.0;
@ -59,6 +62,8 @@ fn audio_variant(m: Mode) -> u8 {
#[derive(Clone, Copy, PartialEq, Eq)]
enum Mode {
Home,
Settings,
Tuner,
Chart,
History,
@ -69,11 +74,17 @@ enum Mode {
pub struct App {
mode: Mode,
/// Modus des vorigen Bildes: Wechsel lösen zentral Aufräumarbeiten aus.
last_mode: Mode,
zoom_set: bool,
chart: Option<Arc<NoteChart>>,
chart_path_text: String,
session: Option<Session>,
/// Simulation: Startzeit der laufenden Session (Wanduhr) und Sim-Zeit dazu.
sim_session_start: Option<Instant>,
/// Simulation: laufende Pause seit und bisher pausierte Zeit (s).
sim_pause_since: Option<Instant>,
sim_paused_total: f64,
session_sim_t0: f64,
gain_backing: f32,
original_on: bool,
@ -95,6 +106,20 @@ pub struct App {
chart_base: Option<Arc<NoteChart>>,
transpose: i32,
calib: CalibState,
/// Probe-Modus im Chart-Tab: Wiedergabe ohne Wertung und Aufnahme, mit Spulen.
practice: Option<chart_view::Practice>,
metro: metro_view::MetroState,
/// Gefundene Songs für die Auswahl.
charts: Vec<chart_view::ChartEntry>,
/// Gewählte Passage (Index in `chart.sections`); `None` = ganzes Lied.
section: Option<usize>,
/// Probe: Passage in Schleife abspielen.
practice_loop: bool,
/// Pitch-Verlauf des Original-Gesangs und ob er im Chart gezeichnet wird.
original: Option<chart_view::OriginalCurve>,
show_original: bool,
/// Akkordleiste und Akkordkarte anzeigen.
show_chords: bool,
calib_wav: std::path::PathBuf,
config_path: std::path::PathBuf,
config: Config,
@ -115,14 +140,20 @@ pub struct App {
}
impl App {
pub fn new(sim: bool, autostart: bool, review_latest: bool) -> Self {
let config = Config::load();
let chart = NoteChart::load(Path::new(&config.session.chart_path))
.ok()
.map(Arc::new);
/// `chart_arg`: Chart-Datei, die beim Start geladen wird (öffnet den Chart-Tab).
pub fn new(sim: bool, autostart: bool, review_latest: bool, chart_arg: Option<String>) -> Self {
let mut config = Config::load();
if let Some(p) = &chart_arg {
config.session.chart_path = p.clone();
}
let chart_result = NoteChart::load(Path::new(&config.session.chart_path));
let chart_error = chart_result.as_ref().err().map(|e| format!("{e:#}"));
let chart = chart_result.ok().map(Arc::new);
let chart_base = chart.clone();
let mut app = Self {
mode: Mode::Tuner,
mode: Mode::Home,
last_mode: Mode::Home,
zoom_set: false,
gain_guide: if chart.as_ref().is_some_and(|c| c.backing.is_none()) {
0.6
} else {
@ -132,6 +163,8 @@ impl App {
chart_path_text: config.session.chart_path.clone(),
session: None,
sim_session_start: None,
sim_pause_since: None,
sim_paused_total: 0.0,
session_sim_t0: 0.0,
gain_backing: 0.8,
original_on: false,
@ -147,6 +180,14 @@ impl App {
chart_base,
transpose: 0,
calib: CalibState::new(),
practice: None,
metro: metro_view::MetroState::new(),
charts: Vec::new(),
section: None,
practice_loop: true,
original: None,
show_original: true,
show_chords: true,
calib_wav: calib_view::default_wav_path(),
config_path: Config::path(),
sample_rate_text: config
@ -180,6 +221,13 @@ impl App {
}
app.refresh_records();
app.refresh_profiles();
app.refresh_charts();
if chart_arg.is_some() {
app.mode = Mode::Chart;
if let Some(e) = chart_error {
app.messages.push(format!("Chart laden: {e}"));
}
}
if review_latest {
app.open_review(0);
}
@ -190,6 +238,79 @@ impl App {
app
}
/// Entwicklungshilfe (`--tab`, `--wizard`): öffnet gezielt eine Ansicht, der Stimmfinder mit simulierten Daten.
/// Tabs: tuner, chart, verlauf, stimmfinder, kalibrierung. Wizard: intro, speech, speech-rec, holds-rec, result.
pub fn demo_view(&mut self, tab: Option<&str>, wizard: Option<&str>) {
if let Some(t) = tab {
self.mode = match t {
"metronom" => {
self.metro.on = true;
Mode::Tuner
}
"start" => Mode::Home,
"einstellungen" => Mode::Settings,
"singen" | "chart" => Mode::Chart,
"verlauf" => Mode::History,
"stimmfinder" | "voice" => Mode::Voice,
"kalibrierung" | "abgleich" => Mode::Calib,
_ => Mode::Tuner,
};
self.last_mode = self.mode;
}
let Some(w) = wizard else { return };
self.mode = Mode::Voice;
self.wizard_begin();
let feed = |app: &mut App, step: crate::voice::sim::SimStep, fraction: f64| {
app.wizard_record_start();
let (t0, seed) = app
.wizard
.as_ref()
.map_or((0.0, 0), |w| (w.rec_t0.unwrap_or(0.0), w.seed));
let n = (step.duration_s() * fraction * 100.0) as usize;
if let Ok(mut h) = app.history.lock() {
for i in 0..n {
let t = i as f64 * 0.01;
h.push(
t0 + t,
crate::voice::sim::sim_voice(step, t, seed)
.map(|m| PitchEstimate::from_midi(m, 0.95)),
);
}
}
app.sim_t = t0 + n as f64 * 0.01 + 1.0;
};
use crate::voice::sim::SimStep;
match w {
"intro" => {}
"speech" => self.wizard_next(),
"speech-rec" => {
self.wizard_next();
feed(self, SimStep::Speech, 0.45);
}
"holds-rec" | "result" => {
self.wizard_next();
for (step, last) in [
(SimStep::Speech, false),
(SimStep::Legato, false),
(SimStep::Siren, false),
] {
let _ = last;
feed(self, step, 1.0);
self.wizard_record_finish();
self.wizard_next();
}
if w == "holds-rec" {
feed(self, SimStep::Holds, 0.35);
} else {
feed(self, SimStep::Holds, 1.0);
self.wizard_record_finish();
self.wizard_next();
}
}
_ => {}
}
}
fn restart(&mut self) {
self.engine = None; // Streams erst schließen, dann neu öffnen
if let Ok(mut h) = self.history.lock() {
@ -225,17 +346,76 @@ impl App {
}
}
fn readout(&self, ui: &mut egui::Ui, est: Option<PitchEstimate>) {
let text = match est {
Some(e) => format!(
"{:<4} {:+4.0} Cent {:6.1} Hz",
note_name(e.note),
e.cents,
e.freq_hz
),
None => "–".to_string(),
/// Zwei Karten der Stimmanzeige: dein aktueller Ton und der Referenzton.
fn tuner_cards(&self, ui: &mut egui::Ui) {
use roll::{PitchCard, USER_COLOR, draw_pitch_cards};
let gray = egui::Color32::from_gray(170);
let est = self
.history
.lock()
.ok()
.and_then(|h| h.latest().and_then(|p| p.est));
let du = PitchCard {
title: "Dein Ton".into(),
color: USER_COLOR,
midi: est.map(|e| e.midi),
big: None,
lines: est.map_or_else(Vec::new, |e| {
vec![
(format!("{:.1} Hz", e.freq_hz), gray),
(format!("{:+.0} Cent", e.cents), gray),
]
}),
level: None,
meter: est.map(|e| e.cents),
};
ui.label(egui::RichText::new(text).size(30.0).monospace());
let reference = PitchCard {
title: "Referenzton".into(),
color: egui::Color32::from_rgb(130, 175, 255),
midi: self.ref_on.then_some(self.ref_midi as f32),
big: None,
lines: if self.ref_on {
vec![(
format!(
"{:.1} Hz",
440.0 * 2f32.powf((self.ref_midi as f32 - 69.0) / 12.0)
),
gray,
)]
} else {
vec![("aus".to_string(), gray)]
},
level: None,
meter: None,
};
draw_pitch_cards(ui, &[du, reference]);
}
/// Aufräumarbeiten beim Wechsel des Tabs (auch wenn ein Knopf auf der Startseite ihn auslöst).
fn handle_mode_change(&mut self) {
let (before, now) = (self.last_mode, self.mode);
if before == now {
return;
}
self.last_mode = now;
if before == Mode::Chart {
self.stop_session(false);
self.practice_stop();
}
if before == Mode::Calib {
self.calib_cancel();
}
// Review (Mikrospur) und Abgleich (Klickzug) brauchen eigene Audio-Streams.
if audio_variant(before) != audio_variant(now) && self.sim_start.is_none() {
self.restart();
}
// Das Metronom gehört zu Stimmanzeige und Singen; beim Verlassen schaltet es sich aus.
if !matches!(now, Mode::Tuner | Mode::Chart) {
self.metro.on = false;
}
if now == Mode::History {
self.refresh_records();
}
}
fn roll_view(&mut self, ui: &mut egui::Ui, below_px: f32) -> Option<PitchEstimate> {
@ -305,6 +485,11 @@ impl App {
ui.weak("(kein Audio)");
}
});
self.apply_reference();
}
/// Übergibt Referenzton-Einstellungen (Note, Klang, an/aus) an die Audio-Engine.
pub(super) fn apply_reference(&self) {
if let Some(engine) = &self.engine {
let hz = 440.0 * 2f32.powf((self.ref_midi as f32 - 69.0) / 12.0);
let s = &engine.shared;
@ -341,26 +526,6 @@ fn device_combo(
changed
}
fn meter(ui: &mut egui::Ui, label: &str, db: f32) {
ui.horizontal(|ui| {
ui.label(format!("{label:5}"));
let frac = ((db - FLOOR_DB) / -FLOOR_DB).clamp(0.0, 1.0);
let color = if db > -3.0 {
egui::Color32::from_rgb(220, 60, 60)
} else if db > -12.0 {
egui::Color32::from_rgb(230, 190, 50)
} else {
egui::Color32::from_rgb(70, 180, 90)
};
ui.add(
egui::ProgressBar::new(frac)
.desired_width(400.0)
.fill(color)
.text(format!("{db:.1} dBFS")),
);
});
}
impl eframe::App for App {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
let dt = ui.input(|i| i.stable_dt);
@ -372,49 +537,68 @@ impl eframe::App for App {
}
self.sim_tick();
self.session_tick();
self.apply_metronome();
ui.ctx().request_repaint();
egui::CentralPanel::default().show(ui, |ui| {
if !self.zoom_set {
// Etwas größere Darstellung für gute Lesbarkeit.
ui.ctx().set_zoom_factor(self.config.ui.zoom);
gear::apply_theme(ui.ctx());
self.zoom_set = true;
}
self.handle_mode_change();
egui::CentralPanel::default()
.frame(egui::Frame::new().fill(gear::CASE_BG).inner_margin(egui::Margin::same(10)))
.show(ui, |ui| {
egui::ScrollArea::vertical()
.auto_shrink(false)
.show(ui, |ui| {
ui.horizontal(|ui| {
let before = self.mode;
ui.selectable_value(&mut self.mode, Mode::Tuner, "Tuner");
ui.selectable_value(&mut self.mode, Mode::Chart, "Chart");
ui.selectable_value(&mut self.mode, Mode::History, "Verlauf");
ui.selectable_value(&mut self.mode, Mode::Voice, "Stimmfinder");
ui.selectable_value(&mut self.mode, Mode::Calib, "Kalibrierung");
ui.horizontal_wrapped(|ui| {
const TABS: [(Mode, &str); 7] = [
(Mode::Home, "Start"),
(Mode::Chart, "Singen"),
(Mode::Voice, "Stimmfinder"),
(Mode::History, "Verlauf"),
(Mode::Tuner, "Stimmanzeige"),
(Mode::Calib, "Mikrofon-Abgleich"),
(Mode::Settings, "Einstellungen"),
];
for (mode, label) in TABS {
ui.selectable_value(&mut self.mode, mode, label);
}
if self.review.is_some() {
ui.selectable_value(&mut self.mode, Mode::Review, "Review");
}
if before == Mode::Chart && self.mode != before {
self.stop_session(false);
}
// Die Review-Wiedergabe braucht einen eigenen Stream-Satz (Mikrospur, Backing).
if before == Mode::Calib && self.mode != before {
self.calib_cancel();
}
if audio_variant(before) != audio_variant(self.mode)
&& self.sim_start.is_none()
{
self.restart();
}
if before != Mode::History && self.mode == Mode::History {
self.refresh_records();
ui.selectable_value(&mut self.mode, Mode::Review, "Auswertung");
}
});
// Hinweise und Fehlermeldungen gut sichtbar oben.
if !self.messages.is_empty() {
ui.horizontal_wrapped(|ui| {
for m in &self.messages {
ui.colored_label(egui::Color32::from_rgb(235, 150, 70), m);
}
if ui.small_button("✕").on_hover_text("Hinweis ausblenden").clicked() {
self.messages.clear();
}
});
}
match self.mode {
Mode::Home => self.home_ui(ui),
Mode::Settings => self.settings_ui(ui, dt),
Mode::Tuner => {
let est_slot = self
.history
.lock()
.ok()
.and_then(|h| h.latest().and_then(|p| p.est));
self.readout(ui, est_slot);
self.roll_view(ui, BELOW_ROLL_PX);
ui.label(
egui::RichText::new(
"Summe oder singe einen Ton – hier siehst du, welcher es ist und ob du ihn triffst.",
)
.size(16.0)
.color(egui::Color32::from_gray(225)),
);
self.tuner_cards(ui);
self.roll_view(ui, BELOW_ROLL_PX + 120.0);
ui.add_space(4.0);
self.reference_controls(ui);
ui.add_space(6.0);
self.metronome_panel(ui);
}
Mode::Chart => self.chart_ui(ui),
Mode::History => self.history_ui(ui),
@ -422,72 +606,6 @@ impl eframe::App for App {
Mode::Voice => self.voice_ui(ui),
Mode::Calib => self.calib_ui(ui),
}
meter(ui, "Spitze", self.peak_db);
meter(ui, "RMS", self.rms_db);
egui::CollapsingHeader::new("Audio-Einstellungen").show(ui, |ui| {
let mut changed = false;
changed |= device_combo(
ui,
"Eingang",
&self.devices.inputs,
&mut self.config.audio.input_device,
);
changed |= device_combo(
ui,
"Ausgang",
&self.devices.outputs,
&mut self.config.audio.output_device,
);
ui.horizontal(|ui| {
ui.label("Samplerate (leer = Standard)");
ui.add(
egui::TextEdit::singleline(&mut self.sample_rate_text)
.desired_width(70.0),
);
ui.label("Puffer in Frames (leer = Standard)");
ui.add(
egui::TextEdit::singleline(&mut self.buffer_text)
.desired_width(70.0),
);
});
ui.horizontal(|ui| {
if ui.button("Streams (neu) starten").clicked() || changed {
self.restart();
}
if ui.button("Geräte neu einlesen").clicked() {
self.devices = list_devices();
}
if ui.button("Config speichern").clicked() {
self.config.ui.reference_midi = self.ref_midi;
self.messages = match self.config.save_to(&self.config_path) {
Ok(()) => {
vec![format!("Gespeichert: {}", Config::path().display())]
}
Err(e) => vec![format!("Speichern fehlgeschlagen: {e:#}")],
};
}
});
});
let (rate_in, rate_out, xruns) =
self.engine.as_ref().map_or((None, None, 0), |e| {
(
e.input_rate,
e.output_rate,
e.shared.xruns.load(Ordering::Relaxed),
)
});
ui.weak(format!(
"Eingang {} Hz · Ausgang {} Hz · Xruns {} · {:.0} fps",
rate_in.map_or("–".into(), |r| r.to_string()),
rate_out.map_or("–".into(), |r| r.to_string()),
xruns,
1.0 / dt.max(1e-4)
));
for m in &self.messages {
ui.colored_label(egui::Color32::from_rgb(230, 120, 60), m);
}
});
});
}