@hfd-sdk/keyboard-kit 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ import { keyPosition, volcanoMountainPositions, musicConfig } from '../shared/types';
2
+ /**
3
+ * 68 键圆环坐标配置
4
+ */
5
+ export declare const RING_68_KEY_POSITIONS: keyPosition[][];
6
+ /**
7
+ * 87 键圆环坐标配置
8
+ */
9
+ export declare const RING_87_KEY_POSITIONS: keyPosition[][];
10
+ /**
11
+ * 108 键圆环坐标配置
12
+ */
13
+ export declare const RING_108_KEY_POSITIONS: keyPosition[][];
14
+ /**
15
+ * 获取音乐律动圆环坐标
16
+ * @param ringKeyPositions 圆环坐标配置,可以是预设名或自定义数组
17
+ */
18
+ export declare function getMusicRingKeyPositions(ringKeyPositions?: musicConfig['ringKeyPositions']): keyPosition[][] | undefined;
19
+ /**
20
+ * 64 键 3141-32777-YUNZII B68 PRO Keyboard 右上是块大屏
21
+ */
22
+ export declare const VOLCANO_64_KEY_POSITIONS: volcanoMountainPositions;
23
+ /**
24
+ * 标准 84 键,例如 ISO
25
+ */
26
+ export declare const VOLCANO_84_ISO_KEY_POSITIONS: volcanoMountainPositions;
27
+ /**
28
+ * 标准 87 键,例如 X87 V2、2902
29
+ */
30
+ export declare const VOLCANO_87_KEY_POSITIONS: volcanoMountainPositions;
31
+ /**
32
+ * 标准 98 键(扩展按键 1-4 行)
33
+ */
34
+ export declare const VOLCANO_98_KEY_POSITIONS: volcanoMountainPositions;
35
+ /**
36
+ * 获取音乐律动火山按键坐标
37
+ * @param volcanoKeyPositions 火山坐标配置,可以是预设名或自定义左/中/右山坐标
38
+ */
39
+ export declare function getMusicVolcanoKeyPositions(volcanoKeyPositions?: musicConfig['volcanoKeyPositions']): volcanoMountainPositions | undefined;
@@ -0,0 +1,16 @@
1
+ import { MusicV2AmplitudeSource, MusicV2ScreenLightClient } from './types';
2
+ export interface MusicV2PluginClientOptions {
3
+ /** 请求超时(毫秒),默认 500 */
4
+ timeoutMs?: number;
5
+ /** Worker 内振幅轮询间隔(毫秒),默认 50 */
6
+ pollIntervalMs?: number;
7
+ }
8
+ export interface MusicV2PluginClient extends MusicV2AmplitudeSource, MusicV2ScreenLightClient {
9
+ /** 获取硬件信息 */
10
+ getHardwareInfo: () => Promise<unknown>;
11
+ }
12
+ /**
13
+ * 创建本地音乐律动插件客户端(默认 http://127.0.0.1:9191)。
14
+ * fetch 在 Web Worker 中执行;振幅由 Worker 独立轮询并缓存,主线程只读缓存。
15
+ */
16
+ export declare function createMusicV2PluginClient(baseUrl?: string, options?: MusicV2PluginClientOptions): MusicV2PluginClient;
@@ -0,0 +1,18 @@
1
+ import { MusicV2AmplitudeSource } from './types';
2
+ export interface SystemAudioFrequencyBands {
3
+ low: number;
4
+ mid: number;
5
+ high: number;
6
+ }
7
+ export interface SystemAudioSource extends MusicV2AmplitudeSource {
8
+ /** 是否正在采集系统音频 */
9
+ isActive: () => boolean;
10
+ /** 获取低(20-250Hz)、中(250-4000Hz)、高(4000-20000Hz)频段强度,范围 0-1000 */
11
+ getFrequencyBands: () => SystemAudioFrequencyBands;
12
+ }
13
+ /**
14
+ * 创建浏览器系统音频振幅来源,无需插件。
15
+ * 通过 getDisplayMedia 分享屏幕/标签页采集音频,
16
+ * 用户需在浏览器分享对话框中勾选「分享系统音频」或「分享标签页音频」。
17
+ */
18
+ export declare function createSystemAudioSource(): SystemAudioSource;
@@ -0,0 +1,138 @@
1
+ import { HFDSDKDevice, KeyboardConfig, RgbColor } from '../shared/types';
2
+ /**
3
+ * 音乐律动 V2 显示模式
4
+ * - 1 绿/黄/红(曲率频阶)
5
+ * - 4 色谱(曲率频阶)
6
+ * - 13 随曲起舞
7
+ * - 14 尘埃光漩(旋转线条)
8
+ * - 15 蛰伏火山(山)
9
+ * - 16 光矢穿心(爱心)
10
+ * - 17 萤火轨迹(线性波动)
11
+ * - 18 光茧共振
12
+ * - 19 音叉振空(潮汐共振)
13
+ * - 20 曲率遗轨(线性波动缩短)
14
+ * - 21 行波律动
15
+ * - 22 双心共舞
16
+ * - 100 屏光联动(需要插件客户端)
17
+ */
18
+ export type MusicV2Mode = 1 | 4 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 100;
19
+ /**
20
+ * 背景灯光模式
21
+ * - 0 无背景
22
+ * - 6 白色 / 7 红色 / 8 橙色 / 9 黄色 / 10 蓝色 / 11 绿色
23
+ * - 1 绿/黄/红三行
24
+ * - 2 彩虹色多行
25
+ * - 4 色谱(色轮)
26
+ * - 5 频谱循环
27
+ */
28
+ export type MusicV2BackgroundMode = 0 | 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
29
+ /** 振幅来源:返回 0-1000 的原始振幅 */
30
+ export interface MusicV2AmplitudeSource {
31
+ /** 启动采集(如请求系统音频授权),可选 */
32
+ start?: () => void | Promise<void>;
33
+ /** 获取当前原始振幅,范围 0-1000 */
34
+ getAmplitude: () => number | Promise<number>;
35
+ /** 停止采集并释放资源,可选 */
36
+ stop?: () => void;
37
+ }
38
+ /** 屏光联动(模式 100)所需的插件客户端能力 */
39
+ export interface MusicV2ScreenLightClient {
40
+ /** 设置键盘布局(base64 编码后的布局 JSON) */
41
+ setKeyboardLayout: (data: string) => Promise<unknown>;
42
+ /** 设置音乐律动模式 */
43
+ setMusicMode: (param: string) => Promise<unknown>;
44
+ /** 获取音乐律动状态(插件回传的每键颜色) */
45
+ getMusicStatus: () => Promise<{
46
+ keys: Array<{
47
+ row: number;
48
+ col: number;
49
+ keyCode: number;
50
+ keyIndex: number;
51
+ color: string;
52
+ }>;
53
+ }>;
54
+ /** 关闭音乐律动 */
55
+ close: () => Promise<unknown>;
56
+ }
57
+ /** 点阵屏配置,用于计算随音乐数据下发的振幅档位 */
58
+ export interface MusicV2LedConfig {
59
+ rows: number;
60
+ cols: number;
61
+ }
62
+ export interface MusicV2EngineOptions {
63
+ /** 键盘布局与音乐协议配置 */
64
+ keyboardConfig: KeyboardConfig;
65
+ /** `@hfd-sdk/keyboard-sdk` 的 HFDDevice 实例 */
66
+ device: HFDSDKDevice;
67
+ /** 是否 USB 有线连接 */
68
+ isUSBDevice?: boolean;
69
+ /** 灯光协议版本 */
70
+ lightingVersion?: number;
71
+ /** 振幅来源;未提供时可使用测试模式驱动 */
72
+ amplitudeSource?: MusicV2AmplitudeSource;
73
+ /** 屏光联动(模式 100)客户端,通常由 createMusicV2PluginClient 创建 */
74
+ screenLightClient?: MusicV2ScreenLightClient;
75
+ /** 点阵屏配置(可选,存在时随音乐数据下发振幅档位) */
76
+ ledConfig?: MusicV2LedConfig;
77
+ /** 渲染 / 下发间隔(毫秒),默认 50 */
78
+ intervalMs?: number;
79
+ /** 静音阈值(连续 N 帧振幅为 0 才视为静音),默认 5 */
80
+ silenceThreshold?: number;
81
+ /** 初始显示模式,默认 13 */
82
+ mode?: MusicV2Mode;
83
+ /** 初始用户振幅(平滑系数)1-100,默认 50 */
84
+ amplitude?: number;
85
+ /** 初始背景模式,默认 0 */
86
+ backMode?: MusicV2BackgroundMode;
87
+ /** 初始背景亮度 10-100,默认 100 */
88
+ backBrightness?: number;
89
+ /** 每帧按键 RGB 变化回调(可用于 UI 预览) */
90
+ onKeysRgbChange?: (keysRgb: RgbColor[][]) => void;
91
+ /** 状态变化回调 */
92
+ onStateChange?: (state: MusicV2State) => void;
93
+ /** 引擎内部错误回调(绘制 / 下发失败等) */
94
+ onError?: (error: unknown) => void;
95
+ }
96
+ export interface MusicV2State {
97
+ /** 是否正在运行 */
98
+ running: boolean;
99
+ /** 当前显示模式 */
100
+ mode: MusicV2Mode;
101
+ /** 用户振幅(平滑系数)1-100 */
102
+ amplitude: number;
103
+ /** 背景模式 */
104
+ backMode: MusicV2BackgroundMode;
105
+ /** 背景亮度 10-100 */
106
+ backBrightness: number;
107
+ /** 当前归一化振幅 0-1 */
108
+ currentAmplitude: number;
109
+ /** 振幅来源是否可用(false 对应 web 端「未下载插件」状态) */
110
+ sourceActive: boolean;
111
+ /** 是否为测试模式 */
112
+ testMode: boolean;
113
+ /** 当前帧按键 RGB(最后一次渲染结果) */
114
+ currentKeysRgb: RgbColor[][] | null;
115
+ }
116
+ export interface MusicV2Engine {
117
+ /** 启动定时渲染循环 */
118
+ start: () => void;
119
+ /** 停止定时渲染循环(不释放振幅来源) */
120
+ stop: () => void;
121
+ /** 暂停(如 profile 切换期间),与 resume 配对 */
122
+ pause: () => void;
123
+ /** 恢复 */
124
+ resume: () => void;
125
+ /** 停止循环并释放振幅来源、关闭屏光联动 */
126
+ dispose: () => void;
127
+ setMode: (mode: MusicV2Mode) => void;
128
+ /** 设置用户振幅(平滑系数)1-100 */
129
+ setAmplitude: (value: number) => void;
130
+ setBackMode: (mode: MusicV2BackgroundMode) => void;
131
+ /** 设置背景亮度 10-100 */
132
+ setBackBrightness: (value: number) => void;
133
+ /** 开关测试模式;开启后以 testAmplitude(0-1000,默认 1000)驱动 */
134
+ setTestMode: (open: boolean, testAmplitude?: number) => void;
135
+ /** 运行时切换振幅来源 */
136
+ setAmplitudeSource: (source: MusicV2AmplitudeSource | undefined) => void;
137
+ getState: () => MusicV2State;
138
+ }
@@ -0,0 +1,82 @@
1
+ import { KeyboardConfig, RgbColor } from '../shared/types';
2
+ import { MusicV2BackgroundMode, MusicV2Mode } from './types';
3
+ export interface MusicV2RenderParams {
4
+ /** 显示模式 */
5
+ mode: MusicV2Mode;
6
+ /** 用户振幅(平滑系数)1-100 */
7
+ amplitude: number;
8
+ /** 背景模式 */
9
+ backMode: MusicV2BackgroundMode;
10
+ /** 背景亮度 10-100 */
11
+ backBrightness: number;
12
+ /** 当前归一化振幅 0-1 */
13
+ currentAmplitude: number;
14
+ }
15
+ /**
16
+ * 音乐律动 V2 渲染器:把每种显示模式绘制到按键 RGB 网格。
17
+ * 纯计算、无定时器,由引擎按固定帧率调用 `render()`。
18
+ */
19
+ export declare class MusicV2Renderer {
20
+ private readonly keyboardConfig;
21
+ private bgStep;
22
+ private pulseOffset;
23
+ private pulseSpeed;
24
+ private colorCycleOffset;
25
+ private smoothedActiveRings;
26
+ private smoothedAmplitude;
27
+ private bgSpeed;
28
+ private lastMaxHeight;
29
+ private diffHeight;
30
+ private tidalOffset;
31
+ private readonly smoothingFactor;
32
+ private params;
33
+ constructor(keyboardConfig: KeyboardConfig);
34
+ /** 键盘行数 */
35
+ private get keyboardRows();
36
+ /** 键盘最大列数值(含最大列偏移) */
37
+ private get keyboardMaxCols();
38
+ /** 中心点 Y */
39
+ private get centerY();
40
+ /** 中心点 X */
41
+ private get centerX();
42
+ /** 按键总数 */
43
+ private get keyCount();
44
+ /**
45
+ * 渲染一帧按键 RGB 网格
46
+ * @param params 当前帧参数
47
+ * @returns 按键 RGB 网格 [row][col]
48
+ */
49
+ render(params: MusicV2RenderParams): RgbColor[][];
50
+ /** 根据模式填充背景颜色 */
51
+ fillModeColor(keysRgb: RgbColor[][], mode: number, brightness?: number): void;
52
+ /** 填充单色 */
53
+ private drawSolidColor;
54
+ /** 填充色谱 */
55
+ private drawColorWheel;
56
+ /** 填充频谱循环 */
57
+ private drawSpectrumCycle;
58
+ /** 填充多行颜色 */
59
+ private drawMultiRowColors;
60
+ /** 随曲起舞 */
61
+ private visualizerDance;
62
+ /** 双心共舞 */
63
+ private visualizerDualCenterDance;
64
+ /** 尘埃光漩(旋转线条) */
65
+ private visualizerRotatingLines;
66
+ /** 蛰伏火山(山) */
67
+ private visualizerMountains;
68
+ /** 光矢穿心(爱心) */
69
+ private visualizerHeart;
70
+ /** 光茧共振 */
71
+ private visualizerAfternoonSunlight;
72
+ /** 音叉振空(潮汐共振) */
73
+ private visualizerTidalResonance;
74
+ /** 萤火轨迹(线性波动) */
75
+ private visualizerLinearWave;
76
+ /** 曲率遗轨(线性波动缩短) */
77
+ private visualizerLinearWaveShortened;
78
+ /** 行波律动 */
79
+ private visualizerRowWaveRhythm;
80
+ /** 曲率频阶(底部到顶部) */
81
+ private visualizerBottomToTop;
82
+ }
@@ -1,3 +1,3 @@
1
- export { setInterval, clearInterval } from 'worker-timers';
1
+ export { setInterval, clearInterval, setTimeout, clearTimeout } from 'worker-timers';
2
2
  export * from '../shared/types';
3
3
  export { serializePreset, deserializePreset } from '../shared/serialize';