Akkorde, Gitarrengriffe, Taktraster, Strumming-Schätzung und Song-Hilfswerkzeug

- Akkorderkennung aus der Begleitung, Akkordleiste und -karte
- Gitarrengriffe (Dur/Moll) und Strumming-Anzeige
- Taktraster ([grid]) mit Taktstrichen, Raster-Editor und songsynchronem Metronom
- Tempo aus Akkordwechseln (genauer als aus Anschlägen)
- UltraStar-Import mit automatischer Zeit- und Oktavprüfung
- tools/fetch_song.py: Audio laden und in Gesang/Begleitung trennen

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 17:58:03 +01:00
parent 4112f88e54
commit a44c9ef6b0
20 changed files with 2113 additions and 65 deletions

212
src/ui/grip_view.rs Normal file
View File

@ -0,0 +1,212 @@
//! Gitarrengriff-Diagramme und Strumming-Anzeige.
use crate::chart::{NoteChart, Strum};
use crate::guitar::{Grip, grip};
use crate::import::chords::{display_chord, prefer_flats};
use eframe::egui::{self, Align2, Color32, FontId, Rect, Stroke, pos2, vec2};
use super::gear::AMBER;
pub const STRIP_H: f32 = 124.0;
const FRETS_SHOWN: u8 = 4;
/// Zeichnet ein Griffbrett-Diagramm in `rect` (Name oben; ×/○ über den Saiten; Punkte; Barré-Balken).
pub fn draw_grip(painter: &egui::Painter, rect: Rect, label: &str, g: &Grip, active: bool) {
let col = if active {
AMBER
} else {
Color32::from_gray(150)
};
painter.text(
pos2(rect.center().x, rect.top() + 9.0),
Align2::CENTER_CENTER,
label,
FontId::proportional(16.0),
col,
);
let board = Rect::from_min_max(
pos2(rect.left() + 18.0, rect.top() + 36.0),
pos2(rect.right() - 18.0, rect.bottom() - 6.0),
);
let sx = |s: usize| board.left() + board.width() * s as f32 / 5.0;
let fy = |f: f32| board.top() + board.height() * f / f32::from(FRETS_SHOWN);
let line = Stroke::new(1.0, Color32::from_gray(120));
let base = g.base_fret();
// Sattel (dick) oder Bundnummer.
if base == 1 {
painter.line_segment(
[
pos2(board.left(), board.top()),
pos2(board.right(), board.top()),
],
Stroke::new(3.0, col),
);
} else {
painter.line_segment(
[
pos2(board.left(), board.top()),
pos2(board.right(), board.top()),
],
line,
);
painter.text(
pos2(board.right() + 4.0, fy(0.5)),
Align2::LEFT_CENTER,
format!("{base}"),
FontId::proportional(11.0),
Color32::from_gray(190),
);
}
for f in 1..=FRETS_SHOWN {
painter.line_segment(
[
pos2(board.left(), fy(f32::from(f))),
pos2(board.right(), fy(f32::from(f))),
],
line,
);
}
for s in 0..6 {
painter.line_segment(
[pos2(sx(s), board.top()), pos2(sx(s), board.bottom())],
line,
);
}
let cell_y = |fret: u8| fy(f32::from(fret - base) + 0.5);
if let Some((fret, a, b)) = g.barre() {
let r = Rect::from_min_max(
pos2(sx(a) - 5.0, cell_y(fret) - 5.0),
pos2(sx(b) + 5.0, cell_y(fret) + 5.0),
);
painter.rect_filled(r, 5.0, col);
}
for (s, f) in g.frets.iter().enumerate() {
match *f {
None => {
painter.text(
pos2(sx(s), board.top() - 9.0),
Align2::CENTER_CENTER,
"×",
FontId::proportional(13.0),
Color32::from_gray(150),
);
}
Some(0) => {
painter.circle_stroke(
pos2(sx(s), board.top() - 9.0),
4.0,
Stroke::new(1.2, Color32::from_gray(190)),
);
}
Some(fret) => {
painter.circle_filled(pos2(sx(s), cell_y(fret)), 5.5, col);
}
}
}
}
/// Streifen „Gitarre“: aktueller und nächster Griff, rechts das Strumming-Muster (falls bekannt).
pub fn grip_strip(ui: &mut egui::Ui, chart: &NoteChart, now_ms: f64) {
let (rect, _) =
ui.allocate_exact_size(vec2(ui.available_width(), STRIP_H), egui::Sense::hover());
let painter = ui.painter_at(rect);
painter.rect_filled(rect, 6.0, Color32::from_rgb(24, 24, 26));
painter.rect_stroke(
rect,
6.0,
Stroke::new(1.0, Color32::from_gray(60)),
egui::StrokeKind::Inside,
);
let flats = prefer_flats(&chart.chords);
let cur = chart
.chord_at(now_ms)
.map(|i| chart.chords[i].name.as_str());
let next = chart.next_chord_after(now_ms, cur).map(|c| c.name.as_str());
let mut x = rect.left() + 8.0;
for (name, active) in [(cur, true), (next, false)] {
let cell = Rect::from_min_size(pos2(x, rect.top() + 2.0), vec2(104.0, STRIP_H - 4.0));
if let Some(n) = name {
let label = if active {
display_chord(n, flats)
} else {
format!("dann {}", display_chord(n, flats))
};
if let Some(g) = grip(n) {
draw_grip(&painter, cell, &label, &g, active);
}
}
x += 112.0;
}
if let Some(st) = &chart.strum {
draw_strum(
&painter,
Rect::from_min_max(
pos2(x + 16.0, rect.top() + 6.0),
rect.right_bottom() - vec2(8.0, 6.0),
),
st,
chart.strum_slot(now_ms).map(|s| s.0),
);
} else {
painter.text(
pos2(x + 16.0, rect.center().y),
Align2::LEFT_CENTER,
"Strumming: kein sicheres Muster erkannt",
FontId::proportional(13.0),
Color32::from_gray(120),
);
}
}
/// Muster als Reihe von acht Feldern („1 & 2 & 3 & 4 &“) mit ▼ (Abschlag) und ▲ (Aufschlag).
fn draw_strum(painter: &egui::Painter, rect: Rect, st: &Strum, slot: Option<usize>) {
painter.text(
rect.left_top(),
Align2::LEFT_TOP,
"Strumming · Muster aus dem Mix geschätzt",
FontId::proportional(12.0),
Color32::from_gray(150),
);
let w = ((rect.width()) / 8.0).min(46.0);
let top = rect.top() + 22.0;
for (i, ch) in st.pattern.chars().enumerate().take(8) {
let cell = Rect::from_min_size(pos2(rect.left() + i as f32 * w, top), vec2(w - 4.0, 70.0));
let now = slot == Some(i);
painter.rect_filled(
cell,
4.0,
if now {
Color32::from_rgb(70, 52, 18)
} else {
Color32::from_rgb(34, 34, 38)
},
);
if now {
painter.rect_stroke(cell, 4.0, Stroke::new(1.5, AMBER), egui::StrokeKind::Inside);
}
let count = if i % 2 == 0 {
format!("{}", i / 2 + 1)
} else {
"&".into()
};
painter.text(
pos2(cell.center().x, cell.top() + 12.0),
Align2::CENTER_CENTER,
count,
FontId::proportional(13.0),
Color32::from_gray(160),
);
let (glyph, c) = match ch {
'D' => ("▼", AMBER),
'U' => ("▲", Color32::from_rgb(110, 190, 230)),
_ => ("·", Color32::from_gray(80)),
};
painter.text(
pos2(cell.center().x, cell.center().y + 12.0),
Align2::CENTER_CENTER,
glyph,
FontId::proportional(24.0),
c,
);
}
}