forked from wlkns-dev/stimmwerk
Rhythmusraster, kompaktes Layout für „Singen“, Akkorde auf dem Raster
- Akkordgrenzen rasten auf die Zählzeiten des Rasters ein - Rhythmusraster im Stil des GuiTacheles-Blatts (Felder anklickbar, speicherbar) - Singen-Ansicht ohne Scrollen: Kopfzeile, Notenfeld füllt den Rest, Mischpult als Leiste, Fenster „Mehr“ und „Ergebnis“ - Regler verbrauchen das Mausrad (Fenster scrollt nicht mehr mit) - Raster/Muster-Änderungen wirken auch nach Transponieren und während einer Session Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
//! Gitarrengriff-Diagramme und Strumming-Anzeige.
|
||||
|
||||
use crate::chart::{NoteChart, Strum};
|
||||
use crate::chart::NoteChart;
|
||||
use crate::guitar::{Grip, grip};
|
||||
use crate::import::chords::{display_chord, prefer_flats};
|
||||
use eframe::egui::{self, Align2, Color32, FontId, Rect, Stroke, pos2, vec2};
|
||||
@ -106,6 +106,14 @@ pub fn draw_grip(painter: &egui::Painter, rect: Rect, label: &str, g: &Grip, act
|
||||
}
|
||||
|
||||
/// Streifen „Gitarre“: aktueller und nächster Griff, rechts das Strumming-Muster (falls bekannt).
|
||||
/// Per Klick geändertes Strumming-Muster, das auf die Übernahme ins Chart wartet.
|
||||
static PENDING_EDIT: std::sync::Mutex<Option<String>> = std::sync::Mutex::new(None);
|
||||
|
||||
/// Holt ein wartendes, geändertes Muster ab.
|
||||
pub fn take_strum_edit() -> Option<String> {
|
||||
PENDING_EDIT.lock().ok().and_then(|mut p| p.take())
|
||||
}
|
||||
|
||||
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());
|
||||
@ -137,76 +145,184 @@ pub fn grip_strip(ui: &mut egui::Ui, chart: &NoteChart, now_ms: f64) {
|
||||
}
|
||||
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),
|
||||
if let Some(g) = chart.effective_grid() {
|
||||
let slots = 2 * g.beats_per_bar as usize;
|
||||
let pattern = chart
|
||||
.strum
|
||||
.as_ref()
|
||||
.map_or_else(|| "-".repeat(slots), |st| st.pattern.clone());
|
||||
let area = Rect::from_min_max(
|
||||
pos2(x + 16.0, rect.top() + 6.0),
|
||||
rect.right_bottom() - vec2(8.0, 6.0),
|
||||
);
|
||||
let estimated = chart.strum.as_ref().is_some_and(|st| st.confidence < 1.0);
|
||||
if let Some(new) = strum_grid(
|
||||
ui,
|
||||
&painter,
|
||||
area,
|
||||
&pattern,
|
||||
slots,
|
||||
chart.strum_slot(now_ms).map(|s| s.0),
|
||||
estimated,
|
||||
chart.strum.is_some(),
|
||||
) && let Ok(mut p) = PENDING_EDIT.lock()
|
||||
{
|
||||
*p = Some(new);
|
||||
}
|
||||
} else {
|
||||
painter.text(
|
||||
pos2(x + 16.0, rect.center().y),
|
||||
Align2::LEFT_CENTER,
|
||||
"Strumming: kein sicheres Muster erkannt",
|
||||
"Strumming: erst ein Takt-Raster anlegen",
|
||||
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>) {
|
||||
/// Nächster Zustand eines Feldes beim Anklicken: leer → Abschlag → Aufschlag → leer.
|
||||
pub fn next_stroke(c: char) -> char {
|
||||
match c {
|
||||
'-' => 'D',
|
||||
'D' => 'U',
|
||||
_ => '-',
|
||||
}
|
||||
}
|
||||
|
||||
/// Muster nach einem Klick auf Feld `i`.
|
||||
pub fn click_slot(pattern: &str, i: usize) -> String {
|
||||
pattern
|
||||
.chars()
|
||||
.enumerate()
|
||||
.map(|(k, c)| if k == i { next_stroke(c) } else { c })
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Abschlag: Kästchen mit dicker Oberkante.
|
||||
fn paint_downstroke(painter: &egui::Painter, c: egui::Pos2, col: Color32) {
|
||||
let r = Rect::from_center_size(c, vec2(20.0, 22.0));
|
||||
painter.rect_stroke(r, 1.0, Stroke::new(1.5, col), egui::StrokeKind::Inside);
|
||||
painter.rect_filled(Rect::from_min_size(r.min, vec2(r.width(), 6.0)), 0.0, col);
|
||||
}
|
||||
|
||||
/// Aufschlag: V.
|
||||
fn paint_upstroke(painter: &egui::Painter, c: egui::Pos2, col: Color32) {
|
||||
let (w, h) = (10.0, 11.0);
|
||||
let st = Stroke::new(2.2, col);
|
||||
painter.line_segment([pos2(c.x - w, c.y - h), pos2(c.x, c.y + h)], st);
|
||||
painter.line_segment([pos2(c.x + w, c.y - h), pos2(c.x, c.y + h)], st);
|
||||
}
|
||||
|
||||
/// Rhythmusraster: ein Takt in Achteln, gezählt „1 und 2 und 3 und 4 und“, darunter je Feld Abschlag (Kästchen mit
|
||||
/// dicker Oberkante), Aufschlag (V) oder leer. Felder sind anklickbar; Ergebnis ist das geänderte Muster.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn strum_grid(
|
||||
ui: &mut egui::Ui,
|
||||
painter: &egui::Painter,
|
||||
rect: Rect,
|
||||
pattern: &str,
|
||||
slots: usize,
|
||||
active: Option<usize>,
|
||||
estimated: bool,
|
||||
has_pattern: bool,
|
||||
) -> Option<String> {
|
||||
let title = if !has_pattern {
|
||||
"Rhythmusraster: Felder anklicken (leer → Abschlag → Aufschlag)"
|
||||
} else if estimated {
|
||||
"Rhythmusraster (aus dem Mix geschätzt, Felder anklicken zum Ändern)"
|
||||
} else {
|
||||
"Rhythmusraster (Felder anklicken zum Ändern)"
|
||||
};
|
||||
painter.text(
|
||||
rect.left_top(),
|
||||
Align2::LEFT_TOP,
|
||||
"Strumming · Muster aus dem Mix geschätzt",
|
||||
title,
|
||||
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(
|
||||
let label_w = 52.0;
|
||||
let gap = 8.0;
|
||||
let beats = slots.div_ceil(2);
|
||||
let cell_w = ((rect.width() - label_w - gap * beats as f32) / slots as f32).clamp(18.0, 44.0);
|
||||
let (top, h) = (rect.top() + 36.0, 58.0);
|
||||
painter.text(
|
||||
pos2(rect.left(), rect.top() + 26.0),
|
||||
Align2::LEFT_CENTER,
|
||||
"Zähle:",
|
||||
FontId::proportional(12.0),
|
||||
Color32::from_gray(150),
|
||||
);
|
||||
let chars: Vec<char> = pattern.chars().collect();
|
||||
let mut changed = None;
|
||||
for i in 0..slots {
|
||||
let x = rect.left() + label_w + i as f32 * cell_w + (i / 2) as f32 * gap;
|
||||
let cell = Rect::from_min_size(pos2(x, top), vec2(cell_w, h));
|
||||
let now = active == Some(i);
|
||||
let resp = ui.interact(cell, ui.scope_id().with(("strum", i)), egui::Sense::click());
|
||||
let fill = if now {
|
||||
Color32::from_rgb(70, 52, 18)
|
||||
} else if resp.hovered() {
|
||||
Color32::from_rgb(48, 48, 54)
|
||||
} else {
|
||||
Color32::from_rgb(34, 34, 38)
|
||||
};
|
||||
painter.rect_filled(cell, 2.0, fill);
|
||||
painter.rect_stroke(
|
||||
cell,
|
||||
4.0,
|
||||
if now {
|
||||
Color32::from_rgb(70, 52, 18)
|
||||
} else {
|
||||
Color32::from_rgb(34, 34, 38)
|
||||
},
|
||||
2.0,
|
||||
Stroke::new(
|
||||
if now { 1.6 } else { 1.0 },
|
||||
if now { AMBER } else { Color32::from_gray(90) },
|
||||
),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
if now {
|
||||
painter.rect_stroke(cell, 4.0, Stroke::new(1.5, AMBER), egui::StrokeKind::Inside);
|
||||
}
|
||||
let count = if i % 2 == 0 {
|
||||
let label = if i % 2 == 0 {
|
||||
format!("{}", i / 2 + 1)
|
||||
} else {
|
||||
"&".into()
|
||||
"und".to_string()
|
||||
};
|
||||
painter.text(
|
||||
pos2(cell.center().x, cell.top() + 12.0),
|
||||
pos2(cell.center().x, top - 10.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,
|
||||
label,
|
||||
FontId::proportional(if i % 2 == 0 { 15.0 } else { 11.0 }),
|
||||
if i % 2 == 0 {
|
||||
Color32::from_gray(220)
|
||||
} else {
|
||||
Color32::from_gray(150)
|
||||
},
|
||||
);
|
||||
let c = cell.center();
|
||||
match chars.get(i).copied().unwrap_or('-') {
|
||||
'D' => paint_downstroke(painter, c, AMBER),
|
||||
'U' => paint_upstroke(painter, c, Color32::from_rgb(110, 190, 230)),
|
||||
_ => {}
|
||||
}
|
||||
if resp
|
||||
.on_hover_text("Klick: leer → Abschlag → Aufschlag → leer")
|
||||
.clicked()
|
||||
{
|
||||
let base: String = (0..slots)
|
||||
.map(|k| chars.get(k).copied().unwrap_or('-'))
|
||||
.collect();
|
||||
changed = Some(click_slot(&base, i));
|
||||
}
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn clicking_a_slot_cycles_empty_down_up() {
|
||||
assert_eq!(next_stroke('-'), 'D');
|
||||
assert_eq!(next_stroke('D'), 'U');
|
||||
assert_eq!(next_stroke('U'), '-');
|
||||
assert_eq!(click_slot("--------", 2), "--D-----");
|
||||
assert_eq!(click_slot("--D-----", 2), "--U-----");
|
||||
assert_eq!(click_slot("D-DUD-DU", 7), "D-DUD-D-");
|
||||
assert_eq!(click_slot("D-DUD-DU", 0).len(), 8);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user