Update
This commit is contained in:
parent
bf62ceb98f
commit
6df8a7344d
@ -3,7 +3,7 @@ import { ipcMain } from 'electron';
|
|||||||
import { blackout } from '../patterns/blackout';
|
import { blackout } from '../patterns/blackout';
|
||||||
import { Pattern, PatternOutput, Time } from '../patterns/proto';
|
import { Pattern, PatternOutput, Time } from '../patterns/proto';
|
||||||
import { TestPattern } from '../patterns/test';
|
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';
|
import { ChaserPattern } from '../patterns/chaser';
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
@ -15,6 +15,7 @@ export type AppState = {
|
|||||||
bassFiltered: Array<number>,
|
bassFiltered: Array<number>,
|
||||||
autoCorrelated: Array<number>,
|
autoCorrelated: Array<number>,
|
||||||
} | null,
|
} | null,
|
||||||
|
trackerConfig: TrackerConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Backend {
|
class Backend {
|
||||||
@ -66,12 +67,27 @@ class Backend {
|
|||||||
selectedPattern: null,
|
selectedPattern: null,
|
||||||
beatProgress: null,
|
beatProgress: null,
|
||||||
graphData: null,
|
graphData: null,
|
||||||
|
trackerConfig: {
|
||||||
|
mode: "auto",
|
||||||
|
acThreshold: 1000,
|
||||||
|
zeroCrossingBeatDelay: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('pattern-select', async (_, arg) => {
|
ipcMain.on('pattern-select', async (_, arg) => {
|
||||||
this.state.selectedPattern = 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 = {
|
let time: Time = {
|
||||||
absolute: 0,
|
absolute: 0,
|
||||||
beatRelative: this.state.beatProgress,
|
beatRelative: this.state.beatProgress,
|
||||||
|
@ -7,6 +7,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import { AppState } from '../main/backend';
|
import { AppState } from '../main/backend';
|
||||||
import PatternPreview from './PatternPreview';
|
import PatternPreview from './PatternPreview';
|
||||||
import GraphVisualization from './Graph';
|
import GraphVisualization from './Graph';
|
||||||
|
import ConfigControls from './ConfigControls';
|
||||||
|
|
||||||
const ipcRenderer = (window as any).electron.ipcRenderer as IpcRenderer;
|
const ipcRenderer = (window as any).electron.ipcRenderer as IpcRenderer;
|
||||||
|
|
||||||
@ -63,9 +64,7 @@ const Frontend: React.FC<{ state: AppState }> = ({ state }) => {
|
|||||||
</div>
|
</div>
|
||||||
: <div> no graph data </div>
|
: <div> no graph data </div>
|
||||||
}
|
}
|
||||||
<div>
|
<ConfigControls/>
|
||||||
{JSON.stringify(state)}
|
|
||||||
</div>
|
|
||||||
</>;
|
</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
boilerbloat/src/renderer/ConfigControls.tsx
Normal file
27
boilerbloat/src/renderer/ConfigControls.tsx
Normal file
@ -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<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
return <>
|
||||||
|
<p>Delay:</p>
|
||||||
|
<input ref={bruh} type="number" min="-1000" max="1000" onChange={
|
||||||
|
(e) => {
|
||||||
|
ipcRenderer.send("update-delay", e.currentTarget.value)
|
||||||
|
}
|
||||||
|
} />
|
||||||
|
<p>Manual mode:
|
||||||
|
<input type="checkbox" onClick = {
|
||||||
|
(e) => {
|
||||||
|
ipcRenderer.send("manual-mode", e.currentTarget.checked);
|
||||||
|
}
|
||||||
|
}></input>
|
||||||
|
</p>
|
||||||
|
</>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfigControls;
|
@ -188,11 +188,11 @@ impl BeatTracker {
|
|||||||
let mut prev = now - Duration::from_millis(dt as u64);
|
let mut prev = now - Duration::from_millis(dt as u64);
|
||||||
|
|
||||||
let period_millis = (period_length * MILLIS_PER_POINT) as u64;
|
let period_millis = (period_length * MILLIS_PER_POINT) as u64;
|
||||||
|
|
||||||
let period = Duration::from_millis(period_millis);
|
let period = Duration::from_millis(period_millis);
|
||||||
|
|
||||||
let mut next = prev + period;
|
let mut next = prev + period;
|
||||||
|
|
||||||
if let Some((_, old_next)) = self.current_beats {
|
if let Some((_, old_next)) = self.current_beats {
|
||||||
while next < old_next + Duration::from_millis(period_millis / 2) {
|
while next < old_next + Duration::from_millis(period_millis / 2) {
|
||||||
prev += period;
|
prev += period;
|
||||||
@ -209,12 +209,16 @@ impl BeatTracker {
|
|||||||
|
|
||||||
let (prev, next) = self.current_beats.unwrap();
|
let (prev, next) = self.current_beats.unwrap();
|
||||||
|
|
||||||
let fractional = if prev < now {
|
let mut relative_millis = if prev < now {
|
||||||
(now - prev).as_millis() as f64 / (next - prev).as_millis() as f64
|
(now - prev).as_millis() as f64
|
||||||
} else {
|
} 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)
|
Some(self.beat_count as f64 + fractional)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user