mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Switched to more generic wording
This commit is contained in:
1 parent
c9e85bbdb5
commit
6e24f5ef1d
29 files changed
+796
-319
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
|
||||
import type { Capabilities } from '../api'
|
||||
|
||||
/**
|
||||
* What the loaded library can persist.
|
||||
*
|
||||
* Components read this instead of branching on the platform, so a control is
|
||||
* never offered for an edit that would silently vanish on save. There is no
|
||||
* default value on purpose: the app does not render until capabilities have
|
||||
* resolved, which removes any chance of a permissive first frame offering an
|
||||
* edit the adapter would reject.
|
||||
*
|
||||
* Containers call `useCaps()`; presentational leaves take plain values as props
|
||||
* so they stay trivially testable.
|
||||
*/
|
||||
export const CapabilitiesContext = createContext<Capabilities | null>(null)
|
||||
|
||||
export function useCaps(): Capabilities {
|
||||
const caps = useContext(CapabilitiesContext)
|
||||
if (!caps) {
|
||||
throw new Error('useCaps() used outside <CapabilitiesContext.Provider>')
|
||||
}
|
||||
return caps
|
||||
}
|
||||
|
||||
/** Label for a bank slot: "1".."8" or "A".."H", per the platform's convention. */
|
||||
export function slotLabeller(caps: Capabilities): (slot: number) => string {
|
||||
return caps.cues.slot_labels === 'letter'
|
||||
? (slot) => String.fromCharCode(65 + slot)
|
||||
: (slot) => String(slot + 1)
|
||||
}
|
||||
+62
-22
@@ -1,21 +1,56 @@
|
||||
import type { CuePoint } from '../api'
|
||||
import type { CuePoint, CueType } from '../api'
|
||||
import { BEATS_PER_BAR, type BeatGrid } from './beatgrid'
|
||||
|
||||
// Marker colour by Traktor cue type. Type is authoritative here (the NML's
|
||||
// stored per-cue colour is intentionally ignored) so each type reads consistently.
|
||||
// There is deliberately no entry for type 4 (grid): grid markers are not cues —
|
||||
// they arrive as TrackCues.grid_markers and are drawn by drawBeatgrid.
|
||||
const TYPE_COLORS: Record<number, string> = {
|
||||
0: '#3b82f6', // cue — blue
|
||||
1: '#ff8c2f', // fade-in — orange
|
||||
2: '#ff8c2f', // fade-out — orange
|
||||
3: '#ffd60a', // load — yellow
|
||||
5: '#22c55e', // loop — green
|
||||
// Fallback colour by cue type, used when the platform stored none.
|
||||
const TYPE_COLORS: Record<CueType, string> = {
|
||||
cue: '#3b82f6', // blue
|
||||
fade_in: '#ff8c2f', // orange
|
||||
fade_out: '#ff8c2f', // orange
|
||||
load: '#ffd60a', // yellow
|
||||
loop: '#22c55e', // green
|
||||
}
|
||||
const OTHER_COLOR = '#8b93a3' // gray
|
||||
const MEMORY_COLOR = '#8b93a3' // gray
|
||||
|
||||
export const CUE_TYPE_LABELS: Record<CueType, string> = {
|
||||
cue: 'Cue',
|
||||
fade_in: 'Fade-In',
|
||||
fade_out: 'Fade-Out',
|
||||
load: 'Load',
|
||||
loop: 'Loop',
|
||||
}
|
||||
|
||||
// A second, always-present channel for type. Colour used to be type-derived and
|
||||
// therefore always carried it; now that a user's stored colour wins, the glyph
|
||||
// is what keeps a fade-in distinguishable from a plain cue.
|
||||
const TYPE_GLYPHS: Record<CueType, string> = {
|
||||
cue: '',
|
||||
fade_in: '▶',
|
||||
fade_out: '◀',
|
||||
load: '⏏',
|
||||
loop: '⟳',
|
||||
}
|
||||
|
||||
/**
|
||||
* Colour for a cue marker or button.
|
||||
*
|
||||
* Stored colour wins where the platform has one: on Rekordbox and Serato it is
|
||||
* the attribute the user actually set, and overriding it with a type palette
|
||||
* would discard their own organisation. Traktor rarely stores one, so in a
|
||||
* Traktor library the type palette still drives virtually every cue and the
|
||||
* existing look is preserved.
|
||||
*/
|
||||
export function cueColor(cue: CuePoint): string {
|
||||
return TYPE_COLORS[cue.type] ?? OTHER_COLOR
|
||||
if (cue.color) return cue.color
|
||||
if (cue.role === 'memory') return MEMORY_COLOR
|
||||
return TYPE_COLORS[cue.type] ?? MEMORY_COLOR
|
||||
}
|
||||
|
||||
export function cueTypeColor(type: CueType): string {
|
||||
return TYPE_COLORS[type] ?? MEMORY_COLOR
|
||||
}
|
||||
|
||||
export function cueGlyph(cue: CuePoint): string {
|
||||
return TYPE_GLYPHS[cue.type] ?? ''
|
||||
}
|
||||
|
||||
function withAlpha(hex: string, a: number): string {
|
||||
@@ -46,6 +81,8 @@ export function drawCues(
|
||||
dpr: number,
|
||||
timeToX: (t: number) => number,
|
||||
labels: boolean,
|
||||
/** How a bank slot is labelled — "1".."8" or "A".."H", per the platform. */
|
||||
slotLabel: (slot: number) => string = (slot) => String(slot + 1),
|
||||
): void {
|
||||
const lineW = Math.max(2, Math.round(2 * dpr))
|
||||
const outline = Math.max(1, Math.round(dpr))
|
||||
@@ -53,10 +90,9 @@ export function drawCues(
|
||||
const flagH = Math.round(14 * dpr)
|
||||
const half = Math.floor(lineW / 2)
|
||||
for (const cue of cues) {
|
||||
// Grid markers and their companion cues belong to the beatgrid and are
|
||||
// drawn by drawBeatgrid; painting them here too would stack a grey line and
|
||||
// a numbered flag on top of every marker.
|
||||
if (cue.type === 4 || cue.grid_marker != null) continue
|
||||
// A grid marker's companion cue is drawn by drawBeatgrid; painting it here
|
||||
// too would stack a flag on top of every marker line.
|
||||
if (cue.grid_marker != null) continue
|
||||
const color = cueColor(cue)
|
||||
const x = Math.round(timeToX(cue.start))
|
||||
|
||||
@@ -78,16 +114,20 @@ export function drawCues(
|
||||
ctx.fillRect(x - half, 0, lineW, h)
|
||||
|
||||
if (labels) {
|
||||
// A flag tab at the top for every cue (outlined), with the hotcue number.
|
||||
// A flag tab at the top for every cue (outlined). A banked cue carries its
|
||||
// slot label; one without a slot (a memory cue) gets a half-height tab, so
|
||||
// it still reads as a real object rather than an anonymous line.
|
||||
const banked = cue.slot != null
|
||||
const tabH = banked ? flagH : Math.round(flagH / 2)
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.7)'
|
||||
ctx.fillRect(x - half - outline, 0, flagW + outline * 2, flagH + outline * 2)
|
||||
ctx.fillRect(x - half - outline, 0, flagW + outline * 2, tabH + outline * 2)
|
||||
ctx.fillStyle = color
|
||||
ctx.fillRect(x - half, 0, flagW, flagH)
|
||||
if (cue.hotcue >= 0) {
|
||||
ctx.fillRect(x - half, 0, flagW, tabH)
|
||||
if (banked) {
|
||||
ctx.fillStyle = contrastText(color)
|
||||
ctx.font = `bold ${Math.round(10 * dpr)}px system-ui, sans-serif`
|
||||
ctx.textBaseline = 'top'
|
||||
ctx.fillText(String(cue.hotcue + 1), x - half + Math.round(2 * dpr), Math.round(2 * dpr))
|
||||
ctx.fillText(slotLabel(cue.slot!), x - half + Math.round(2 * dpr), Math.round(2 * dpr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -12,14 +12,14 @@ export function formatBpm(bpm: number | null): string {
|
||||
return bpm.toFixed(1)
|
||||
}
|
||||
|
||||
// Traktor stores keys like "10m" / "8d" (Open Key notation) or classic "8A".
|
||||
// Give each of the 12 pitch classes a stable hue so harmonic groups read at a
|
||||
// glance — adjacent/compatible keys land near each other on the color wheel.
|
||||
export function keyColor(key: string | null): string | undefined {
|
||||
if (!key) return undefined
|
||||
const m = key.match(/(\d+)/)
|
||||
if (!m) return undefined
|
||||
const n = parseInt(m[1], 10) % 12
|
||||
const hue = (n / 12) * 360
|
||||
return `hsl(${hue} 65% 62%)`
|
||||
/**
|
||||
* Hue by wheel position, so harmonically adjacent keys sit adjacent in colour.
|
||||
*
|
||||
* Takes the parsed Camelot position rather than the key string: "10m" vs "Am"
|
||||
* vs "8A" is platform notation, and parsing it is the adapter's job. Doing it
|
||||
* here used to mean every non-Traktor key lost its colour.
|
||||
*/
|
||||
export function keyColor(wheel: number | null): string | undefined {
|
||||
if (wheel == null) return undefined
|
||||
return `hsl(${((wheel % 12) / 12) * 360} 65% 62%)`
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Wording that names the loaded platform.
|
||||
*
|
||||
* The adapter supplies structured facts, never finished sentences, and these
|
||||
* compose them. That keeps the copy (and any future translation) in the UI while
|
||||
* staying genuinely specific — the pre-save warning is a real, per-platform
|
||||
* hazard and must not be watered down into something vague.
|
||||
*/
|
||||
import type { SaveCapabilities } from '../api'
|
||||
|
||||
export function saveLabel(save: SaveCapabilities): string {
|
||||
return `Save to ${save.app_name}`
|
||||
}
|
||||
|
||||
/** Shown while there are unsaved changes. Null when the platform has no hazard. */
|
||||
export function overwriteWarning(save: SaveCapabilities): string | null {
|
||||
switch (save.overwrite_risk) {
|
||||
case 'none':
|
||||
return null
|
||||
case 'on_exit':
|
||||
return `Close ${save.app_name} before saving — it overwrites ${save.library_label} on exit.`
|
||||
case 'while_running':
|
||||
return `${save.app_name} is open — it may overwrite or re-sync ${save.library_label} while running. Close it before saving.`
|
||||
}
|
||||
}
|
||||
|
||||
export function restoreWarning(save: SaveCapabilities): string | null {
|
||||
switch (save.overwrite_risk) {
|
||||
case 'none':
|
||||
return null
|
||||
case 'on_exit':
|
||||
return `Close ${save.app_name} before restoring — it overwrites ${save.library_label} on exit.`
|
||||
case 'while_running':
|
||||
return `${save.app_name} is open — close it before restoring, or it may overwrite ${save.library_label}.`
|
||||
}
|
||||
}
|
||||
|
||||
/** Trailing hint after an in-memory edit. */
|
||||
export function writeHint(save: SaveCapabilities): string {
|
||||
return `Save to ${save.app_name} to write it to disk`
|
||||
}
|
||||
@@ -122,12 +122,12 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
|
||||
)
|
||||
},
|
||||
}),
|
||||
col.accessor('is_stem', {
|
||||
col.accessor('media_kind', {
|
||||
id: 'type',
|
||||
header: 'Type',
|
||||
size: 64,
|
||||
cell: (c) =>
|
||||
c.getValue() ? (
|
||||
c.getValue() === 'stem' ? (
|
||||
// Stem file → stacked lines ("burger"), the usual stem glyph.
|
||||
<span title="Stem file" className="text-accent">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-label="Stem">
|
||||
@@ -168,7 +168,10 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
|
||||
return (
|
||||
<span
|
||||
className="rounded px-1.5 py-0.5 text-xs font-semibold"
|
||||
style={{ color: keyColor(k), background: 'color-mix(in srgb, currentColor 14%, transparent)' }}
|
||||
style={{
|
||||
color: keyColor(c.row.original.key_wheel),
|
||||
background: 'color-mix(in srgb, currentColor 14%, transparent)',
|
||||
}}
|
||||
>
|
||||
{k}
|
||||
</span>
|
||||
@@ -211,12 +214,12 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
|
||||
size: 72,
|
||||
cell: (c) => {
|
||||
const n = c.getValue()
|
||||
const markers = c.row.original.grid_markers
|
||||
const markers = c.row.original.grid_marker_count
|
||||
// Gold marks a flexible (multi-tempo) grid, mint an ordinary constant one.
|
||||
return (
|
||||
<span className="flex items-center gap-1 tabular-nums">
|
||||
<span className={n > 0 ? 'text-text' : 'text-faint'}>{n}</span>
|
||||
{c.row.original.has_grid && (
|
||||
{markers > 0 && (
|
||||
<span
|
||||
className={markers > 1 ? 'text-[10px] text-gold' : 'text-[10px] text-mint'}
|
||||
title={markers > 1 ? `Flexible beatgrid (${markers} markers)` : 'Beatgrid analyzed'}
|
||||
|
||||
Reference in new issue
Block a user