This commit is contained in:
Kai Vogelgesang 2021-11-13 00:22:24 +01:00
parent bf62ceb98f
commit 6df8a7344d
Signed by: kai
GPG Key ID: 0A95D3B6E62C0879
4 changed files with 55 additions and 9 deletions

View File

@ -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<number>,
autoCorrelated: Array<number>,
} | 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,

View File

@ -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 }) => {
</div>
: <div> no graph data </div>
}
<div>
{JSON.stringify(state)}
</div>
<ConfigControls/>
</>;
}

View 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;

View File

@ -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)
}