mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Made UI improvements
This commit is contained in:
1 parent
2f9b1d59ae
commit
d848efaf50
15 files changed
+563
-118
No files matched your search
@@ -86,6 +86,33 @@ export function drawCues(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the floating "CUE" point: a gold vertical line with a dark outline and a
|
||||
* solid downward triangle tab at the top, distinct from numbered hotcue flags,
|
||||
* the white beatgrid, and the red playhead.
|
||||
*/
|
||||
export function drawCuePoint(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
x: number,
|
||||
h: number,
|
||||
dpr: number,
|
||||
): void {
|
||||
const lw = Math.max(2, Math.round(2 * dpr))
|
||||
const half = Math.floor(lw / 2)
|
||||
const outline = Math.max(1, Math.round(dpr))
|
||||
const tab = Math.round(8 * dpr)
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.6)'
|
||||
ctx.fillRect(x - half - outline, 0, lw + outline * 2, h)
|
||||
ctx.fillStyle = '#ffb020'
|
||||
ctx.fillRect(x - half, 0, lw, h)
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(x - tab, 0)
|
||||
ctx.lineTo(x + tab, 0)
|
||||
ctx.lineTo(x, tab)
|
||||
ctx.closePath()
|
||||
ctx.fill()
|
||||
}
|
||||
|
||||
/** Draw the active loop region: a translucent green band with bright edges. */
|
||||
export function drawLoop(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
// The audio is downmixed to mono and split into three frequency bands with
|
||||
// native BiquadFilters (via OfflineAudioContext — fast, off the main thread).
|
||||
// Per output column we keep each band's RMS energy plus the amplitude peak.
|
||||
// Colour = balance of the three bands (bass→red, mids→green, highs→blue);
|
||||
// height = amplitude. This mirrors how Traktor's Spectrum waveform reads.
|
||||
// Each band is mapped to a target colour on Traktor's warm→cool ramp
|
||||
// (bass→orange, mids→violet, highs→cyan) and the three are blended by energy;
|
||||
// height = amplitude. Traktor's palette has NO green — mapping bands straight
|
||||
// to R/G/B (the naive approach) produces yellows/greens it never shows, so we
|
||||
// blend named palette colours instead. Tune the three constants below.
|
||||
|
||||
export interface WaveColumn {
|
||||
peak: number // 0..1 amplitude (column height)
|
||||
r: number // 0..1 colour channels (already contrast-boosted)
|
||||
r: number // 0..1 final blended colour (already contrast-boosted)
|
||||
g: number
|
||||
b: number
|
||||
}
|
||||
@@ -20,6 +23,11 @@ const MID_HZ = 1200
|
||||
const MID_Q = 0.6
|
||||
const HIGH_HZ = 5000
|
||||
|
||||
// Target colour per band on Traktor's ramp (0..1 RGB). Blended by band energy.
|
||||
const LOW_COL = [1.0, 0.30, 0.15] // bass → orange-red
|
||||
const MID_COL = [0.65, 0.18, 0.95] // mids → violet / magenta
|
||||
const HIGH_COL = [0.15, 0.65, 1.0] // highs → cyan-blue
|
||||
|
||||
/**
|
||||
* Paint a slice of the analysed columns across a canvas: source columns in the
|
||||
* fractional range [startFrac, endFrac) (of the whole track) are mapped across
|
||||
@@ -167,12 +175,19 @@ export async function analyzeWaveform(url: string, buckets?: number): Promise<Wa
|
||||
// tied to loudness — amplitude is shown by height, like Traktor). Gamma
|
||||
// sharpens the separation between bands.
|
||||
const mx = Math.max(l, m, h, 1e-9)
|
||||
cols[b] = {
|
||||
peak: peak[b] / maxPeak,
|
||||
r: Math.pow(l / mx, 1.3),
|
||||
g: Math.pow(m / mx, 1.3),
|
||||
b: Math.pow(h / mx, 1.3),
|
||||
}
|
||||
const wl = Math.pow(l / mx, 1.3)
|
||||
const wm = Math.pow(m / mx, 1.3)
|
||||
const wh = Math.pow(h / mx, 1.3)
|
||||
// Blend the three band palette colours by weight, then normalise to the
|
||||
// brightest channel so the colour stays vivid (height carries loudness).
|
||||
let cr = wl * LOW_COL[0] + wm * MID_COL[0] + wh * HIGH_COL[0]
|
||||
let cg = wl * LOW_COL[1] + wm * MID_COL[1] + wh * HIGH_COL[1]
|
||||
let cb = wl * LOW_COL[2] + wm * MID_COL[2] + wh * HIGH_COL[2]
|
||||
const cmax = Math.max(cr, cg, cb, 1e-9)
|
||||
cr /= cmax
|
||||
cg /= cmax
|
||||
cb /= cmax
|
||||
cols[b] = { peak: peak[b] / maxPeak, r: cr, g: cg, b: cb }
|
||||
}
|
||||
return { cols, buffer: audio }
|
||||
}
|
||||
Reference in new issue
Block a user