osynic_midi 0.1.0

A MIDI -> keyboard mapper for the Osynic
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# CLI 使用指南 | CLI Usage Guide


## 中文版本


### 概述

`osynic-midi` 命令行工具允许你从终端控制 MIDI 到键盘的映射。支持交互式菜单和直接参数两种使用方式。

### 编译


#### 开发版本

```bash
cargo build
```
输出:`target/debug/osynic-midi.exe`

#### 发布版本(推荐用于生产环境)

```bash
cargo build --release
```
输出:`target/release/osynic-midi.exe`

### 子命令详解


#### 1. 列出 MIDI 设备

```bash
osynic-midi list-devices
```

列出系统中所有连接的 MIDI 输入设备。

**示例输出**:
```
Available MIDI input devices:
  0: X8III
  1: MIDIIN2 (X8III)
  2: loopMIDI Port
  3: loopMIDI Port 1
```

#### 2. 列出配置文件

```bash
osynic-midi list-configs
```

列出 `configs` 目录中所有可用的 MIDI 映射配置文件。

**示例输出**:
```
Available configuration files:
  0: midi_config.json
  1: midi_config_10ka.json
  2: midi_config_10kab.json
  ...
```

#### 3. 启动映射(交互式)

```bash
osynic-midi start
```

使用交互式菜单启动 MIDI 映射。将按顺序引导你:
1. 选择配置文件
2. 选择 MIDI 输入设备
3. 选择映射模式(音符或八度)

**菜单示例**:
```
? Select configuration file:
❯ midi_config.json
  midi_config_10ka.json
  midi_config_10kab.json
```

使用方法:
- `` 向上移动
- `` 向下移动
- `Enter` 确认选择
- `Ctrl+C` 中止

#### 4. 使用指定配置启动

```bash
osynic-midi start --config configs/midi_config_10ka.json
```

或简写:
```bash
osynic-midi start -c configs/midi_config_10ka.json
```

#### 5. 指定映射模式

```bash
osynic-midi start --mode notes
# 
osynic-midi start --mode octaves
```

或简写:
```bash
osynic-midi start -m notes
osynic-midi start -m octaves
```

#### 6. 组合:配置 + 模式

```bash
osynic-midi start -c configs/midi_config.json -m notes
```

这种非交互式方式适合脚本和自动化任务。

### 映射模式说明


#### 音符模式 (Notes)

将单个 MIDI 音符映射到特定的键盘按键。基于配置文件中的 `note_mappings` 部分。

**适用场景**:当你希望为每个音符指定特定的按键时。

#### 八度模式 (Octaves)

