forked from wlkns-dev/stimmwerk
Stimmfinder: automatisch speichern, Songliste mit Begründung; Sänger-Regler; README
- Profil wird beim Ergebnis automatisch gespeichert (und bei jeder Anpassung erneut); Verwerfen löscht es - Ergebnisseite mit „Deine Songs“: Passung je Song mit ausführlicher Begründung (Melodie, Stimme, zu tief/zu hoch, Verschiebung, betroffene Stellen) - Mischpult: eigener Lautstärkeregler für den Original-Sänger - README: Kopf aktualisiert, Übersicht über Ordner und Werkzeuge Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
//! Stimmfinder: geführter Assistent (Willkommen → Sprechlage → Legato → Sirene → Haltetöne → Ergebnis) mit
|
||||
//! Stimmtyp-Einschätzung und Empfehlung. Die Schrittlogik (`wizard_*`) kommt ohne egui aus.
|
||||
|
||||
use super::App;
|
||||
use super::{App, Mode};
|
||||
use crate::chart::NoteChart;
|
||||
use crate::config::VoiceConfig;
|
||||
use crate::pitch::note_name;
|
||||
use crate::voice::classify::{Classification, Confidence, classify};
|
||||
@ -12,6 +13,7 @@ use crate::voice::{
|
||||
suggest_tessitura, tessitura_hint,
|
||||
};
|
||||
use eframe::egui::{self, Align2, Color32, FontId, Rect, RichText, Stroke, pos2, vec2};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
pub(super) enum Step {
|
||||
@ -184,6 +186,8 @@ pub(super) struct Wizard {
|
||||
pub ref_driven: bool,
|
||||
/// Seed der simulierten Stimme; wechselt mit jeder Aufnahme.
|
||||
pub seed: u64,
|
||||
/// (ID, Zeitstempel) des automatisch gespeicherten Profils dieser Messung.
|
||||
pub saved: Option<(String, String)>,
|
||||
}
|
||||
|
||||
impl Wizard {
|
||||
@ -202,6 +206,7 @@ impl Wizard {
|
||||
auto_ref: true,
|
||||
ref_driven: false,
|
||||
seed: 0,
|
||||
saved: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,6 +374,13 @@ impl App {
|
||||
});
|
||||
w.preview = Some(w.profile_preview());
|
||||
}
|
||||
if self
|
||||
.wizard
|
||||
.as_ref()
|
||||
.is_some_and(|w| w.step == Step::Overview)
|
||||
{
|
||||
self.wizard_autosave();
|
||||
}
|
||||
}
|
||||
|
||||
/// Einen Schritt zurück (die bisherigen Ergebnisse bleiben erhalten).
|
||||
@ -387,26 +399,158 @@ impl App {
|
||||
w.tess = (lo, hi.max(lo + 1));
|
||||
w.preview = Some(w.profile_preview());
|
||||
}
|
||||
self.wizard_autosave();
|
||||
}
|
||||
|
||||
/// Speichert die Messung als neues Profil; frühere bleiben erhalten.
|
||||
pub(super) fn wizard_save(&mut self) -> Result<(), String> {
|
||||
/// Speichert die Messung als Profil, sobald das Ergebnis steht, und danach bei jeder Anpassung der Wohlfühllage
|
||||
/// erneut unter derselben ID. So geht eine fünfminütige Messung nie verloren, auch wenn man den Assistenten
|
||||
/// einfach verlässt. Frühere Profile bleiben erhalten.
|
||||
fn wizard_autosave(&mut self) {
|
||||
let Some(w) = self.wizard.as_mut() else {
|
||||
return Ok(());
|
||||
return;
|
||||
};
|
||||
let Some(mut p) = w.preview.clone() else {
|
||||
return Ok(());
|
||||
return;
|
||||
};
|
||||
let (id, created) = voice::new_id(&self.profiles_root);
|
||||
p.id = id;
|
||||
p.created = created;
|
||||
voice::save(&self.profiles_root, &p).map_err(|e| format!("{e:#}"))?;
|
||||
let (id, created) = w
|
||||
.saved
|
||||
.clone()
|
||||
.unwrap_or_else(|| voice::new_id(&self.profiles_root));
|
||||
p.id = id.clone();
|
||||
p.created = created.clone();
|
||||
match voice::save(&self.profiles_root, &p) {
|
||||
Ok(_) => {
|
||||
w.saved = Some((id, created));
|
||||
self.refresh_profiles();
|
||||
self.shown_profile = 0;
|
||||
}
|
||||
Err(e) => self.messages = vec![format!("Profil speichern fehlgeschlagen: {e:#}")],
|
||||
}
|
||||
}
|
||||
|
||||
/// Schließt den Assistenten; das Profil ist bereits gespeichert (Notfalls wird es jetzt gespeichert).
|
||||
pub(super) fn wizard_save(&mut self) -> Result<(), String> {
|
||||
if self.wizard.as_ref().is_some_and(|w| w.saved.is_none()) {
|
||||
self.wizard_autosave();
|
||||
}
|
||||
self.wizard = None;
|
||||
self.refresh_profiles();
|
||||
self.shown_profile = 0;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Verwirft die Messung: das automatisch gespeicherte Profil wird wieder gelöscht.
|
||||
pub(super) fn wizard_discard(&mut self) {
|
||||
if let Some((id, _)) = self.wizard.as_ref().and_then(|w| w.saved.clone()) {
|
||||
let _ = std::fs::remove_file(self.profiles_root.join(format!("{id}.json")));
|
||||
}
|
||||
self.wizard = None;
|
||||
self.refresh_profiles();
|
||||
self.shown_profile = 0;
|
||||
}
|
||||
|
||||
/// Lädt die Charts für die Songliste (einmal; danach aus dem Zwischenspeicher).
|
||||
fn voice_songs(&mut self) -> &[(String, std::path::PathBuf, Arc<NoteChart>)] {
|
||||
if self.voice_songs.is_none() {
|
||||
let list = self
|
||||
.charts
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
NoteChart::load(&e.path)
|
||||
.ok()
|
||||
.map(|c| (e.title.clone(), e.path.clone(), Arc::new(c)))
|
||||
})
|
||||
.collect();
|
||||
self.voice_songs = Some(list);
|
||||
}
|
||||
self.voice_songs.as_deref().unwrap_or(&[])
|
||||
}
|
||||
|
||||
/// Öffnet einen Song im Reiter „Singen“.
|
||||
fn open_song(&mut self, path: &std::path::Path) {
|
||||
self.wizard = None;
|
||||
self.chart_path_text = path.display().to_string();
|
||||
self.load_chart();
|
||||
self.mode = Mode::Chart;
|
||||
}
|
||||
|
||||
/// Ergebnisse links, rechts eine Liste der Songs mit Passung und ausführlicher Begründung. Liefert den Song, der
|
||||
/// geöffnet werden soll.
|
||||
fn results_with_songs(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
p: &VoiceProfile,
|
||||
) -> Option<std::path::PathBuf> {
|
||||
let cfg = self.config.voice.clone();
|
||||
let total = ui.available_width();
|
||||
let mut open = None;
|
||||
// Passungen nur neu berechnen, wenn sich Profil oder Lage ändern.
|
||||
let key = format!("{}|{:?}|{:?}", p.id, p.tessitura, p.safe_range);
|
||||
let mut cache = self.voice_fits.take().filter(|(k, _)| *k == key);
|
||||
if cache.is_none() {
|
||||
let rows = self
|
||||
.voice_songs()
|
||||
.iter()
|
||||
.map(|(title, path, c)| {
|
||||
let fit = crate::voice::song_fit(c, p);
|
||||
let lines = fit.as_ref().map(crate::voice::explain).unwrap_or_default();
|
||||
SongRow {
|
||||
title: title.clone(),
|
||||
path: path.clone(),
|
||||
fit,
|
||||
lines,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
cache = Some((key, rows));
|
||||
}
|
||||
let rows: &[SongRow] = cache.as_ref().map_or(&[], |(_, r)| r.as_slice());
|
||||
// Unter den Spalten stehen noch zwei Einklappbereiche und die Knöpfe: dafür Platz lassen.
|
||||
let height = (ui.ctx().content_rect().bottom() - ui.next_widget_position().y - 270.0)
|
||||
.clamp(180.0, 430.0);
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(total * 0.50);
|
||||
draw_results(ui, p, &cfg);
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(total * 0.46);
|
||||
ui.add_space(4.0);
|
||||
ui.label(egui::RichText::new("Deine Songs").size(20.0).color(egui::Color32::from_rgb(255, 176, 48)));
|
||||
ui.weak("So gut passt jeder Song zu deiner Stimme – und warum:");
|
||||
egui::ScrollArea::vertical().max_height(height).auto_shrink([false, false]).show(ui, |ui| {
|
||||
if rows.is_empty() {
|
||||
ui.weak("Keine Songs gefunden.");
|
||||
}
|
||||
for row in rows {
|
||||
ui.add_space(6.0);
|
||||
ui.label(egui::RichText::new(&row.title).strong().size(16.0));
|
||||
match &row.fit {
|
||||
Some(f) => {
|
||||
let (text, color) = fit_verdict(f);
|
||||
ui.colored_label(color, egui::RichText::new(text).strong());
|
||||
for line in &row.lines {
|
||||
ui.label(egui::RichText::new(line).size(12.5).color(egui::Color32::from_gray(180)));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
ui.weak("Noch keine Aussage möglich: Es fehlen Haltetöne (Schritt 4), aus denen dein sicherer Bereich bestimmt wird.");
|
||||
}
|
||||
}
|
||||
if ui.small_button("Öffnen ▶").clicked() {
|
||||
open = Some(row.path.clone());
|
||||
}
|
||||
ui.separator();
|
||||
}
|
||||
ui.weak("Hinweis: Beim Transponieren bleibt die Musik in der Originaltonart; verschoben werden die Zieltöne und die Wertung.");
|
||||
});
|
||||
});
|
||||
});
|
||||
self.voice_fits = cache;
|
||||
open
|
||||
}
|
||||
|
||||
/// Simulierte Stimme, solange im Simulationsmodus ein Schritt aufnimmt.
|
||||
pub(super) fn sim_voice_pitch(&self, t: f64) -> Option<Option<f32>> {
|
||||
let w = self.wizard.as_ref()?;
|
||||
@ -705,9 +849,12 @@ impl App {
|
||||
""
|
||||
}
|
||||
));
|
||||
draw_results(ui, &p, &self.config.voice);
|
||||
let open = self.results_with_songs(ui, &p);
|
||||
egui::CollapsingHeader::new("Alle Messwerte")
|
||||
.show(ui, |ui| profile_details(ui, &p, &self.config.voice));
|
||||
if let Some(path) = open {
|
||||
self.open_song(&path);
|
||||
}
|
||||
ui.separator();
|
||||
ui.strong("Verlauf der Messungen");
|
||||
let mut show = None;
|
||||
@ -1019,7 +1166,11 @@ impl App {
|
||||
let Some(p) = self.wizard.as_ref().and_then(|w| w.preview.clone()) else {
|
||||
return;
|
||||
};
|
||||
draw_results(ui, &p, &cfg);
|
||||
ui.colored_label(
|
||||
egui::Color32::from_rgb(110, 200, 130),
|
||||
"✓ Dein Profil ist gespeichert – auch wenn du den Assistenten jetzt verlässt.",
|
||||
);
|
||||
let open = self.results_with_songs(ui, &p);
|
||||
let (mut lo, mut hi) = self.wizard.as_ref().map_or((55, 63), |w| w.tess);
|
||||
egui::CollapsingHeader::new("Wohlfühllage anpassen (optional)").show(ui, |ui| {
|
||||
ui.weak("Die Empfehlung kommt aus deinen stabilsten Tönen. Ändere sie nur, wenn du dich woanders wohler fühlst.");
|
||||
@ -1043,16 +1194,59 @@ impl App {
|
||||
if ui.button("◀ Zurück").clicked() {
|
||||
self.wizard_back();
|
||||
}
|
||||
if primary_button(ui, "✔ Profil speichern", true).clicked() {
|
||||
self.messages = match self.wizard_save() {
|
||||
Ok(()) => vec!["Stimmprofil gespeichert".into()],
|
||||
Err(e) => vec![format!("Profil speichern fehlgeschlagen: {e}")],
|
||||
};
|
||||
if primary_button(ui, "✔ Fertig – weiter zu den Songs ▶", true).clicked() {
|
||||
let _ = self.wizard_save();
|
||||
self.messages = vec!["Stimmprofil gespeichert".into()];
|
||||
self.mode = Mode::Chart;
|
||||
}
|
||||
if ui.button("Verwerfen").clicked() {
|
||||
self.wizard = None;
|
||||
if ui.button("Neu messen").clicked() {
|
||||
self.wizard = Some(Wizard::new());
|
||||
}
|
||||
if ui
|
||||
.button("Verwerfen")
|
||||
.on_hover_text("Löscht diese Messung wieder")
|
||||
.clicked()
|
||||
{
|
||||
self.wizard_discard();
|
||||
}
|
||||
});
|
||||
if let Some(path) = open {
|
||||
let _ = self.wizard_save();
|
||||
self.open_song(&path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Song mit Passung zum Profil und fertig formulierter Begründung.
|
||||
pub(super) struct SongRow {
|
||||
title: String,
|
||||
path: std::path::PathBuf,
|
||||
fit: Option<crate::voice::SongFit>,
|
||||
lines: Vec<String>,
|
||||
}
|
||||
|
||||
/// Kurzurteil zur Passung eines Songs in einfachen Worten.
|
||||
fn fit_verdict(f: &crate::voice::SongFit) -> (String, egui::Color32) {
|
||||
let green = egui::Color32::from_rgb(110, 200, 130);
|
||||
let amber = egui::Color32::from_rgb(255, 176, 48);
|
||||
let red = egui::Color32::from_rgb(230, 120, 60);
|
||||
let pct = |x: f32| (x * 100.0).round() as i32;
|
||||
if f.shift.abs() <= 1 && f.outside_now() <= 0.05 {
|
||||
("✓ passt so, wie er ist".into(), green)
|
||||
} else if f.outside_shifted() <= 0.05 {
|
||||
let dir = if f.shift < 0 { "tiefer" } else { "höher" };
|
||||
(
|
||||
format!("passt mit {} Halbtönen {dir}", f.shift.abs()),
|
||||
amber,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
format!(
|
||||
"schwierig: auch angepasst {} % außerhalb deines sicheren Bereichs",
|
||||
pct(f.outside_shifted())
|
||||
),
|
||||
red,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user