Skip to content

Commit

Permalink
feat: cleaner reactive UI structure
Browse files Browse the repository at this point in the history
  • Loading branch information
davay42 committed Nov 5, 2024
1 parent 5b62531 commit 342a183
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { version, year } from '../package.json'
import { useSpectrogram } from './useSpectrogram';
import { useVideoRecorder } from './useVideoRecorder';
const time = useTimestamp()
const {
screen, canvasElement, video, paused, recording, recordedWidth, controls, params, initiated, vertical, width, height, initiate, startRecording, stopRecording, pics, clear
} = useSpectrogram()
const time = useTimestamp()
const { toggle, isSupported } = useFullscreen(screen)
const { videoRecording, startVideo, stopVideo } = useVideoRecorder(video)
Expand Down
16 changes: 10 additions & 6 deletions src/useSpectrogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ const params = {
speed: { default: 1, min: 1, max: 4, step: 1, fixed: 0 }
}

function useControls(paramsList) {
const controls = reactive({})
for (let param in paramsList) {
let p = paramsList[param]
controls[param] = useClamp(useStorage(param, p.default), p.min, p.max)
}
return controls
}

export function useSpectrogram() {
let canvas, ctx, tempCanvas, tempCtx, audio

Expand All @@ -25,12 +34,7 @@ export function useSpectrogram() {

const vertical = useStorage('vertical', false)

const controls = reactive({})

for (let param in params) {
let p = params[param]
controls[param] = useClamp(useStorage(param, p.default), p.min, p.max)
}
const controls = useControls(params)

watch(() => controls.frame, f => audio && (audio.fftSize = Math.pow(2, 11 + f)))
watch(() => controls.smooth, s => audio && (audio.smooth = s))
Expand Down

0 comments on commit 342a183

Please sign in to comment.