mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Added context option to multi analyze
This commit is contained in:
1 parent
b71436fad6
commit
532dc5d6ac
11 files changed
+486
-12
No files matched your search
@@ -0,0 +1,83 @@
|
||||
import { useEffect } from 'react'
|
||||
|
||||
interface Props {
|
||||
/** Tracks the user selected. */
|
||||
total: number
|
||||
/** Unlocked tracks that already have a beatgrid. */
|
||||
existing: number
|
||||
/** Tracks whose grid is locked — skipped whatever is chosen here. */
|
||||
locked: number
|
||||
onChoose: (replaceExisting: boolean) => void
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
/** Asked only when a batch analysis would meet existing grids: re-analysing a
|
||||
* grid someone may have hand-fixed is a decision, not a default. */
|
||||
export function AnalyzeGridDialog({ total, existing, locked, onChoose, onClose }: Props) {
|
||||
// "Skip them" would leave nothing to do when every unlocked track has a grid.
|
||||
const canSkip = existing < total - locked
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [onClose])
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-modal="true"
|
||||
className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="w-full max-w-sm overflow-hidden rounded-xl border border-line bg-ink-900 shadow-2xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="border-b border-line px-5 py-4">
|
||||
<div className="text-[15px] font-semibold tracking-tight">Analyze Grid & BPM</div>
|
||||
<div className="text-xs text-muted">
|
||||
{total} track{total === 1 ? '' : 's'} selected
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-1 px-5 py-4 text-sm text-muted">
|
||||
<p>
|
||||
<span className="tabular-nums text-text">{existing}</span>{' '}
|
||||
{existing === 1 ? 'already has a beatgrid' : 'already have a beatgrid'}. Replacing
|
||||
discards any hand edits to {existing === 1 ? 'it' : 'them'}.
|
||||
</p>
|
||||
{locked > 0 && (
|
||||
<p className="text-faint">
|
||||
{locked} {locked === 1 ? 'is' : 'are'} locked and will be skipped either way.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-2 border-t border-line px-5 py-3">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="rounded-md px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onChoose(true)}
|
||||
className={
|
||||
canSkip
|
||||
? 'rounded-md px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text'
|
||||
: 'rounded-md bg-accent px-4 py-1.5 text-sm font-medium text-ink-950 hover:brightness-110'
|
||||
}
|
||||
>
|
||||
Replace {existing === 1 ? 'it' : 'them'}
|
||||
</button>
|
||||
{canSkip && (
|
||||
<button
|
||||
onClick={() => onChoose(false)}
|
||||
className="rounded-md bg-accent px-4 py-1.5 text-sm font-medium text-ink-950 hover:brightness-110"
|
||||
>
|
||||
Skip {existing === 1 ? 'it' : 'them'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react'
|
||||
|
||||
/** One row of a menu: an action, a submenu (`label ▸`), or a section heading. */
|
||||
export type MenuItem =
|
||||
| { label: string; onClick: () => void; danger?: boolean; hint?: string; icon?: string }
|
||||
| { label: string; onClick: () => void; danger?: boolean; hint?: string; icon?: string; disabled?: boolean }
|
||||
| { label: string; submenu: MenuItem[] }
|
||||
| { heading: string; empty?: string }
|
||||
|
||||
@@ -122,15 +122,18 @@ function MenuPanel({
|
||||
return (
|
||||
<button
|
||||
key={i}
|
||||
disabled={item.disabled}
|
||||
onMouseEnter={() => setOpen(null)}
|
||||
onClick={() => {
|
||||
item.onClick()
|
||||
onClose()
|
||||
}}
|
||||
className={`flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm ${
|
||||
item.danger
|
||||
? 'text-pink hover:bg-ink-800'
|
||||
: 'text-muted hover:bg-ink-800 hover:text-text'
|
||||
item.disabled
|
||||
? 'cursor-default text-faint'
|
||||
: item.danger
|
||||
? 'text-pink hover:bg-ink-800'
|
||||
: 'text-muted hover:bg-ink-800 hover:text-text'
|
||||
}`}
|
||||
>
|
||||
{item.icon && <span className="shrink-0 text-[11px] text-gold">{item.icon}</span>}
|
||||
|
||||
@@ -39,6 +39,9 @@ interface Props {
|
||||
* deck gates on those — so this only needs to redirect the two READS.
|
||||
*/
|
||||
fromDevice?: boolean
|
||||
/** Bumped when something outside the deck (batch grid analysis) rewrote the
|
||||
* loaded track's cues/grid, so the deck re-reads them. */
|
||||
cuesRefresh?: number
|
||||
}
|
||||
|
||||
function fmt(secs: number): string {
|
||||
@@ -73,7 +76,14 @@ const LOOP_SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32]
|
||||
* Web Audio PlaybackEngine (seamless loops); the same decoded buffer feeds the
|
||||
* scratch engine and both waveform views.
|
||||
*/
|
||||
export function PrepStrip({ track, playRequest = 0, onError, onNotify, fromDevice = false }: Props) {
|
||||
export function PrepStrip({
|
||||
track,
|
||||
playRequest = 0,
|
||||
onError,
|
||||
onNotify,
|
||||
fromDevice = false,
|
||||
cuesRefresh = 0,
|
||||
}: Props) {
|
||||
const qc = useQueryClient()
|
||||
const [playing, setPlaying] = useState(false)
|
||||
const [previewing, setPreviewing] = useState(false) // momentary hold-to-play active
|
||||
@@ -287,6 +297,19 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify, fromDevic
|
||||
}
|
||||
}, [trackId, fromDevice])
|
||||
|
||||
// Re-read after an outside edit. Deliberately NOT the effect above: that one
|
||||
// resets `originalGridRef`, and "Reset" should still restore the grid the
|
||||
// track had before the outside edit replaced it.
|
||||
useEffect(() => {
|
||||
if (!trackId || !cuesRefresh) return
|
||||
let cancelled = false
|
||||
api.trackCues(trackId).then((d) => !cancelled && setCueData(d)).catch(() => {})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [cuesRefresh])
|
||||
|
||||
const toggle = () => {
|
||||
const eng = playbackRef.current
|
||||
if (!eng || !eng.ready) return
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
/** A background job's progress, shown at the right of the bar. */
|
||||
export interface StatusJob {
|
||||
label: string
|
||||
done: number
|
||||
/** 0 until the job knows its size → indeterminate bar. */
|
||||
total: number
|
||||
/** What it is working on right now, e.g. the current track's title. */
|
||||
detail?: string
|
||||
cancelling?: boolean
|
||||
onCancel: () => void
|
||||
}
|
||||
|
||||
interface Props {
|
||||
showing: number
|
||||
total: number
|
||||
sourceName: string
|
||||
/** Rows currently selected; shown only when non-zero. */
|
||||
selected?: number
|
||||
job?: StatusJob | null
|
||||
loading?: boolean
|
||||
collectionName?: string | null
|
||||
onChangeCollection?: () => void
|
||||
@@ -14,6 +27,7 @@ export function StatusBar({
|
||||
total,
|
||||
sourceName,
|
||||
selected = 0,
|
||||
job,
|
||||
loading,
|
||||
collectionName,
|
||||
onChangeCollection,
|
||||
@@ -41,10 +55,35 @@ export function StatusBar({
|
||||
<span className="tabular-nums text-accent">{selected.toLocaleString()} selected</span>
|
||||
</>
|
||||
)}
|
||||
{job && (
|
||||
<div className="ml-auto flex min-w-0 items-center gap-2">
|
||||
<span className="shrink-0 tabular-nums text-text">
|
||||
{job.cancelling ? 'Cancelling…' : job.label}
|
||||
{job.total > 0 && ` ${Math.min(job.done + 1, job.total)}/${job.total}`}
|
||||
</span>
|
||||
<span className="h-1.5 w-32 shrink-0 overflow-hidden rounded-full bg-ink-800">
|
||||
<span
|
||||
className={`block h-full rounded-full bg-accent transition-[width] duration-300 ${
|
||||
job.total > 0 ? '' : 'w-1/3 animate-pulse'
|
||||
}`}
|
||||
style={job.total > 0 ? { width: `${(job.done / job.total) * 100}%` } : undefined}
|
||||
/>
|
||||
</span>
|
||||
{job.detail && <span className="max-w-[240px] truncate text-faint">{job.detail}</span>}
|
||||
<button
|
||||
onClick={job.onCancel}
|
||||
disabled={job.cancelling}
|
||||
className="shrink-0 rounded px-1.5 text-faint hover:bg-ink-800 hover:text-pink disabled:opacity-40"
|
||||
title="Cancel"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{collectionName && (
|
||||
<button
|
||||
onClick={onChangeCollection}
|
||||
className="ml-auto flex items-center gap-1.5 rounded px-2 py-0.5 text-faint hover:bg-ink-800 hover:text-text"
|
||||
className={`${job ? '' : 'ml-auto '}flex items-center gap-1.5 rounded px-2 py-0.5 text-faint hover:bg-ink-800 hover:text-text`}
|
||||
title="Change collection"
|
||||
>
|
||||
<span className="text-[11px]">⎘</span>
|
||||
|
||||
Reference in new issue
Block a user