import { soundLibrary } from '../../viewport/SoundLibrary'; import { centreOf, type HookContext } from './hookHelpers'; /** The Master routing tab (#351): its graph, where its nodes, ports and links are, and the buses it makes. */ export function routingHooks({ state, editor }: HookContext) { const { routingEditor } = editor; const canvas = routingEditor.canvas; return { routing: { shown: () => editor.tab === 'routing' && canvas.currentAssetId !== '', info: () => routingEditor.shownInfo, graph: () => JSON.parse(JSON.stringify(state.project.routing)) as unknown, portAt: (nodeId: string, port: string, isOutput: boolean) => canvas.portGlobal(nodeId, port, isOutput), nodeAt: (nodeId: string) => canvas.nodeGlobal(nodeId), edgeAt: (edgeId: string) => canvas.edgeGlobal(edgeId), label: (nodeId: string) => canvas.nodeLabel(nodeId), problem: (nodeId: string) => canvas.nodeProblem(nodeId), fitAt: () => centreOf(routingEditor.fitButton), /** The loudest sample on each side of these buses of the mix, tapped on first asking (#359). */ peaks: (names: string[]) => Object.fromEntries(soundLibrary.busPeaks(names)), buses: () => soundLibrary.busLevels(), }, }; }