Skip to content

Commit c905c62

Browse files
authored
integrate json2daisy into hvcc (#307)
* integrate json2daisy into hvcc * drop wstd2daisy dependency; update changelog * fix package resource path * cleanup
1 parent 1a607e5 commit c905c62

31 files changed

Lines changed: 6061 additions & 25 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Bugfixes:
1919
* c2dpf: portGroup template fix with i/o port 0 as CV
2020
* c2wwise: use correct SDK header paths and allow any platform in the xml - thanks to @eu-ch
2121

22+
Updates:
23+
24+
* drop py3.8 - add py3.13
25+
* integrate json2daisy library, tests and documentation
26+
2227
0.13.4
2328
-----
2429

docs/03.gen.daisy.components.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
## Custom JSON
2+
3+
JSON is a human-readable file format for data storage, and it's what plugdata uses to help translate your Pd patch into something that will run on a Daisy-based board. If you haven't worked with something like it before, it might look a little strange, but don't worry! We'll cover enough here to get you on your way to custom hardware in no time.
4+
5+
### JSON Basics
6+
7+
For most hardware descriptions, there are only three JSON concepts you need to know: numbers, strings, and objects.
8+
9+
#### Numbers and strings
10+
11+
Numbers are just numbers! They can be integers (1, 2, 3) or any real number (3.141), and don't need any special formatting or indication.
12+
13+
Text data is stored as "strings", which are strings of characters enclosed in double quote marks ("like this :O").
14+
15+
#### Objects
16+
17+
An object is a set of _name_, _value_ pairs, enclosed in curly brackets. Each name is a unique string, and each value can be a number, a string, or another object. The name and value are separated by a colon. For a simple object, you might just have one name with a simple value:
18+
19+
```json
20+
{ "pin": 15 }
21+
```
22+
23+
When things get a little more complicated, such as objects with mutliple pairs, the pairs are usually broken up into their own lines for readability:
24+
25+
```json
26+
{
27+
"component": "Encoder",
28+
"pin": {
29+
"a": 12,
30+
"b": 11,
31+
"click": 0
32+
}
33+
}
34+
```
35+
36+
An object with multiple pairs must have commas between each.
37+
38+
To make editing JSON by hand easy, it's usually best to use a program that provides syntax highlighting (like the colors you see on this page). [VS Code](https://code.visualstudio.com/) is a great cross-platform tool for this. Of course, you can just use a normal text editor, but errors may be more difficult to spot, and some may even mangle the text in undesireable ways.
39+
40+
### Board description format
41+
42+
To describe a board, your JSON will need an object with a few critical pairs:
43+
44+
- name
45+
- This describes your project name and determines the names of automatically generated files
46+
- som
47+
- This is the SOM (system-on-module) that your project uses. This will usually be the Daisy Seed, but can also be the Patch SM.
48+
- The exact strings are:
49+
- `"seed"`
50+
- `"patch_sm"`
51+
- audio
52+
- This is an object describing your audio layout. For most projects, this will simply have a single pair describing the number of audio channels:
53+
```json
54+
{ "channels": 2 }
55+
```
56+
- components
57+
- This is the meat of your description. Here, you'll describe all the input and output components of your design such as knobs, CVs, LEDs, and so on. The name determines the receive or send name in your Pd patch, and must have an object with a `"component"` name. For example, a gate input could be described as:
58+
59+
```json
60+
"components": {
61+
"myGateIn": {
62+
"component": "GateIn",
63+
"pin": 20
64+
}
65+
}
66+
```
67+
- More complicated objects may have more required fields.
68+
69+
So, a very simple but viable board description might look like:
70+
71+
```json
72+
{
73+
"name": "MyProject",
74+
"som": "seed",
75+
"audio": { "channels": 2 },
76+
"components": {
77+
"myGateIn": {
78+
"component": "GateIn",
79+
"pin": 20
80+
}
81+
}
82+
}
83+
84+
```
85+
86+
### Component reference
87+
88+
| Type | _variant | Behavior |
89+
| --- | --- | --- |
90+
| **Inputs** | --- | --- |
91+
| AnalogControl | --- | Returns a floating point representation of the voltage at its input. The typical range is 0-5 V, which is represented as 0-1. |
92+
| BipolarAnalogControl | --- | Similar to a regular analog control, but can handle negative voltages. |
93+
| Switch | --- | Returns a bang on the signal's rising edge (i.e. when the switch is actuated). |
94+
| Switch | _press | Returns a float representing the current state (1 = pressed, 0 = not pressed) |
95+
| Switch | _fall | Returns a bang on the signal's falling edge (i.e. when the switch is released). |
96+
| Switch | _seconds | Returns a float representing the number of seconds the switch has been held down. |
97+
| Switch3 | --- | Returns a float representing the current state, either 0 or 1. |
98+
| Encoder | --- | Returns a 1 if turned one direction, -1 if turned in the other, and 0 otherwise. |
99+
| Encoder | \_rise | Returns a bang when the encoder is pressed. The special alias _EncSwitch_ is always bound to this. |
100+
| Encoder | _press | Same as switch _press. |
101+
| Encoder | _fall | Same as switch _fall. |
102+
| Encoder | _seconds | Same as switch _seconds. |
103+
| GateIn | --- | Returns a float representing the current gate voltage, where a _high_ voltage is 1 and a _low_ voltage is 0. |
104+
| GateIn | _trig | Returns a bang on the rising edge of the gate signal. |
105+
| **Outputs** | --- | --- |
106+
| CVOuts | --- | Expects a floating point value from 0-1, usually converted to 0-5V. |
107+
| GateOut | --- | Expects a floating point value from 0-1. 0 sets the output low, and 1 sets it high. |
108+
| Led | --- | Expects a floating point value from 0-1. The brightness is PWM modulated to match the input. |
109+
| RgbLed | --- | Expects a floating point value from 0-1. The default behavior sets all three colors to the same brightness. |
110+
| RgbLed | _white | Same as default. |
111+
| RgbLed | _red | Expects a floating point value from 0-1. Sets the brightness of the red LED only. |
112+
| RgbLed | _green | Expects a floating point value from 0-1. Sets the brightness of the green LED only. |
113+
| RgbLed | _blue | Expects a floating point value from 0-1. Sets the brightness of the blue LED only. |
114+
115+
### Built-in descriptions
116+
117+
If some details are still unclear, the [JSON descriptions for the built-in boards](https://github.com/Wasted-Audio/hvcc/tree/develop/hvcc/generators/c2daisy/json2daisy/resources) might help.

docs/03.gen.daisy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Which can be configured using the `-m` metadata.json `daisy.board` setting:
2020
}
2121
```
2222

23-
However one can also create custom board layouts. See [the Electro-Smith documentation](https://github.com/electro-smith/DaisyWiki/wiki/Pd2dsy-Guide) for more information.
23+
However one can also create custom board layouts. See [the Daisy Component documentation](03.gen.daisy.components.md) for more information.
2424

2525
The custom layout can be passed on via the meta.json as such:
2626

@@ -112,4 +112,4 @@ The linker and `APP_TYPE` can be set in the json metadata accordingly:
112112
"bootloader": <APP_TYPE>
113113
}
114114
}
115-
```
115+
```

hvcc/generators/c2daisy/c2daisy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import os
33
import shutil
44
import time
5-
import json2daisy # type: ignore
65

76
from typing import Any, Dict, Optional
87

98
from ..copyright import copyright_manager
10-
from . import parameters
9+
from .parameters import parse_parameters
10+
from .json2daisy import generate_header_from_file, generate_header_from_name
1111

1212
from hvcc.interpreters.pd2hv.NotificationEnum import NotificationEnum
1313
from hvcc.types.compiler import Generator, CompilerResp, CompilerNotif, CompilerMsg, ExternInfo
@@ -67,15 +67,15 @@ def compile(
6767
shutil.copytree(c_src_dir, source_dir)
6868

6969
if daisy_meta.board_file is not None:
70-
header, board_info = json2daisy.generate_header_from_file(daisy_meta.board_file)
70+
header, board_info = generate_header_from_file(daisy_meta.board_file)
7171
else:
72-
header, board_info = json2daisy.generate_header_from_name(board)
72+
header, board_info = generate_header_from_name(board)
7373

7474
# remove heavy out params from externs
7575
externs.parameters.outParam = [
7676
t for t in externs.parameters.outParam if not any(x == y for x in hv_midi_messages for y in t)]
7777

78-
component_glue = parameters.parse_parameters(
78+
component_glue = parse_parameters(
7979
externs.parameters, board_info['components'], board_info['aliases'], 'hardware')
8080
component_glue['class_name'] = board_info['name']
8181
component_glue['patch_name'] = patch_name
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Electrosmith
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .json2daisy import * # noqa

0 commit comments

Comments
 (0)