@vessel-dsp/core 0.5.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.
- package/LICENSE.md +21 -0
- package/README.md +6 -0
- package/package.json +56 -0
- package/src/editor/commands.ts +344 -0
- package/src/editor/factory.ts +148 -0
- package/src/editor/history.ts +142 -0
- package/src/editor/index.ts +11 -0
- package/src/editor/layout.ts +207 -0
- package/src/formats/circuit-json/serializer.ts +1410 -0
- package/src/formats/document.ts +274 -0
- package/src/formats/interchange/parser.ts +1165 -0
- package/src/formats/interchange/serializer.ts +594 -0
- package/src/formats/ltspice/catalog.ts +181 -0
- package/src/formats/ltspice/encoding.ts +151 -0
- package/src/formats/ltspice/parser.ts +432 -0
- package/src/formats/ltspice/serializer.ts +169 -0
- package/src/formats/schx/catalog.ts +439 -0
- package/src/formats/schx/parser.ts +261 -0
- package/src/formats/schx/runtime-descriptors.ts +502 -0
- package/src/formats/schx/serializer.ts +211 -0
- package/src/formats/schx/transforms.ts +38 -0
- package/src/formats/spice/parser.ts +373 -0
- package/src/formats/spice/serializer.ts +43 -0
- package/src/index.ts +205 -0
- package/src/model/connectivity.ts +239 -0
- package/src/model/netlist.ts +375 -0
- package/src/model/properties.ts +101 -0
- package/src/model/quantity.ts +173 -0
- package/src/model/types.ts +309 -0
- package/src/model/validation.ts +985 -0
- package/src/model/wires.ts +86 -0
- package/src/panel/extract.ts +878 -0
- package/src/panel/index.ts +39 -0
- package/src/panel/knobs.ts +70 -0
- package/src/panel/protocol.ts +117 -0
- package/src/panel/types.ts +180 -0
- package/src/preview/bounds.ts +85 -0
- package/src/preview/box-layout.ts +24 -0
- package/src/preview/colors.ts +43 -0
- package/src/preview/hanging.ts +94 -0
- package/src/preview/junctions.ts +94 -0
- package/src/preview/label-layout.ts +90 -0
- package/src/preview/ports.ts +101 -0
- package/src/preview/renderable-wires.ts +113 -0
- package/src/preview/routing.ts +15 -0
- package/src/preview/snap.ts +104 -0
- package/src/preview/symbols/analog-switch.svg +17 -0
- package/src/preview/symbols/battery.svg +16 -0
- package/src/preview/symbols/bbd.svg +21 -0
- package/src/preview/symbols/bjt-npn.svg +16 -0
- package/src/preview/symbols/bjt-pnp.svg +17 -0
- package/src/preview/symbols/capacitor-electrolytic.svg +13 -0
- package/src/preview/symbols/capacitor.svg +12 -0
- package/src/preview/symbols/current-source.svg +14 -0
- package/src/preview/symbols/delay-ic.svg +22 -0
- package/src/preview/symbols/diode-schottky.svg +12 -0
- package/src/preview/symbols/diode-zener.svg +12 -0
- package/src/preview/symbols/diode.svg +13 -0
- package/src/preview/symbols/flipflop.svg +20 -0
- package/src/preview/symbols/ground.svg +12 -0
- package/src/preview/symbols/ic-block.svg +20 -0
- package/src/preview/symbols/ic.svg +19 -0
- package/src/preview/symbols/inductor.svg +11 -0
- package/src/preview/symbols/jack-input.svg +16 -0
- package/src/preview/symbols/jack-output.svg +16 -0
- package/src/preview/symbols/jfet-junction-n.svg +17 -0
- package/src/preview/symbols/jfet-n.svg +17 -0
- package/src/preview/symbols/jfet-p.svg +17 -0
- package/src/preview/symbols/label.svg +8 -0
- package/src/preview/symbols/led.svg +18 -0
- package/src/preview/symbols/mosfet-n.svg +21 -0
- package/src/preview/symbols/mosfet-p.svg +21 -0
- package/src/preview/symbols/named-wire.svg +11 -0
- package/src/preview/symbols/opamp.svg +21 -0
- package/src/preview/symbols/optocoupler.svg +30 -0
- package/src/preview/symbols/ota.svg +20 -0
- package/src/preview/symbols/pentode.svg +25 -0
- package/src/preview/symbols/photoresistor.svg +19 -0
- package/src/preview/symbols/port.svg +8 -0
- package/src/preview/symbols/potentiometer.svg +15 -0
- package/src/preview/symbols/power-amp.svg +20 -0
- package/src/preview/symbols/rail.svg +11 -0
- package/src/preview/symbols/regulator.svg +13 -0
- package/src/preview/symbols/relay.svg +20 -0
- package/src/preview/symbols/resistor.svg +11 -0
- package/src/preview/symbols/svg-content.ts +59 -0
- package/src/preview/symbols/switch-3pdt.svg +32 -0
- package/src/preview/symbols/switch-rotary.svg +23 -0
- package/src/preview/symbols/switch-spdt.svg +16 -0
- package/src/preview/symbols/switch-spst.svg +14 -0
- package/src/preview/symbols/switch-toggle.svg +14 -0
- package/src/preview/symbols/transformer.svg +17 -0
- package/src/preview/symbols/triode.svg +17 -0
- package/src/preview/symbols/tube-diode.svg +13 -0
- package/src/preview/symbols/unsupported.svg +8 -0
- package/src/preview/symbols/variable-resistor.svg +13 -0
- package/src/preview/symbols/voltage-source.svg +15 -0
- package/src/preview/symbols.ts +207 -0
- package/src/preview/wire-chains.ts +153 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import type { ComponentKind, Point } from '../../model/types';
|
|
2
|
+
|
|
3
|
+
export type SchxTerminalLocal = Readonly<{ name: string; local: Point }>;
|
|
4
|
+
|
|
5
|
+
export type SchxComponentDef = Readonly<{
|
|
6
|
+
shortType: string;
|
|
7
|
+
kind: ComponentKind;
|
|
8
|
+
terminals: readonly SchxTerminalLocal[];
|
|
9
|
+
quantityProps: readonly string[];
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
const TWO_TERMINAL_AB: readonly SchxTerminalLocal[] = [
|
|
13
|
+
{ name: 'a', local: { x: 0, y: 20 } },
|
|
14
|
+
{ name: 'b', local: { x: 0, y: -20 } },
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const TWO_TERMINAL_DIODE: readonly SchxTerminalLocal[] = [
|
|
18
|
+
{ name: 'anode', local: { x: 0, y: 20 } },
|
|
19
|
+
{ name: 'cathode', local: { x: 0, y: -20 } },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const TWO_TERMINAL_SOURCE: readonly SchxTerminalLocal[] = [
|
|
23
|
+
{ name: '+', local: { x: 0, y: 20 } },
|
|
24
|
+
{ name: '-', local: { x: 0, y: -20 } },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const SINGLE_TERMINAL: readonly SchxTerminalLocal[] = [
|
|
28
|
+
{ name: 't', local: { x: 0, y: 0 } },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const BJT_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
32
|
+
{ name: 'collector', local: { x: 0, y: 20 } },
|
|
33
|
+
{ name: 'base', local: { x: -20, y: 0 } },
|
|
34
|
+
{ name: 'emitter', local: { x: 10, y: -20 } },
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const SPDT_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
38
|
+
{ name: 'common', local: { x: -20, y: 0 } },
|
|
39
|
+
{ name: 'throw0', local: { x: 0, y: 20 } },
|
|
40
|
+
{ name: 'throw1', local: { x: 10, y: -20 } },
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const SP3T_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
44
|
+
{ name: 'common', local: { x: -20, y: 0 } },
|
|
45
|
+
{ name: 'throw0', local: { x: 0, y: 20 } },
|
|
46
|
+
{ name: 'throw1', local: { x: 10, y: 0 } },
|
|
47
|
+
{ name: 'throw2', local: { x: 0, y: -20 } },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const SP4T_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
51
|
+
{ name: 'common', local: { x: -20, y: 0 } },
|
|
52
|
+
{ name: 'throw0', local: { x: 0, y: 20 } },
|
|
53
|
+
{ name: 'throw1', local: { x: 10, y: 7 } },
|
|
54
|
+
{ name: 'throw2', local: { x: 10, y: -7 } },
|
|
55
|
+
{ name: 'throw3', local: { x: 0, y: -20 } },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const JFET_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
59
|
+
{ name: 'drain', local: { x: 0, y: 20 } },
|
|
60
|
+
{ name: 'gate', local: { x: -20, y: 0 } },
|
|
61
|
+
{ name: 'source', local: { x: 0, y: -20 } },
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const LIVE_SPICE_JUNCTION_FET_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
65
|
+
{ name: 'drain', local: { x: 10, y: 20 } },
|
|
66
|
+
{ name: 'gate', local: { x: -20, y: 0 } },
|
|
67
|
+
{ name: 'source', local: { x: 10, y: -20 } },
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const MOSFET_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
71
|
+
{ name: 'drain', local: { x: 0, y: 20 } },
|
|
72
|
+
{ name: 'gate', local: { x: -20, y: 0 } },
|
|
73
|
+
{ name: 'source', local: { x: 0, y: -20 } },
|
|
74
|
+
{ name: 'body', local: { x: 10, y: 0 } },
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const OPAMP_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
78
|
+
{ name: 'vin+', local: { x: -30, y: 10 } },
|
|
79
|
+
{ name: 'vin-', local: { x: -30, y: -10 } },
|
|
80
|
+
{ name: 'vout', local: { x: 30, y: 0 } },
|
|
81
|
+
{ name: 'vcc', local: { x: 0, y: 20 } },
|
|
82
|
+
{ name: 'vee', local: { x: 0, y: -20 } },
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
const TRIODE_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
86
|
+
{ name: 'plate', local: { x: 0, y: 20 } },
|
|
87
|
+
{ name: 'grid', local: { x: -20, y: 0 } },
|
|
88
|
+
{ name: 'cathode', local: { x: -10, y: -20 } },
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
const PENTODE_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
92
|
+
{ name: 'plate', local: { x: 0, y: 20 } },
|
|
93
|
+
{ name: 'screen', local: { x: 10, y: 10 } },
|
|
94
|
+
{ name: 'grid', local: { x: -20, y: 0 } },
|
|
95
|
+
{ name: 'cathode', local: { x: -10, y: -20 } },
|
|
96
|
+
{ name: 'suppressor', local: { x: 10, y: -10 } },
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
const POT_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
100
|
+
{ name: 'a', local: { x: -10, y: 40 } },
|
|
101
|
+
{ name: 'wiper', local: { x: 10, y: 0 } },
|
|
102
|
+
{ name: 'b', local: { x: -10, y: -40 } },
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
const TRANSFORMER_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
106
|
+
{ name: 'p+', local: { x: -10, y: 20 } },
|
|
107
|
+
{ name: 'p-', local: { x: -10, y: -20 } },
|
|
108
|
+
{ name: 's+', local: { x: 10, y: 20 } },
|
|
109
|
+
{ name: 's-', local: { x: 10, y: -20 } },
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
const CENTER_TAP_TRANSFORMER_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
113
|
+
...TRANSFORMER_TERMINALS,
|
|
114
|
+
{ name: 'sct', local: { x: 10, y: 0 } },
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
const VOLTAGE_DEFINITION_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
118
|
+
{ name: '+', local: { x: 0, y: -50 } },
|
|
119
|
+
{ name: '-', local: { x: 0, y: 50 } },
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
// 3PDT footswitch — 3 columns (one per pole) × 3 rows (top throw / pole / bottom throw).
|
|
123
|
+
// Pole names are p1..p3; per-pole throws are tNa (top, world-down → SVG y=+20) and tNb (bottom).
|
|
124
|
+
// The "ganged" mechanical link is implicit — wires define which throws are connected to what.
|
|
125
|
+
const THREE_PDT_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
126
|
+
{ name: 't1a', local: { x: -20, y: 20 } },
|
|
127
|
+
{ name: 'p1', local: { x: -20, y: 0 } },
|
|
128
|
+
{ name: 't1b', local: { x: -20, y: -20 } },
|
|
129
|
+
{ name: 't2a', local: { x: 0, y: 20 } },
|
|
130
|
+
{ name: 'p2', local: { x: 0, y: 0 } },
|
|
131
|
+
{ name: 't2b', local: { x: 0, y: -20 } },
|
|
132
|
+
{ name: 't3a', local: { x: 20, y: 20 } },
|
|
133
|
+
{ name: 'p3', local: { x: 20, y: 0 } },
|
|
134
|
+
{ name: 't3b', local: { x: 20, y: -20 } },
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
// LM13700-style OTA: differential inputs + bias current + output. Two amps per package
|
|
138
|
+
// are modeled as separate symbols sharing the same supply.
|
|
139
|
+
const OTA_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
140
|
+
{ name: 'vin+', local: { x: -30, y: 10 } },
|
|
141
|
+
{ name: 'vin-', local: { x: -30, y: -10 } },
|
|
142
|
+
{ name: 'ibias', local: { x: -30, y: 20 } },
|
|
143
|
+
{ name: 'iout', local: { x: 30, y: 0 } },
|
|
144
|
+
{ name: 'vcc', local: { x: 0, y: 20 } },
|
|
145
|
+
{ name: 'vee', local: { x: 0, y: -20 } },
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
// Bucket-brigade delay (MN3007/3008/3205 family). Symmetric balanced outputs.
|
|
149
|
+
const BBD_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
150
|
+
{ name: 'vdd', local: { x: -30, y: 20 } },
|
|
151
|
+
{ name: 'vgg', local: { x: -30, y: 0 } },
|
|
152
|
+
{ name: 'vss', local: { x: -30, y: -20 } },
|
|
153
|
+
{ name: 'cp1', local: { x: 0, y: 20 } },
|
|
154
|
+
{ name: 'cp2', local: { x: 0, y: -20 } },
|
|
155
|
+
{ name: 'in', local: { x: -30, y: -10 } },
|
|
156
|
+
{ name: 'out1', local: { x: 30, y: 10 } },
|
|
157
|
+
{ name: 'out2', local: { x: 30, y: -10 } },
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
// PT2399 digital echo IC (16-pin DIP). Key audio + control pins; others omitted from the
|
|
161
|
+
// terminal map but still preserved as raw_attributes properties on the component.
|
|
162
|
+
const PT2399_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
163
|
+
{ name: 'vcc', local: { x: -30, y: 20 } },
|
|
164
|
+
{ name: 'gnd', local: { x: -30, y: -20 } },
|
|
165
|
+
{ name: 'vref', local: { x: -30, y: 10 } },
|
|
166
|
+
{ name: 'vco', local: { x: -30, y: 0 } },
|
|
167
|
+
{ name: 'in', local: { x: -30, y: -10 } },
|
|
168
|
+
{ name: 'out', local: { x: 30, y: 10 } },
|
|
169
|
+
{ name: 'fb', local: { x: 30, y: 0 } },
|
|
170
|
+
{ name: 'da1', local: { x: 30, y: -5 } },
|
|
171
|
+
{ name: 'da2', local: { x: 30, y: -10 } },
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
// LM386 mini power amp (8-pin DIP).
|
|
175
|
+
const LM386_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
176
|
+
{ name: 'gain1', local: { x: -30, y: 20 } },
|
|
177
|
+
{ name: 'vin-', local: { x: -30, y: 10 } },
|
|
178
|
+
{ name: 'vin+', local: { x: -30, y: 0 } },
|
|
179
|
+
{ name: 'gnd', local: { x: -30, y: -20 } },
|
|
180
|
+
{ name: 'vout', local: { x: 30, y: 0 } },
|
|
181
|
+
{ name: 'vs', local: { x: 30, y: 20 } },
|
|
182
|
+
{ name: 'bypass', local: { x: 30, y: 10 } },
|
|
183
|
+
{ name: 'gain8', local: { x: 30, y: -20 } },
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
const MICROBLOCK_STAGE_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
187
|
+
{ name: 'in', local: { x: 0, y: 20 } },
|
|
188
|
+
{ name: 'out', local: { x: 0, y: -20 } },
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
const RUNTIME_DESCRIPTOR_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
192
|
+
{ name: 'input', local: { x: 0, y: 20 } },
|
|
193
|
+
{ name: 'output', local: { x: 0, y: -20 } },
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
const MICROBLOCK_STAGE_QUANTITY_PROPS: readonly string[] = [
|
|
197
|
+
'ClipThreshold',
|
|
198
|
+
'InputHighpassHz',
|
|
199
|
+
'OutputLowpassHz',
|
|
200
|
+
'MinDriveGain',
|
|
201
|
+
'MaxDriveGain',
|
|
202
|
+
'DriveControlWipe',
|
|
203
|
+
'MinOutputLevel',
|
|
204
|
+
'MaxOutputLevel',
|
|
205
|
+
'OutputControlWipe',
|
|
206
|
+
'MinToneHz',
|
|
207
|
+
'MaxToneHz',
|
|
208
|
+
'ToneControlWipe',
|
|
209
|
+
'DecaySeconds',
|
|
210
|
+
'PreDelaySeconds',
|
|
211
|
+
'DelaySeconds',
|
|
212
|
+
'MinDelaySeconds',
|
|
213
|
+
'MaxDelaySeconds',
|
|
214
|
+
'Feedback',
|
|
215
|
+
'FeedbackControlWipe',
|
|
216
|
+
'Mix',
|
|
217
|
+
'MixControlWipe',
|
|
218
|
+
'WetMix',
|
|
219
|
+
'DryMix',
|
|
220
|
+
'RoomSize',
|
|
221
|
+
'Damping',
|
|
222
|
+
'DampingHz',
|
|
223
|
+
'ModDepth',
|
|
224
|
+
'ModRateHz',
|
|
225
|
+
'SampleRateHz',
|
|
226
|
+
];
|
|
227
|
+
|
|
228
|
+
const RUNTIME_DESCRIPTOR_QUANTITY_PROPS: readonly string[] = [
|
|
229
|
+
...MICROBLOCK_STAGE_QUANTITY_PROPS,
|
|
230
|
+
'MinDelayMs',
|
|
231
|
+
'MaxDelayMs',
|
|
232
|
+
'DelayMs',
|
|
233
|
+
'PreDelayMs',
|
|
234
|
+
'Decay',
|
|
235
|
+
'Damping',
|
|
236
|
+
'Size',
|
|
237
|
+
'Tone',
|
|
238
|
+
'ModDepthMs',
|
|
239
|
+
'MinModDepthMs',
|
|
240
|
+
'MaxModDepthMs',
|
|
241
|
+
'ModRateHz',
|
|
242
|
+
'MinModRateHz',
|
|
243
|
+
'MaxModRateHz',
|
|
244
|
+
'InputDrive',
|
|
245
|
+
'Headroom',
|
|
246
|
+
'Sensitivity',
|
|
247
|
+
'MinSensitivity',
|
|
248
|
+
'MaxSensitivity',
|
|
249
|
+
'AttackMs',
|
|
250
|
+
'MinAttackMs',
|
|
251
|
+
'MaxAttackMs',
|
|
252
|
+
'ReleaseMs',
|
|
253
|
+
'TriggerThreshold',
|
|
254
|
+
'MinGain',
|
|
255
|
+
'MinInputGain',
|
|
256
|
+
'MaxInputGain',
|
|
257
|
+
'BandFrequencyControlWipes',
|
|
258
|
+
'BandControlWipes',
|
|
259
|
+
'MinMix',
|
|
260
|
+
'MaxMix',
|
|
261
|
+
'ToneHz',
|
|
262
|
+
'RateHz',
|
|
263
|
+
'MinRateHz',
|
|
264
|
+
'MaxRateHz',
|
|
265
|
+
'Depth',
|
|
266
|
+
'StageCount',
|
|
267
|
+
'MinFeedback',
|
|
268
|
+
'MaxFeedback',
|
|
269
|
+
'SemitoneShift',
|
|
270
|
+
'MinSemitoneShift',
|
|
271
|
+
'MaxSemitoneShift',
|
|
272
|
+
];
|
|
273
|
+
|
|
274
|
+
const MICROBLOCK_OVERDRIVE_STAGE_DEF: SchxComponentDef = {
|
|
275
|
+
shortType: 'MicroBlockOverdriveStage',
|
|
276
|
+
kind: 'ic',
|
|
277
|
+
terminals: MICROBLOCK_STAGE_TERMINALS,
|
|
278
|
+
quantityProps: MICROBLOCK_STAGE_QUANTITY_PROPS,
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// 78L05 / 78xx 3-terminal linear regulator (TO-92 / TO-220 pinout: input / ground / output).
|
|
282
|
+
const REGULATOR_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
283
|
+
{ name: 'vin', local: { x: -20, y: 0 } },
|
|
284
|
+
{ name: 'gnd', local: { x: 0, y: -20 } },
|
|
285
|
+
{ name: 'vout', local: { x: 20, y: 0 } },
|
|
286
|
+
];
|
|
287
|
+
|
|
288
|
+
// CD4066 quad bilateral switch — one switch element of four. Each instance models one of
|
|
289
|
+
// the four switches in the package; the package itself is implied by Name + Group metadata.
|
|
290
|
+
const ANALOG_SWITCH_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
291
|
+
{ name: 'a', local: { x: -20, y: 10 } },
|
|
292
|
+
{ name: 'b', local: { x: 20, y: 10 } },
|
|
293
|
+
{ name: 'ctrl', local: { x: 0, y: -20 } },
|
|
294
|
+
];
|
|
295
|
+
|
|
296
|
+
// CD4013 dual D flip-flop — single FF instance (D, CLK, Q, Q̅, S, R).
|
|
297
|
+
const FLIPFLOP_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
298
|
+
{ name: 'd', local: { x: -20, y: 10 } },
|
|
299
|
+
{ name: 'clk', local: { x: -20, y: -10 } },
|
|
300
|
+
{ name: 's', local: { x: 0, y: 20 } },
|
|
301
|
+
{ name: 'r', local: { x: 0, y: -20 } },
|
|
302
|
+
{ name: 'q', local: { x: 20, y: 10 } },
|
|
303
|
+
{ name: 'qbar', local: { x: 20, y: -10 } },
|
|
304
|
+
];
|
|
305
|
+
|
|
306
|
+
// Generic opaque IC fallback (4 + 4 pins, DIP-8 layout). Used when no specific catalog
|
|
307
|
+
// entry exists — preserves the source type name for round-tripping.
|
|
308
|
+
const GENERIC_IC_TERMINALS: readonly SchxTerminalLocal[] = [
|
|
309
|
+
{ name: 'p1', local: { x: -20, y: 15 } },
|
|
310
|
+
{ name: 'p2', local: { x: -20, y: 5 } },
|
|
311
|
+
{ name: 'p3', local: { x: -20, y: -5 } },
|
|
312
|
+
{ name: 'p4', local: { x: -20, y: -15 } },
|
|
313
|
+
{ name: 'p5', local: { x: 20, y: -15 } },
|
|
314
|
+
{ name: 'p6', local: { x: 20, y: -5 } },
|
|
315
|
+
{ name: 'p7', local: { x: 20, y: 5 } },
|
|
316
|
+
{ name: 'p8', local: { x: 20, y: 15 } },
|
|
317
|
+
];
|
|
318
|
+
|
|
319
|
+
const DEFS: readonly SchxComponentDef[] = [
|
|
320
|
+
{ shortType: 'Resistor', kind: 'resistor', terminals: TWO_TERMINAL_AB, quantityProps: ['Resistance'] },
|
|
321
|
+
{ shortType: 'Capacitor', kind: 'capacitor', terminals: TWO_TERMINAL_AB, quantityProps: ['Capacitance'] },
|
|
322
|
+
{ shortType: 'Inductor', kind: 'inductor', terminals: TWO_TERMINAL_AB, quantityProps: ['Inductance'] },
|
|
323
|
+
{ shortType: 'Conductor', kind: 'unsupported', terminals: TWO_TERMINAL_AB, quantityProps: [] },
|
|
324
|
+
{ shortType: 'Buffer', kind: 'unsupported', terminals: TWO_TERMINAL_AB, quantityProps: [] },
|
|
325
|
+
{ shortType: 'Diode', kind: 'diode', terminals: TWO_TERMINAL_DIODE, quantityProps: ['IS', 'Is', 'N', 'n', 'Rs'] },
|
|
326
|
+
{ shortType: 'TubeDiode', kind: 'tube-diode', terminals: TWO_TERMINAL_DIODE, quantityProps: [] },
|
|
327
|
+
{ shortType: 'BipolarJunctionTransistor', kind: 'bjt', terminals: BJT_TERMINALS, quantityProps: ['IS', 'BF', 'BR', 'Is', 'Vt', 'Bf', 'Br', 'n'] },
|
|
328
|
+
{ shortType: 'NpnBjt', kind: 'bjt', terminals: BJT_TERMINALS, quantityProps: ['Is', 'Vt', 'Bf', 'Br'] },
|
|
329
|
+
{ shortType: 'PnpBjt', kind: 'bjt', terminals: BJT_TERMINALS, quantityProps: ['Is', 'Vt', 'Bf', 'Br'] },
|
|
330
|
+
{ shortType: 'Bjt', kind: 'bjt', terminals: BJT_TERMINALS, quantityProps: ['Is', 'Vt', 'Bf', 'Br'] },
|
|
331
|
+
{ shortType: 'NjfJfet', kind: 'jfet', terminals: JFET_TERMINALS, quantityProps: ['Is', 'Beta', 'Vt', 'Lambda'] },
|
|
332
|
+
{ shortType: 'PjfJfet', kind: 'jfet', terminals: JFET_TERMINALS, quantityProps: ['Is', 'Beta', 'Vt', 'Lambda'] },
|
|
333
|
+
{ shortType: 'Jfet', kind: 'jfet', terminals: JFET_TERMINALS, quantityProps: ['Is', 'Beta', 'Vt', 'Lambda'] },
|
|
334
|
+
{ shortType: 'JunctionFieldEffectTransistor', kind: 'jfet', terminals: LIVE_SPICE_JUNCTION_FET_TERMINALS, quantityProps: ['IS', 'Is', 'n', 'Vt0', 'Vt', 'Beta', 'Lambda'] },
|
|
335
|
+
{ shortType: 'NMosfet', kind: 'mosfet', terminals: MOSFET_TERMINALS, quantityProps: ['Vto', 'Kp', 'Lambda'] },
|
|
336
|
+
{ shortType: 'PMosfet', kind: 'mosfet', terminals: MOSFET_TERMINALS, quantityProps: ['Vto', 'Kp', 'Lambda'] },
|
|
337
|
+
{ shortType: 'Mosfet', kind: 'mosfet', terminals: MOSFET_TERMINALS, quantityProps: ['Vto', 'Kp', 'Lambda'] },
|
|
338
|
+
{ shortType: 'OpAmp', kind: 'opamp', terminals: OPAMP_TERMINALS, quantityProps: ['SupplyVoltage'] },
|
|
339
|
+
{ shortType: 'IdealOpAmp', kind: 'opamp', terminals: OPAMP_TERMINALS, quantityProps: [] },
|
|
340
|
+
{ shortType: 'OTA', kind: 'ota', terminals: OTA_TERMINALS, quantityProps: ['SupplyVoltage'] },
|
|
341
|
+
{ shortType: 'BBD', kind: 'bbd', terminals: BBD_TERMINALS, quantityProps: ['Stages'] },
|
|
342
|
+
{ shortType: 'PT2399', kind: 'delay-ic', terminals: PT2399_TERMINALS, quantityProps: [] },
|
|
343
|
+
{ shortType: 'LM386', kind: 'power-amp', terminals: LM386_TERMINALS, quantityProps: ['SupplyVoltage'] },
|
|
344
|
+
{ shortType: 'Regulator', kind: 'regulator', terminals: REGULATOR_TERMINALS, quantityProps: ['Vout'] },
|
|
345
|
+
{ shortType: 'AnalogSwitch', kind: 'analog-switch', terminals: ANALOG_SWITCH_TERMINALS, quantityProps: [] },
|
|
346
|
+
{ shortType: 'FlipFlop', kind: 'flipflop', terminals: FLIPFLOP_TERMINALS, quantityProps: [] },
|
|
347
|
+
{ shortType: 'IC', kind: 'ic', terminals: GENERIC_IC_TERMINALS, quantityProps: [] },
|
|
348
|
+
MICROBLOCK_OVERDRIVE_STAGE_DEF,
|
|
349
|
+
{ shortType: 'Triode', kind: 'triode', terminals: TRIODE_TERMINALS, quantityProps: ['Mu', 'K', 'Kp', 'Kvb', 'Ex'] },
|
|
350
|
+
{ shortType: 'Pentode', kind: 'pentode', terminals: PENTODE_TERMINALS, quantityProps: ['Mu', 'K', 'Kp', 'Kvb', 'Ex'] },
|
|
351
|
+
{ shortType: 'Transformer', kind: 'transformer', terminals: TRANSFORMER_TERMINALS, quantityProps: ['Lp', 'Ls', 'k'] },
|
|
352
|
+
{ shortType: 'CenterTapTransformer', kind: 'transformer', terminals: CENTER_TAP_TRANSFORMER_TERMINALS, quantityProps: ['Turns'] },
|
|
353
|
+
{ shortType: 'Potentiometer', kind: 'potentiometer', terminals: POT_TERMINALS, quantityProps: ['Resistance', 'Wipe', 'Sweep'] },
|
|
354
|
+
{ shortType: 'VariableResistor', kind: 'variable-resistor', terminals: TWO_TERMINAL_AB, quantityProps: ['Resistance'] },
|
|
355
|
+
{ shortType: 'Switch', kind: 'switch', terminals: TWO_TERMINAL_AB, quantityProps: [] },
|
|
356
|
+
{ shortType: 'SPDT', kind: 'switch', terminals: SPDT_TERMINALS, quantityProps: [] },
|
|
357
|
+
{ shortType: 'SP3T', kind: 'switch', terminals: SP3T_TERMINALS, quantityProps: [] },
|
|
358
|
+
{ shortType: 'SP4T', kind: 'switch', terminals: SP4T_TERMINALS, quantityProps: [] },
|
|
359
|
+
{ shortType: '3PDT', kind: 'switch', terminals: THREE_PDT_TERMINALS, quantityProps: [] },
|
|
360
|
+
{ shortType: 'VoltageSource', kind: 'voltage-source', terminals: TWO_TERMINAL_SOURCE, quantityProps: ['Voltage'] },
|
|
361
|
+
{ shortType: 'CurrentSource', kind: 'current-source', terminals: TWO_TERMINAL_SOURCE, quantityProps: ['Current'] },
|
|
362
|
+
{ shortType: 'Battery', kind: 'battery', terminals: TWO_TERMINAL_SOURCE, quantityProps: ['Voltage'] },
|
|
363
|
+
{ shortType: 'Rail', kind: 'rail', terminals: SINGLE_TERMINAL, quantityProps: ['Voltage'] },
|
|
364
|
+
{ shortType: 'Ground', kind: 'ground', terminals: SINGLE_TERMINAL, quantityProps: [] },
|
|
365
|
+
{ shortType: 'VoltageDefinition', kind: 'unsupported', terminals: VOLTAGE_DEFINITION_TERMINALS, quantityProps: [] },
|
|
366
|
+
{ shortType: 'Input', kind: 'jack', terminals: TWO_TERMINAL_AB, quantityProps: ['V0dBFS'] },
|
|
367
|
+
{ shortType: 'Speaker', kind: 'jack', terminals: TWO_TERMINAL_AB, quantityProps: ['Impedance', 'V0dBFS'] },
|
|
368
|
+
{ shortType: 'NamedWire', kind: 'named-wire', terminals: SINGLE_TERMINAL, quantityProps: [] },
|
|
369
|
+
{ shortType: 'Label', kind: 'label', terminals: [], quantityProps: [] },
|
|
370
|
+
{ shortType: 'Port', kind: 'port', terminals: SINGLE_TERMINAL, quantityProps: [] },
|
|
371
|
+
];
|
|
372
|
+
|
|
373
|
+
const BY_SHORT_TYPE = new Map<string, SchxComponentDef>(DEFS.map((d) => [d.shortType, d]));
|
|
374
|
+
const BY_KIND = new Map<ComponentKind, SchxComponentDef>(
|
|
375
|
+
DEFS.reduce<Array<[ComponentKind, SchxComponentDef]>>((acc, def) => {
|
|
376
|
+
if (!acc.some(([k]) => k === def.kind)) {
|
|
377
|
+
acc.push([def.kind, def]);
|
|
378
|
+
}
|
|
379
|
+
return acc;
|
|
380
|
+
}, []),
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
export function shortenSchxType(fullType: string): string {
|
|
384
|
+
if (fullType.includes('Circuit.Components.Diode')) {
|
|
385
|
+
return 'TubeDiode';
|
|
386
|
+
}
|
|
387
|
+
const match = fullType.match(/Circuit\.(?:Components\.)?([A-Za-z0-9_]+)/);
|
|
388
|
+
return match?.[1] ?? fullType;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export function lookupSchxDef(shortType: string): SchxComponentDef | undefined {
|
|
392
|
+
return BY_SHORT_TYPE.get(shortType)
|
|
393
|
+
?? lookupMicroBlockStageDef(shortType)
|
|
394
|
+
?? lookupRuntimeDescriptorDef(shortType);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export function isSchxRuntimeDescriptor(shortType: string): boolean {
|
|
398
|
+
return /^MicroBlock[A-Za-z0-9_]*$/.test(shortType)
|
|
399
|
+
|| shortType === 'MacroTremolo'
|
|
400
|
+
|| shortType === 'MacroPhaser';
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export function defaultDefForKind(kind: ComponentKind): SchxComponentDef | undefined {
|
|
404
|
+
return BY_KIND.get(kind);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const CIRCUIT_ASSEMBLY = 'Circuit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null';
|
|
408
|
+
export const SCHX_SYMBOL_ELEMENT_TYPE = `Circuit.Symbol, ${CIRCUIT_ASSEMBLY}`;
|
|
409
|
+
export const SCHX_WIRE_ELEMENT_TYPE = `Circuit.Wire, ${CIRCUIT_ASSEMBLY}`;
|
|
410
|
+
|
|
411
|
+
export function fullSchxType(shortType: string): string {
|
|
412
|
+
if (shortType === 'TubeDiode') {
|
|
413
|
+
return `Circuit.Components.Diode, ${CIRCUIT_ASSEMBLY}`;
|
|
414
|
+
}
|
|
415
|
+
const namespace = shortType === 'Pentode' ? 'Circuit.Components' : 'Circuit';
|
|
416
|
+
return `${namespace}.${shortType}, ${CIRCUIT_ASSEMBLY}`;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function lookupMicroBlockStageDef(shortType: string): SchxComponentDef | undefined {
|
|
420
|
+
if (!/^MicroBlock[A-Za-z0-9_]*Stage$/.test(shortType)) {
|
|
421
|
+
return undefined;
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
...MICROBLOCK_OVERDRIVE_STAGE_DEF,
|
|
425
|
+
shortType,
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function lookupRuntimeDescriptorDef(shortType: string): SchxComponentDef | undefined {
|
|
430
|
+
if (!isSchxRuntimeDescriptor(shortType)) {
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
shortType,
|
|
435
|
+
kind: 'ic',
|
|
436
|
+
terminals: RUNTIME_DESCRIPTOR_TERMINALS,
|
|
437
|
+
quantityProps: RUNTIME_DESCRIPTOR_QUANTITY_PROPS,
|
|
438
|
+
};
|
|
439
|
+
}
|