基于八度和音高名称映射 MIDI 音符。按八度和音高(C、C#/Db、D 等)分组。

**适用场景**:当你有八度基础的键盘布局时。

### 配置文件格式


配置文件采用 JSON 格式,存储在 `configs` 目录中。

#### 示例结构:

```json
{
  "mapping_mode": "notes",
  "velocity_threshold": 0,
  "octaves": {
    "3": {
      "C": "A",
      "C#/Db": "S",
      "D": "D",
      "D#/Eb": "F",
      "E": "G",
      ...
    }
  },
  "note_mappings": {
    "0": "Key_0",
    "1": "Key_1",
    ...
    "127": "Key_127"
  }
}
```

#### 字段说明:


- **mapping_mode**:默认模式("notes" 或 "octaves"),可由 CLI 参数覆盖
- **velocity_threshold**:MIDI 力度阈值(0-127),低于此值的按键将被忽略
- **octaves**:音符映射字典,按八度分组,再按音高分组
- **note_mappings**:音符编号(0-127)到键盘按键的直接映射

### 支持的按键名称


配置文件中支持以下按键名称:

#### 字母:

A-Z(单个大写字母)

#### 符号:

- `,` - 逗号
- `.` - 句号
- `/` - 正斜杠
- `;` - 分号
- `'` - 撇号
- `[` - 左方括号
- `]` - 右方括号
- `\` - 反斜杠
- `-` - 连字符
- `=` - 等号

#### 特殊按键:

- `Space` - 空格键
- `Left` - 左箭头键
- `Right` - 右箭头键
- `RAlt` - 右 Alt 键

### 工作流示例


#### 示例 1:快速启动(使用默认配置和音符模式)

```bash
osynic-midi start -c configs/midi_config.json -m notes
```

#### 示例 2:交互式设置

```bash
osynic-midi start
```

按照提示逐步完成配置。

#### 示例 3:启动前检查设备

```bash
osynic-midi list-devices
osynic-midi list-configs
osynic-midi start
```

### 操作期间的键盘快捷键


- **Enter**:退出 MIDI 映射应用程序

### 故障排除


#### 常见问题:


1. **找不到 MIDI 设备**
   - 安装 MIDI 设备驱动程序
   - 检查设备是否正确连接
   - 尝试重新启动应用程序

2. **配置文件无法加载**
   - 确保配置文件位于 `configs` 目录
   - 检查 JSON 格式是否有效
   - 检查文件权限

3. **键盘输入无法工作**
   - 某些应用程序可能限制键盘输入
   - 尝试以管理员权限运行
   - 检查操作系统安全设置

---

## English Version


### Overview

The `osynic-midi` command-line tool allows you to control MIDI-to-keyboard mapping from the terminal. It supports both interactive menu mode and direct parameter mode.

### Compilation


#### Debug build

```bash
cargo build
```
Output: `target/debug/osynic-midi.exe`

#### Release build (Recommended for production)

```bash
cargo build --release
```
Output: `target/release/osynic-midi.exe`

### Commands


#### 1. List MIDI Devices

```bash
osynic-midi list-devices
```

Lists all MIDI input devices currently connected to your system.

**Example output**:
```
Available MIDI input devices:
  0: X8III
  1: MIDIIN2 (X8III)
  2: loopMIDI Port
  3: loopMIDI Port 1
```

#### 2. List Configuration Files

```bash
osynic-midi list-configs
```

Displays all available MIDI mapping configuration files in the `configs` directory.

**Example output**:
```
Available configuration files:
  0: midi_config.json
  1: midi_config_10ka.json
  2: midi_config_10kab.json
  ...
```

#### 3. Start Mapping (Interactive)

```bash
osynic-midi start
```

Start MIDI mapping with interactive prompts to select device, configuration, and mapping mode.

**Menu example**:
```
? Select configuration file:
❯ midi_config.json
  midi_config_10ka.json
  midi_config_10kab.json
```

Controls:
- `` Move up
- `` Move down
- `Enter` Confirm selection
- `Ctrl+C` Abort

#### 4. Start with Specific Configuration

```bash
osynic-midi start --config configs/midi_config_10ka.json
```

Or shorthand:
```bash
osynic-midi start -c configs/midi_config_10ka.json
```

#### 5. Specify Mapping Mode

```bash
osynic-midi start --mode notes
# or

osynic-midi start --mode octaves
```

Or shorthand:
```bash
osynic-midi start -m notes
osynic-midi start -m octaves
```

#### 6. Combined: Config + Mode

```bash
osynic-midi start -c configs/midi_config.json -m notes
```

This non-interactive mode is perfect for scripts and automation.

### Mapping Modes


#### Notes Mode

Maps individual MIDI notes to specific keyboard keys based on the `note_mappings` configuration.

**Use case**: When you want specific keys for each note number.

#### Octaves Mode

Maps MIDI notes based on octave and pitch name (C, C#/Db, D, etc.).

**Use case**: When you have octave-based keyboard layouts.

### Configuration File Format


Configuration files are JSON-based and located in the `configs` directory.

#### Example structure:

```json
{
  "mapping_mode": "notes",
  "velocity_threshold": 0,
  "octaves": {
    "3": {
      "C": "A",
      "C#/Db": "S",
      "D": "D",
      ...
    }
  },
  "note_mappings": {
    "0": "Key_0",
    "1": "Key_1",
    ...
    "127": "Key_127"
  }
}
```

#### Field explanations:


- **mapping_mode**: Default mode ("notes" or "octaves"), can be overridden by CLI argument
- **velocity_threshold**: MIDI velocity threshold (0-127), keys below are ignored
- **octaves**: Note mapping dictionary structured by octave and pitch
- **note_mappings**: Direct note (0-127) to keyboard key mapping

### Supported Key Names


The following key names are supported in configuration files:

#### Letters:

A-Z (single uppercase letter)

#### Symbols:

- `,` - Comma
- `.` - Period
- `/` - Forward slash
- `;` - Semicolon
- `'` - Apostrophe
- `[` - Left bracket
- `]` - Right bracket
- `\` - Backslash
- `-` - Hyphen
- `=` - Equals

#### Special Keys:

- `Space` - Spacebar
- `Left` - Left arrow key
- `Right` - Right arrow key
- `RAlt` - Right Alt key

### Workflow Examples


#### Example 1: Quick start with default config and notes mode

```bash
osynic-midi start -c configs/midi_config.json -m notes
```

#### Example 2: Interactive setup

```bash
osynic-midi start
```

Follow the prompts for step-by-step configuration.

#### Example 3: Check devices before starting

```bash
osynic-midi list-devices
osynic-midi list-configs
osynic-midi start
```

### Keyboard Shortcuts During Operation


- **Enter**: Exit the MIDI mapping application

### Troubleshooting


#### Common Issues:


1. **No MIDI devices found**
   - Install MIDI device drivers
   - Check if devices are properly connected
   - Try restarting the application

2. **Cannot load configuration file**
   - Ensure the configuration file is in the `configs` directory
   - Verify JSON format is valid
   - Check file permissions

3. **Keyboard input doesn't work**
   - Some applications may restrict keyboard input
   - Try running with administrator privileges
   - Check operating system security settings