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:
@ -39,6 +39,8 @@ pub struct Metronome {
|
||||
click_len: u32,
|
||||
phase: f32,
|
||||
freq: f32,
|
||||
/// Versatz des Taktanfangs im synchronen Modus (Frames): Schlag 0 liegt bei dieser Chart-Position.
|
||||
offset_frames: i64,
|
||||
}
|
||||
|
||||
impl Metronome {
|
||||
@ -53,9 +55,15 @@ impl Metronome {
|
||||
click_len: ((CLICK_S * rate) as u32).max(8),
|
||||
phase: 0.0,
|
||||
freq: NORMAL_HZ,
|
||||
offset_frames: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Taktanfang im synchronen Modus (ms ab Chartanfang; darf negativ sein).
|
||||
pub fn set_offset_ms(&mut self, ms: f32) {
|
||||
self.offset_frames = (f64::from(ms) * f64::from(self.rate) / 1000.0).round() as i64;
|
||||
}
|
||||
|
||||
/// Nächstes Sample (Klick bereits mit `gain` skaliert) und ggf. der in diesem Sample begonnene Klick.
|
||||
/// `sync_pos`: Chart-Position in Frames für den synchronen Modus, sonst `None`.
|
||||
pub fn next(&mut self, p: &Params, sync_pos: Option<i64>) -> (f32, Option<Click>) {
|
||||
@ -78,7 +86,7 @@ impl Metronome {
|
||||
self.last_floor = -1;
|
||||
}
|
||||
match sync_pos {
|
||||
Some(pos) => self.beat_pos = pos as f64 * step,
|
||||
Some(pos) => self.beat_pos = (pos - self.offset_frames) as f64 * step,
|
||||
None => self.beat_pos += step,
|
||||
}
|
||||
let fl = self.beat_pos.floor() as i64;
|
||||
@ -265,6 +273,33 @@ mod tests {
|
||||
assert_eq!(clicks[0].1.beat_in_bar, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn synced_clicks_follow_the_bar_offset_of_the_song() {
|
||||
// 120 BPM (24 000 Frames je Schlag), Taktanfang bei 500 ms = 24 000 Frames, 4/4.
|
||||
let mut m = Metronome::new(RATE);
|
||||
m.set_offset_ms(500.0);
|
||||
let start = -1000i64;
|
||||
let clicks = run(&mut m, ¶ms(120.0, 4), 60_000, Some(start));
|
||||
let at: Vec<(i64, i64, bool)> = clicks
|
||||
.iter()
|
||||
.map(|(f, c)| (*f as i64 + start, c.index, c.accent))
|
||||
.collect();
|
||||
// Schläge bei 24 000 (Eins, Index 0), 48 000 (1), 72 000 (2); davor bei 0 (Index −1, Position 3).
|
||||
assert_eq!(
|
||||
at,
|
||||
[(0, -1, false), (24_000, 0, true), (48_000, 1, false)],
|
||||
"{at:?}"
|
||||
);
|
||||
assert_eq!(clicks[0].1.beat_in_bar, 3);
|
||||
// Ohne Versatz liegt die Eins wieder bei 0.
|
||||
let mut m = Metronome::new(RATE);
|
||||
let c = run(&mut m, ¶ms(120.0, 4), 30_000, Some(-1000));
|
||||
assert!(
|
||||
c.iter()
|
||||
.any(|(f, c)| c.index == 0 && c.accent && (*f as i64 - 1000).abs() <= 1)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seeking_never_clicks_and_resumes_on_the_grid() {
|
||||
let mut m = Metronome::new(RATE);
|
||||
|
||||
@ -129,6 +129,7 @@ impl Mixer {
|
||||
gain: load_f32(&sh.met_gain),
|
||||
};
|
||||
let metro_sync = sh.met_sync.load(Relaxed) && playing;
|
||||
self.metro.set_offset_ms(load_f32(&sh.met_offset));
|
||||
let (ref_on, ref_soft) = (sh.ref_on.load(Relaxed), sh.ref_soft.load(Relaxed));
|
||||
self.ref_osc.set_freq(load_f32(&sh.ref_freq));
|
||||
|
||||
|
||||
@ -133,6 +133,8 @@ pub struct Shared {
|
||||
pub met_beats: AtomicU32,
|
||||
pub met_gain: AtomicU32,
|
||||
pub met_sync: AtomicBool,
|
||||
/// Taktanfang des Songs in ms (Versatz des synchronen Metronoms), als f32-Bits.
|
||||
pub met_offset: AtomicU32,
|
||||
/// Vom Callback gesetzt: Anzahl bisheriger Klicks und Taktposition des letzten Klicks (für die LED-Anzeige).
|
||||
pub met_count: AtomicU32,
|
||||
pub met_beat: AtomicU32,
|
||||
@ -161,6 +163,7 @@ impl Default for Shared {
|
||||
met_beats: AtomicU32::new(4),
|
||||
met_gain: AtomicU32::new(0.5f32.to_bits()),
|
||||
met_sync: AtomicBool::new(false),
|
||||
met_offset: AtomicU32::new(0.0f32.to_bits()),
|
||||
met_count: AtomicU32::new(0),
|
||||
met_beat: AtomicU32::new(0),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user