diff --git a/boilerbloat/src/main/backend.ts b/boilerbloat/src/main/backend.ts index dc458c0..5bd606f 100644 --- a/boilerbloat/src/main/backend.ts +++ b/boilerbloat/src/main/backend.ts @@ -3,7 +3,7 @@ import { ipcMain } from 'electron'; import { blackout } from '../patterns/blackout'; import { Pattern, PatternOutput, Time } from '../patterns/proto'; import { TestPattern } from '../patterns/test'; -import rust, { BeatTrackerHandle, MovingHeadState, OutputHandle } from 'rust_native_module'; +import rust, { BeatTrackerHandle, MovingHeadState, OutputHandle, TrackerConfig } from 'rust_native_module'; import { ChaserPattern } from '../patterns/chaser'; export type AppState = { @@ -15,6 +15,7 @@ export type AppState = { bassFiltered: Array, autoCorrelated: Array, } | null, + trackerConfig: TrackerConfig, }; class Backend { @@ -66,12 +67,27 @@ class Backend { selectedPattern: null, beatProgress: null, graphData: null, + trackerConfig: { + mode: "auto", + acThreshold: 1000, + zeroCrossingBeatDelay: 0, + } } ipcMain.on('pattern-select', async (_, arg) => { this.state.selectedPattern = arg; }); + ipcMain.on('update-delay', async (_, delay) => { + this.state.trackerConfig.zeroCrossingBeatDelay = Math.floor(delay); + this.beatTracker.setConfig(this.state.trackerConfig); + }); + + ipcMain.on('manual-mode', async (_, is_manual) => { + this.state.trackerConfig.mode = is_manual ? "manual" : "auto"; + this.beatTracker.setConfig(this.state.trackerConfig); + }); + let time: Time = { absolute: 0, beatRelative: this.state.beatProgress, diff --git a/boilerbloat/src/renderer/App.tsx b/boilerbloat/src/renderer/App.tsx index 28aa9f5..85b4545 100644 --- a/boilerbloat/src/renderer/App.tsx +++ b/boilerbloat/src/renderer/App.tsx @@ -7,6 +7,7 @@ import { useEffect, useState } from 'react'; import { AppState } from '../main/backend'; import PatternPreview from './PatternPreview'; import GraphVisualization from './Graph'; +import ConfigControls from './ConfigControls'; const ipcRenderer = (window as any).electron.ipcRenderer as IpcRenderer; @@ -63,9 +64,7 @@ const Frontend: React.FC<{ state: AppState }> = ({ state }) => { :
no graph data
} -
- {JSON.stringify(state)} -
+ ; } diff --git a/boilerbloat/src/renderer/ConfigControls.tsx b/boilerbloat/src/renderer/ConfigControls.tsx new file mode 100644 index 0000000..3738432 --- /dev/null +++ b/boilerbloat/src/renderer/ConfigControls.tsx @@ -0,0 +1,27 @@ +import { useRef } from "react"; + +import { IpcRenderer } from 'electron/renderer'; +const ipcRenderer = (window as any).electron.ipcRenderer as IpcRenderer; + +const ConfigControls: React.FC = () => { + + const bruh = useRef(null); + + return <> +

Delay:

+ { + ipcRenderer.send("update-delay", e.currentTarget.value) + } + } /> +

Manual mode: + { + ipcRenderer.send("manual-mode", e.currentTarget.checked); + } + }> +

+ ; +} + +export default ConfigControls; diff --git a/rust_native_module/src/beat_tracking/tracker.rs b/rust_native_module/src/beat_tracking/tracker.rs index 265fd6a..96c07b7 100644 --- a/rust_native_module/src/beat_tracking/tracker.rs +++ b/rust_native_module/src/beat_tracking/tracker.rs @@ -188,11 +188,11 @@ impl BeatTracker { let mut prev = now - Duration::from_millis(dt as u64); let period_millis = (period_length * MILLIS_PER_POINT) as u64; - + let period = Duration::from_millis(period_millis); let mut next = prev + period; - + if let Some((_, old_next)) = self.current_beats { while next < old_next + Duration::from_millis(period_millis / 2) { prev += period; @@ -209,12 +209,16 @@ impl BeatTracker { let (prev, next) = self.current_beats.unwrap(); - let fractional = if prev < now { - (now - prev).as_millis() as f64 / (next - prev).as_millis() as f64 + let mut relative_millis = if prev < now { + (now - prev).as_millis() as f64 } else { - -1.0 * (prev - now).as_millis() as f64 / (next - prev).as_millis() as f64 + -1.0 * (prev - now).as_millis() as f64 }; + relative_millis += self.config.zero_crossing_beat_delay as f64; + + let fractional = relative_millis / (next - prev).as_millis() as f64; + Some(self.beat_count as f64 + fractional) }