-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
545 lines (497 loc) · 13.4 KB
/
generate.py
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
import csv
from enum import Enum
import json
from PIL import Image, ImageDraw, ImageFont
print('Creating your patch bay label')
csv_output_file = "csv_output/patch_bay.csv"
pixels_per_inch = 300
# Define the image dimensions and patch point width
image_width_inches = 17
image_height_inches = 0.14
font_size = 30
# Mac os
font_location = '/System/Library/Fonts/Supplemental/Andale Mono.ttf'
# github codespaces
# font_location = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
background_color = "white"
ink_color = "black"
expected_count = 24
image_width_px = int(image_width_inches * pixels_per_inch)
image_height_px = int(image_height_inches * pixels_per_inch)
# Load a font (this will need to be changed to a path on your system)
fnt = ImageFont.truetype(font_location, font_size)
def clear_csv_file():
open(csv_output_file, 'w').close()
def append_line_to_csv_file(line_to_append_as_list):
with open(csv_output_file, "a") as f:
f.write(f"{','.join(line_to_append_as_list)}\n")
def generate_single_label(top_or_bottom_key: str, reverse: bool):
image_size_tuple = (image_width_px, image_height_px)
image = Image.new('RGB', image_size_tuple, background_color)
d = ImageDraw.Draw(image)
last_used_x_position = 0
label_output_dir = "label_outputs"
label_name = config['label_name']
front_rear_prefix = "front"
entries_list = config["entries"]
if reverse is True:
entries_list = reversed(entries_list)
front_rear_prefix = "rear"
image_output_destination = f"{label_output_dir}/{label_name}-{front_rear_prefix}-{top_or_bottom_key}.png"
csv_list = []
# loop through entries
for i, entry in enumerate(entries_list):
csv_list.append(entry[top_or_bottom_key])
patch_width = image_width_px / expected_count
rect_width = patch_width * entry['width']
rect_x_start = last_used_x_position
rect_x_end = rect_x_start + rect_width
text_entry = entry[top_or_bottom_key]
text_length_px = int(d.textlength(text_entry, font=fnt))
# # Calcluate height of font
ascent, descent = fnt.getmetrics()
text_height_px = ascent + descent
text_x = last_used_x_position + (rect_width / 2) - (text_length_px / 2)
text_y = (image_height_px - text_height_px) / 2
text_pos = (text_x, text_y)
last_used_x_position = rect_x_end
rect_y_start = 0
rect_y_end = image_height_px
rect_top_config = [rect_x_start, rect_y_start, rect_x_end, rect_y_end]
rect_width = 2
# genreate rectangle
d.rectangle(rect_top_config, width=rect_width, outline=(ink_color))
# generate text
d.text(text_pos, text_entry, font=fnt, fill=(ink_color))
# Add underline only if it's a normalled connection
underline_padding = 8
underline_y_position = rect_y_end - underline_padding
underline_pos = [rect_x_start + underline_padding, underline_y_position, rect_x_end - underline_padding, underline_y_position]
if entry['normalled'] is True:
d.line(underline_pos, width=1, fill=ink_color)
# Add trailing commas to csv file entries
for i in range(entry['width'] - 1):
csv_list.append('')
if reverse is not True:
# Only append lines to CSV if reverse is not true
# ie: only generate csv file for front of patch bay
append_line_to_csv_file(csv_list)
image.save(image_output_destination)
def generate_patch_bay_labels_from_json(config, index):
# Tally total width and check that we're the right size
total_width = 0
for i, entry in enumerate(config["entries"]):
total_width += entry['width']
if total_width is not expected_count:
raise Exception(f"Config has {total_width}, but needs {expected_count} items")
append_line_to_csv_file([])
append_line_to_csv_file([f"Patch bay: {config['label_name']}"])
append_line_to_csv_file([])
# Generaet top and bottom front
generate_single_label(
top_or_bottom_key="top",
reverse=False
)
generate_single_label(
top_or_bottom_key="bottom",
reverse=False
)
# Generate top and bottom for rear
generate_single_label(
top_or_bottom_key="top",
reverse=True
)
generate_single_label(
top_or_bottom_key="bottom",
reverse=True
)
config = [
{
"label_name": "1",
"entries": [
{
"normalled": True,
"top": "Worm hole Matched to Left Side Patch bay 1-16 top",
"bottom": "Console Line In 1-16",
"width": 16
},
{
"normalled": False,
"top": "API L/R In",
"bottom": "API L/R Out",
"width": 2
},
{
"normalled": False,
"top": "Dbx 160A L/R In",
"bottom": "Dbx 160A L/R Out",
"width": 2
},
{
"normalled": False,
"top": "D-Comp L/R In",
"bottom": "D-Comp L/R Out",
"width": 2
},
{
"normalled": True,
"top": "902 De-esser IN 1-2",
"bottom": "902 De-esser OUT 1-2",
"width": 2
}
]
},
{
"label_name": "2",
"entries": [
{
"normalled": True,
"top": "Worm hole Matched to Left Side Patch bay 1-16 bottom",
"bottom": "Console Line In 17-32",
"width": 16
},
{
"normalled": True,
"top": "Aux 1 Out",
"bottom": "EMT 140 IN",
"width": 1
},
{
"normalled": True,
"top": "Aux 2 Out",
"bottom": "PCM60 IN",
"width": 1
},
{
"normalled": True,
"top": "Aux 3 Out",
"bottom": "SDE 1000 IN",
"width": 1
},
{
"normalled": True,
"top": "Aux 4 Out",
"bottom": "-",
"width": 1
},
{
"normalled": True,
"top": "Aux 5 / 6 Out",
"bottom": "Pro Verb Out",
"width": 2
},
{
"normalled": True,
"top": "Aux 7 Out",
"bottom": "Pro Verb In",
"width": 2
},
]
},
{
"label_name": "3",
"entries": [
{
"normalled": True,
"top": "Apollo #1 1-16 Out",
"bottom": "Ghost 1-16 Tape In",
"width": 16
},
{
"normalled": True,
"top": "Aux 8 Out L/R",
"bottom": "-",
"width": 2
},
{
"normalled": True,
"top": "Studio A O/P L/R",
"bottom": "Headamp Pro Input",
"width": 2
},
{
"normalled": True,
"top": "Studio Phones B L/R Out",
"bottom": "Meyer Mains In L/R",
"width": 2
},
{
"normalled": False,
"top": "PCM60 Return L/R",
"bottom": "EMT 140 Return L/R",
"width": 2
},
]
},
{
"label_name": "4",
"entries": [
{
"normalled": True,
"top": "Apollo #2 17-32 Out",
"bottom": "Ghost 17-32 Tape In",
"width": 16
},
{
"normalled": False,
"top": "Tascam TSR-8 In 1-8",
"bottom": "Tascam TSR-8 Out 1-8",
"width": 8
}
]
},
{
"label_name": "5",
"entries": [
{
"normalled": True,
"top": "Ghost 1-16 Tape Send",
"bottom": "Apollo #1 1-16 In",
"width": 16
},
{
"normalled": False,
"top": "Control Room Out",
"bottom": "Yamaha Monitors In",
"width": 2
},
{
"normalled": False,
"top": "Apollo 2 Track Out",
"bottom": "Ghost 2 Track A Input",
"width": 2
},
{
"normalled": False,
"top": "-",
"bottom": "Ghost 2 Track B Input",
"width": 2
},
{
"normalled": True,
"top": "Ghost Mix OUT",
"bottom": "-",
"width": 2
}
]
},
{
"label_name": "6",
"entries": [
{
"normalled": True,
"top": "Ghost 17-32 Tape Send",
"bottom": "Apollo #2 17-32 In",
"width": 16
},
{
"normalled": True,
"top": "Alt CRM Out L/R",
"bottom": "Mix Cube L / -",
"width": 2
},
{
"normalled": False,
"top": "-",
"bottom": "-",
"width": 6
}
]
},
{
"label_name": "7",
"entries": [
{
"normalled": True,
"top": "Ghost Channel Insert Send 1-16",
"bottom": "Ghost Channel Insert Return 1-16",
"width": 16
},
{
"normalled": False,
"top": "Group 1 / 2 Out",
"bottom": "FX 1 In L / R",
"width": 2
},
{
"normalled": False,
"top": "Group 3 / 4 Out",
"bottom": "FX 2 In L / R",
"width": 2
},
{
"normalled": False,
"top": "Group 5 / 6 Out",
"bottom": "FX 3 In L / R",
"width": 2
},
{
"normalled": False,
"top": "Group 7 / 8 Out",
"bottom": "FX 4 In L / R",
"width": 2
},
]
},
{
"label_name": "8",
"entries": [
{
"normalled": True,
"top": "Ghost Channel Insert Send 17-32",
"bottom": "Ghost Channel Insert Return 17-32",
"width": 16
},
{
"normalled": False,
"top": "Group 1 - 8 Insert Send",
"bottom": "Group 1 - 8 Insert Return",
"width": 8
},
]
},
{
"label_name": "9",
"entries": [
{
"normalled": True,
"top": "Main Insert Send",
"bottom": "Main Insert Return",
"width": 2
},
{
"normalled": False,
"top": "Basement Snake Send A, B, C, D",
"bottom": "Basement Snake Send E, F, G, H",
"width": 4
},
{
"normalled": False,
"top": "-",
"bottom": "-",
"width": 10
},
{
"normalled": False,
"top": "SDE 1000 Return",
"bottom": "-",
"width": 1
},
{
"normalled": False,
"top": "-",
"bottom": "-",
"width": 1
},
{
"normalled": False,
"top": "DBX 160 Link",
"bottom": "DBX 160 Link",
"width": 1
},
{
"normalled": False,
"top": "Fuzz In",
"bottom": "Fuzz Out",
"width": 1
},
{
"normalled": False,
"top": "Transition Delay In",
"bottom": "Transition Delay Out",
"width": 2
},
{
"normalled": False,
"top": "Hall of Fame Verb In",
"bottom": "Hall of Fame Verb Out",
"width": 2
},
]
},
{
"label_name": "10",
"entries": [
{
"normalled": False,
"top": "Rooms IN (todo define this)",
"bottom": "Rooms IN ",
"width": 3
},
{
"normalled": False,
"top": "Moog DLY IN",
"bottom": "Moog DLY OUT",
"width": 1
},
{
"normalled": False,
"top": "Tanzbar OUT L/R",
"bottom": "-",
"width": 2
},
{
"normalled": True,
"top": "-",
"bottom": "-",
"width": 14
},
{
"normalled": False,
"top": "MXR Dist IN",
"bottom": "MXR Dist OUT",
"width": 1
},
{
"normalled": False,
"top": "Art Comp IN L/R",
"bottom": "Art Comp OUT L/R",
"width": 2
},
{
"normalled": False,
"top": "UA 550 In",
"bottom": "UA 550 Out",
"width": 1
},
]
},
{
"label_name": "11-amp-rack",
"entries": [
{
"normalled": True,
"top": "L / R Audio Source Out",
"bottom": "DBX Drive Rack L/R IN",
"width": 2
},
{
"normalled": True,
"top": "DBX High Out L/R",
"bottom": "High Amp In L/R",
"width": 2
},
{
"normalled": True,
"top": "DBX Mid Out L/R",
"bottom": "Mid Amp In L/R",
"width": 2
},
{
"normalled": True,
"top": "DBX Low Out L/R",
"bottom": "Low Amp In L/R",
"width": 2
},
{
"normalled": True,
"top": "-",
"bottom": "-",
"width": 16
},
]
}
]
clear_csv_file()
for i, config in enumerate(config):
generate_patch_bay_labels_from_json(config, i)