-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.py
880 lines (749 loc) · 34.1 KB
/
data.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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Copyright (C) 2019 JPfeP
#
# ##### END GPL LICENSE BLOCK #####
import bpy
import copy
from bpy.app.handlers import persistent
from bpy.utils import register_class, unregister_class
from distutils.util import strtobool
from numpy import radians, degrees
import numpy as np
import sys
import g_vars
g_vars.vpt_in = None
g_vars.vpt_osc_in = []
g_vars.vpt_remote = []
vpt_remote_pre = {}
def n_to_enum(bl_item, item, arg):
ref = item['ref']
prop = item['prop']
idx = int(arg)
ref_rna = ref.bl_rna.properties[prop].enum_items
max_idx = len(ref_rna)-1
if idx < 0:
idx = 0
if idx >= max_idx:
idx = max_idx
return ref_rna[idx].identifier
def enum_to_n (bl_item, item, arg):
ref = item['ref']
prop = item['prop']
ref_rna = ref.bl_rna.properties[prop].enum_items
return ref_rna[arg].value
def radeg(bl_item, item, arg):
return radians(arg)
def degra(bl_item, item, arg):
return degrees(arg)
def nothing(bl_item, item, arg):
return arg
# post function (SET/ADD/SUB/MULT/DIVIDE/EXPR)
def post_set(current, result, bl_item):
out = result
return out
def post_add(current, result, bl_item):
out = current + result
return out
def post_sub(current, result, bl_item):
out = current - result
return out
def post_mul(current, result, bl_item):
out = current * result
return out
def post_div(current, result, bl_item):
out = current / result
return out
def post_expr(PROP, IN, bl_item):
out = eval(bl_item.eval_expr)
return out
def parse_route(item, k=0):
val = item.offset + k
if item.is_multi and (item.VAR_use == 'name'):
if item.name_var == 'VAR':
index = str(val)
id = eval('bpy.data.'+item.id_type+'['+index+']')
else:
name = item.name_var.replace('VAR', str(val))
id = eval('bpy.data.' + item.id_type + '["' + name + '"]')
else:
id = item.id[item.id_type]
# Replace VAR in data-path
dp = item.data_path
if item.is_multi and (item.VAR_use == 'dp'):
dp = dp.replace('VAR', str(val))
# getting a ref
dp_split = dp.split('.')
if len(dp_split) > 1:
ref = eval(repr(id) + '.' + '.'.join(dp_split[0:-1]))
else:
ref = id
prop = dp_split[-1]
# setting item array and size
if hasattr(ref.bl_rna.properties[prop], 'is_array'):
item.is_array = ref.bl_rna.properties[prop].is_array
item.len = ref.bl_rna.properties[prop].array_length
else:
item.is_array = False
item.len = 0
# FUNCTIONS
# for general case
func = {'midi_in_func': nothing,
'midi_out_func': nothing,
'osc_in_func': nothing,
'osc_out_func': nothing,
'remote_func': nothing
}
# for enum
if ref.bl_rna.properties[prop].type == 'ENUM':
#l = []
#for item in ref.bl_rna.properties[prop].enum_items:
# l.append(item.identifier)
func = {'midi_in_func': n_to_enum,
'midi_out_func': enum_to_n,
'osc_in_func': nothing,
'osc_out_func': nothing,
'remote_func': n_to_enum,
}
# for angles
#if hasattr(ref.bl_rna.properties[prop], 'unit'):
if ref.bl_rna.properties[prop].unit == 'ROTATION':
item.is_angle = True
else:
item.is_angle = False
if item.rad2deg is True and item.is_angle is True:
func = {'midi_in_func': radeg,
'midi_out_func': degra,
'osc_in_func': radeg,
'osc_out_func': degra,
'remote_func': radeg
}
# POST FUNCTIONS (SET/ADD/DEL/MUL/DIV/EXPR..)
post_func = None
if item.eval_mode == 'replace':
post_func = post_set
elif item.eval_mode == 'add':
post_func = post_add
elif item.eval_mode == 'subtract':
post_func = post_sub
elif item.eval_mode == 'multiply':
post_func = post_mul
elif item.eval_mode == 'divide':
post_func = post_div
elif item.eval_mode == 'expr':
post_func = post_expr
# options for keyframe insertion
ks_options = set()
if item.kf_needed:
ks_options.add('INSERTKEY_NEEDED')
if item.kf_visual:
ks_options.add('INSERTKEY_VISUAL')
if item.kf_rgb:
ks_options.add('INSERTKEY_XYZ_TO_RGB')
if item.kf_replace:
ks_options.add('INSERTKEY_REPLACE')
if item.kf_available:
ks_options.add('INSERTKEY_AVAILABLE')
if item.kf_cycle:
ks_options.add('INSERTKEY_CYCLE_AWARE')
if item.kf_group is not '':
ks_params = {'options': ks_options, 'group': item.kf_group}
else:
ks_params = {'options': ks_options}
return id, ref, prop, dp, ks_params, func, post_func
def encode(chan, cont_type):
chan -= 1
# return channel byte, number of param, quantification
if cont_type == 'AT_mono':
return 13 * 16 + chan, 1, 127
if cont_type == 'AT_poly':
return 10 * 16 + chan, 2, 127
if cont_type == 'pitchbend':
return 14 * 16 + chan, 2, 16383
if cont_type == 'pgm':
return 12 * 16 + chan, 1, 127
if cont_type == 'cc7':
return 11 * 16 + chan, 2, 127
if cont_type == 'rpn' or cont_type == 'nrpn':
return 11 * 16 + chan, 2, 127
if cont_type == 'rpn14' or cont_type == 'nrpn14':
return 11 * 16 + chan, 2, 16383
# workaround for the other note types, to be removed
return 11 * 16 + chan, 2, 127
def generate_dict(self, context):
exed_item = {
'key_on': [],
'key_off': [],
'cc7': [],
'pgm': [],
'AT_mono': [],
'AT_poly': [],
'pitchbend': [],
'rpn': [],
'rpn14': [],
'nrpn': [],
'nrpn14': []
}
g_vars.vpt_in = {
'1': copy.deepcopy(exed_item),
'2': copy.deepcopy(exed_item),
'3': copy.deepcopy(exed_item),
'4': copy.deepcopy(exed_item),
'5': copy.deepcopy(exed_item),
'6': copy.deepcopy(exed_item),
'7': copy.deepcopy(exed_item),
'8': copy.deepcopy(exed_item),
'9': copy.deepcopy(exed_item),
'10': copy.deepcopy(exed_item),
'11': copy.deepcopy(exed_item),
'12': copy.deepcopy(exed_item),
'13': copy.deepcopy(exed_item),
'14': copy.deepcopy(exed_item),
'15': copy.deepcopy(exed_item),
'16': copy.deepcopy(exed_item),
'pass': None
}
g_vars.vpt_out = []
g_vars.vpt_osc_in = {}
g_vars.vpt_osc_out = []
for i, item in enumerate(context.scene.VPT_Items):
if item.is_multi:
j = item.number
else:
j = 1
# first pass to test if creating a route is possible
try:
for k in range(j):
# val = k + item.offset
id, ref, prop, dp, ks_params, func, post_func = parse_route(item, k)
except:
item.alert = True
break
item.alert = False
# some common variables for MIDI receiving/sending
cont = item.cont_type
chan = item.channel
midi, lenx, quant = encode(chan, cont)
# add an option for treating velocity later
num = context.scene['VPT_Items'][i]['cont_type']
option = g_vars.Cont_types[num][2]
# set filter flag to various events
# MIDI : "option" is useful only for receiving, but f_show and f_filter serve for the GUI too (send/receive)
if item.engine == 'MIDI':
if option == '':
item.f_show = False
item.filter = False
if option == 'f_forced':
item.filter = True
item.f_show = False
if option == 'f_opt':
item.f_show = True
if item.mode == 'Receive' or item.mode == 'Both':
dico = {}
# actually create route for MIDI
if item.engine == 'MIDI':
rescale = item.rescale_outside_high - item.rescale_outside_low
for k in range(j):
id, ref, prop, dp, ks_params, func, post_func = parse_route(item, k)
filt = str(k + item.controller)
dico[filt] = {
'ref': ref,
'prop': prop,
'option': option,
'quant': quant,
'rescale_out': rescale,
'func': func['midi_in_func'],
'post_func': post_func,
'ks_params': ks_params
}
g_vars.vpt_in[str(chan)][cont].append((i, dico))
# for OSC
elif item.engine == 'OSC':
if g_vars.vpt_osc_in.get(item.osc_address) is None:
g_vars.vpt_osc_in[item.osc_address] = []
for k in range(j):
id, ref, prop, dp, ks_params, func, post_func = parse_route(item, k)
filt = str(k)
dico[filt] = {
'ref': ref,
'prop': prop,
'func': func['osc_in_func'],
'post_func': post_func,
'ks_params': ks_params
}
g_vars.vpt_osc_in[item.osc_address].append((i, dico))
if item.mode == 'Send' or item.mode == 'Both':
# for MIDI engine
if item.engine == 'MIDI':
rescale = item.rescale_blender_high - item.rescale_blender_low
# for single and multi routes
for k in range(j):
id, ref, prop, dp, ks_params, func, post_func = parse_route(item, k)
filt = k + item.controller
LSB = str(filt % 128)
MSB = str(int(filt / 128))
if item.cont_type == 'rpn':
reg = [(101, MSB), (100, LSB), (6, 'val2')]
elif item.cont_type == 'rpn14':
reg = [(101, MSB), (100, LSB), (6, 'MSB'), (38, 'LSB')]
elif item.cont_type == 'nrpn':
reg = [(99, MSB), (98, LSB), (6, 'val2')]
elif item.cont_type == 'nrpn14':
reg = [(99, MSB), (98, LSB), (6, 'MSB'), (38, 'LSB')]
else:
reg = None
g_vars.vpt_out.append(
{'chan': chan,
'cont': cont,
'ref': ref,
'prop': prop,
'ID': id,
'filter': filt,
'midi': midi,
'val': None,
'rescale_bl': rescale,
'quant': quant,
'lenx': lenx,
'reg': reg,
'func': func['midi_out_func'],
'n': i})
# for OSC
else:
# for single and multi routes
for k in range(j):
id, ref, prop, dp, ks_params, func, post_func = parse_route(item, k)
g_vars.vpt_osc_out.append(
{'address': item.osc_address,
'ref': ref,
'prop': prop,
'ID': id,
'val': None,
'func': func['osc_out_func'],
'n': i,
'idx': k
})
# A special case is remote (no receive/send thing)
if item.engine == 'remote':
id, ref, prop, dp, ks_params, func, post_func = parse_route(item)
vpt_remote_pre[i] = {
'ref': ref,
'prop': prop,
'ID': id,
'val': None,
'func': func['remote_func'],
'post_func': post_func,
'ks_params': ks_params
}
# this to avoid some errors when changing scene
g_vars.scene = context.scene
#generate_dict(None, context)
#print(g_vars.vpt_in, "\n")
#print(g_vars.vpt_out, "\n")
#print(g_vars.vpt_osc_in, "\n")
#print(g_vars.vpt_osc_out, "\n")
# for the blemotization and the real remote routes
g_vars.vpt_remote = {}
for i, item in enumerate(context.scene.VPT_Items):
trigger = None
if item.bl_switch and item.engine == 'MIDI':
trigger = {
'channel': item.channel,
'cont_type': item.cont_type,
'controller': item.controller
}
elif item.bl_switch and item.engine == 'OSC':
trigger = item.osc_address
elif item.engine == 'remote':
trigger = vpt_remote_pre[i]
if trigger is not None:
dico = {
'engine': item.engine,
'trigger': trigger,
'min': item.bl_min,
'max': item.bl_max
}
g_vars.vpt_remote[str(i)] = dico
#print(g_vars.vpt_remote)
def dynamic_cat(self, context):
list_items = [("Default", "Default", "", 0)]
for item in context.scene.VPT_categories:
new = (item.name, item.name, item.name, item.rank)
list_items.append(new)
return list_items
class VPT_categories_PG(bpy.types.PropertyGroup):
name: bpy.props.StringProperty(name='New Category')
rank: bpy.props.IntProperty()
bpy.utils.register_class(VPT_categories_PG)
bpy.types.Scene.VPT_categories = bpy.props.CollectionProperty(type=VPT_categories_PG)
bpy.types.Scene.VPT_catenum = bpy.props.EnumProperty(
name='Category',
items=dynamic_cat
)
class VPT_ID_PG(bpy.types.PropertyGroup):
actions: bpy.props.PointerProperty(name="ID_act", type=bpy.types.Action, update=generate_dict)
armatures: bpy.props.PointerProperty(name="ID_arm", type=bpy.types.Armature, update=generate_dict)
brushes: bpy.props.PointerProperty(name="ID_bru", type=bpy.types.Brush, update=generate_dict)
cache_files: bpy.props.PointerProperty(name="ID_cac", type=bpy.types.CacheFile, update=generate_dict)
cameras: bpy.props.PointerProperty(name="ID_cam", type=bpy.types.Camera, update=generate_dict)
collections: bpy.props.PointerProperty(name="ID_col", type=bpy.types.Collection, update=generate_dict)
curves: bpy.props.PointerProperty(name="ID_cur", type=bpy.types.Curve, update=generate_dict)
grease_pencils: bpy.props.PointerProperty(name="ID_gre", type=bpy.types.GreasePencil, update=generate_dict)
images: bpy.props.PointerProperty(name="ID_ima", type=bpy.types.Image, update=generate_dict)
shape_keys: bpy.props.PointerProperty(name="ID_sha", type=bpy.types.Key, update=generate_dict) #Warning shape_keys or keys ???
lattices: bpy.props.PointerProperty(name="ID_lat", type=bpy.types.Lattice, update=generate_dict)
libraries: bpy.props.PointerProperty(name="ID_lib", type=bpy.types.Library, update=generate_dict)
lights: bpy.props.PointerProperty(name="ID_lig", type=bpy.types.Light, update=generate_dict)
lightprobes: bpy.props.PointerProperty(name="ID_lip", type=bpy.types.LightProbe, update=generate_dict)
linestyles: bpy.props.PointerProperty(name="ID_lin", type=bpy.types.FreestyleLineStyle, update=generate_dict)
masks: bpy.props.PointerProperty(name="ID_mas", type=bpy.types.Mask, update=generate_dict)
materials: bpy.props.PointerProperty(name="ID_mat", type=bpy.types.Material, update=generate_dict)
meshes: bpy.props.PointerProperty(name="ID_mes", type=bpy.types.Mesh, update=generate_dict)
metaballs: bpy.props.PointerProperty(name="ID_met", type=bpy.types.MetaBall, update=generate_dict)
movieclips: bpy.props.PointerProperty(name="ID_mov", type=bpy.types.MovieClip, update=generate_dict)
node_groups: bpy.props.PointerProperty(name="ID_nod", type=bpy.types.NodeTree, update=generate_dict)
objects: bpy.props.PointerProperty(name="ID_obj", type=bpy.types.Object, update=generate_dict)
paint_curves: bpy.props.PointerProperty(name="ID_pai", type=bpy.types.PaintCurve, update=generate_dict)
palettes: bpy.props.PointerProperty(name="ID_pal", type=bpy.types.Palette, update=generate_dict)
particles: bpy.props.PointerProperty(name="ID_par", type=bpy.types.ParticleSettings, update=generate_dict)
scenes: bpy.props.PointerProperty(name="ID_sce", type=bpy.types.Scene, update=generate_dict)
sounds: bpy.props.PointerProperty(name="ID_sou", type=bpy.types.Sound, update=generate_dict)
speakers: bpy.props.PointerProperty(name="ID_spe", type=bpy.types.Speaker, update=generate_dict)
texts: bpy.props.PointerProperty(name="ID_tex", type=bpy.types.Text, update=generate_dict)
textures: bpy.props.PointerProperty(name="ID_tur", type=bpy.types.Texture, update=generate_dict)
fonts: bpy.props.PointerProperty(name="ID_fon", type=bpy.types.VectorFont, update=generate_dict)
window_managers:bpy.props.PointerProperty(name="ID_win", type=bpy.types.WindowManager, update=generate_dict)
workspaces: bpy.props.PointerProperty(name="ID_wor", type=bpy.types.WorkSpace, update=generate_dict)
worlds: bpy.props.PointerProperty(name="ID_wod", type=bpy.types.World, update=generate_dict)
bpy.utils.register_class(VPT_ID_PG)
g_vars.ID_types=[
('actions', 'Action', 'Action', 'ACTION', 0),
('armatures', 'Armature', 'Armature', 'ARMATURE_DATA', 1),
('brushes', 'Brush', 'Brush', 'BRUSH_DATA', 2),
('cache_files', 'CacheFile', 'CacheFile', 'FILE', 3),
('cameras', 'Camera', 'Camera', 'CAMERA_DATA', 4),
('collections', 'Collection', 'Collection', 'GROUP', 5),
('curves', 'Curve', 'Curve', 'CURVE_DATA', 6),
('grease_pencils', 'Grease Pencil', 'Grease Pencil', 'GREASEPENCIL', 7),
('images', 'Image', 'Image', 'IMAGE_DATA', 8),
('shape_keys', 'Key', 'Key', 'SHAPEKEY_DATA', 9),
('lattices', 'Lattice', 'Lattice', 'LATTICE_DATA', 10),
('libraries', 'Library', 'Library', 'LIBRARY_DATA_DIRECT', 11),
('lights', 'Light', 'Light', 'LIGHT_DATA', 12),
('lightprobes', 'LightProbe', 'LightProbe', 'LIGHTPROBE_CUBEMAP', 13),
('linestyles', 'Line Style', 'Line Style', 'LINE_DATA', 14),
('masks', 'Mask', 'Mask', 'MOD_MASK', 15),
('materials', 'Material', 'Material', 'MATERIAL_DATA', 16),
('meshes', 'Mesh', 'Mesh', 'MESH_DATA', 17),
('metaballs', 'Metaball', 'Metaball', 'META_DATA', 18),
('movieclips', 'Movie Clip', 'Movie Clip', 'SEQUENCE', 19),
('node_groups', 'Node Tree', 'Node Tree', 'NODETREE', 20),
('objects', 'Object', 'Object', 'OBJECT_DATA', 21),
('paint_curves', 'Paint Curve', 'Paint Curve', 'CURVE_BEZCURVE', 22),
('palettes', 'Palette', 'Palette', 'RESTRICT_COLOR_ON', 23),
('particles', 'Particle', 'Particle', 'PARTICLE_DATA', 24),
('scenes', 'Scene', 'Scene', 'SCENE_DATA', 25),
# ('screens', 'Screen', 'Screen', 'SCREEN', 25), #No screen exposed ?
('sounds', 'Sound', 'Sound', 'SOUND', 26),
('speakers', 'Speaker', 'Speaker', 'SPEAKER', 27),
('texts', 'Text', 'Text', 'TEXT', 28),
('textures', 'Texture', 'Texture', 'TEXTURE_DATA', 29),
('fonts', 'Font', 'Font', 'FONT_DATA', 30),
('window_managers', 'Window Manager', 'Window Manager', 'WINDOW', 31),
('workspaces', 'Workspace', 'Workspace', 'WORKSPACE', 32),
('worlds', 'World', 'World', 'WORLD_DATA', 33)
]
g_vars.Cont_types = [
('key_on', 'Key On number', ''),
('key_off', 'Key Off number', ''),
('key_on', 'Note On velocity', 'f_opt'),
('key_off', 'Note Off velocity', 'f_opt'),
('AT_mono', 'Aftertouch mono', ''),
('AT_poly', 'Aftertouch poly', 'f_forced'),
('pitchbend', 'Pitchbend 14bit', ''),
('pgm', 'Program Change', ''),
('cc7', 'Continous Controller 7bit', 'f_forced'),
('rpn', 'RPN 7bit', 'f_forced'),
('rpn14', 'RPN 14bit', 'f_forced'),
('nrpn', 'NRPN 7bit', 'f_forced'),
('nrpn14', 'NRPN 14bit', 'f_forced'),
]
class VPT_Items_PG(bpy.types.PropertyGroup):
def upd_min(self, context):
if self.min >= self.max:
self.min = self.max - 1
generate_dict(self, context)
def upd_max(self, context):
if self.max <= self.min:
self.max = self.max + 1
generate_dict(self, context)
engine: bpy.props.EnumProperty(
items=[
('MIDI', 'MIDI', 'MIDI', '', 0),
('OSC', 'OSC', 'OSC', '', 1),
('remote', 'remote', 'remote', '', 2)
],
default='MIDI',
update=generate_dict
)
mode: bpy.props.EnumProperty(
items=[
('Receive', 'Receive', 'Receive', '', 0),
('Send', 'Send', 'Send', '', 1),
('Both', 'Both', 'Both', '', 2),
('Off', 'Off', 'Off', '', 3)
],
default='Off',
update=generate_dict
)
record: bpy.props.BoolProperty(name='Record', update=generate_dict)
id_type: bpy.props.EnumProperty(
items=g_vars.ID_types,
name='ID-Block',
default='objects',
update=generate_dict
)
id: bpy.props.PointerProperty(name='ID', type=VPT_ID_PG, update=generate_dict)
data_path: bpy.props.StringProperty(name="Data Path", update=generate_dict)
array: bpy.props.IntProperty(name="Index", min=0, update=generate_dict)
is_array: bpy.props.BoolProperty(name='Is Array ?')
len: bpy.props.IntProperty()
use_array: bpy.props.BoolProperty(name='All')
channel: bpy.props.IntProperty(name="Channel", min=1, max=16, default=1, update=generate_dict)
controller: bpy.props.IntProperty(name="Controller number", min=0, max=16384, default=1, update=generate_dict)
# controller14: bpy.props.IntProperty(name="Controller number", min=1, max=16384, default=1, update=generate_dict)
use_clip: bpy.props.BoolProperty(name='Clip incoming', update=generate_dict)
clip_low: bpy.props.FloatProperty(name="Low", default=0, update=generate_dict)
clip_high: bpy.props.FloatProperty(name="High", default=127, update=generate_dict)
rescale_mode: bpy.props.EnumProperty(name='Rescale in/out',
items=[
('Direct', 'Direct', 'Direct', '', 0),
('Auto', 'Auto', 'Auto', '', 1),
('Cut', 'Cut', 'Cut', '', 2),
('Wrap', 'Wrap', 'Wrap', '', 3)
]
)
rescale_outside_low: bpy.props.IntProperty(name="Low", default=0, min=0, max=16383, update=generate_dict)
rescale_outside_high: bpy.props.IntProperty(name="High", default=127, min=0, max=16383, update=generate_dict)
rescale_blender_low: bpy.props.FloatProperty(name="Low", default=0, update=generate_dict)
rescale_blender_high: bpy.props.FloatProperty(name="High", default=127, update=generate_dict)
min: bpy.props.IntProperty(name="Min", default=0, update=generate_dict)
max: bpy.props.IntProperty(name="Max", default=127, update=generate_dict)
eval_mode: bpy.props.EnumProperty(
name='Actualization',
items=[
('replace', 'Replace', 'replace', '', 0),
#('add', 'add', 'add', '', 1),
#('subtract', 'subtract', 'subtract', '', 2),
#('multiply', 'multiply', 'multiply', '', 3),
#('divide', 'divide', 'divide', '', 4),
('expr', 'Expression', 'expression', '', 5)
],
update=generate_dict)
eval_expr: bpy.props.StringProperty(name="Evaluate",
description='IN = incoming value (processed)\nPROP = current Blender value',
default='IN',
update=generate_dict)
osc_address: bpy.props.StringProperty(name="Address", default='/blender', update=generate_dict)
filter: bpy.props.BoolProperty(name='Filter')
f_show: bpy.props.BoolProperty(name='Show Filter')
cont_type: bpy.props.EnumProperty(
name='Event type',
items=g_vars.Cont_types,
update=generate_dict
)
alert: bpy.props.BoolProperty(name='Alert')
typ: bpy.props.StringProperty(name='Type')
# for keying set options
kf_needed: bpy.props.BoolProperty(name='KF_needed', update=generate_dict)
kf_visual: bpy.props.BoolProperty(name='KF_visual', update=generate_dict)
kf_rgb: bpy.props.BoolProperty(name='KF_xyz2rgb', update=generate_dict)
kf_replace: bpy.props.BoolProperty(name='KF_replace', update=generate_dict)
kf_available: bpy.props.BoolProperty(name='KF_available', update=generate_dict)
kf_cycle: bpy.props.BoolProperty(name='KF_cycle', update=generate_dict)
kf_group: bpy.props.StringProperty(name='Group', description='Group name for F-curves (mandatory for MIDI envelope)', update=generate_dict)
# for remote
bl_switch: bpy.props.BoolProperty(name='Show remote options', description='Display this route in remote', update=generate_dict)
bl_min: bpy.props.FloatProperty(name="Min", default=0, update=generate_dict)
bl_max: bpy.props.FloatProperty(name="Max", default=100, update=generate_dict)
# for multi routes
is_multi: bpy.props.BoolProperty(name='Multi routing', update=generate_dict)
number: bpy.props.IntProperty(name="Instances", default=2, min=2, update=generate_dict)
VAR_use: bpy.props.EnumProperty(
name='Use VAR',
items=[
('name', 'in name', 'in name', '', 0),
('dp', 'in data-path', 'in data-path', '', 1)
],
update=generate_dict)
name_var: bpy.props.StringProperty(name='Base name', default='name_VAR', update=generate_dict)
offset: bpy.props.IntProperty(name="Offset ", default=0, update=generate_dict)
osc_select_rank: bpy.props.IntProperty(name="From", update=generate_dict)
osc_select_n: bpy.props.IntProperty(name="n", min=1, default=1, update=generate_dict)
# for angles
rad2deg: bpy.props.BoolProperty(name='Deg', default=True, update=generate_dict, description='Convert degrees <-> radians')
is_angle: bpy.props.BoolProperty()
# for MIDI post processing
env_auto: bpy.props.BoolProperty(name='Auto', description='Automatically apply envelope after midifile conversion')
env_attack: bpy.props.IntProperty(name='Pre Attack', description='Pre Attack time in millisecondes', default=50, min=1)
env_release: bpy.props.IntProperty(name='Release', description='Release time in millisecondes', default=50, min=1)
# for the categories feature
category: bpy.props.EnumProperty(
name='Category',
items=dynamic_cat,
update=generate_dict
)
bpy.utils.register_class(VPT_Items_PG) # to be moved elsewhere ?
bpy.types.Scene.VPT_Items = bpy.props.CollectionProperty(type=VPT_Items_PG)
bpy.types.Scene.show_postprocess = bpy.props.BoolProperty(name="Show envelope settings ")
bpy.types.Scene.show_categories = bpy.props.BoolProperty(name="Show categories")
bpy.types.Scene.show_routes_number = bpy.props.BoolProperty(name="Show routes number")
bpy.types.Scene.VPT_sorting = bpy.props.EnumProperty(
name='Sorting',
items=[
('None', 'None', '', '', 0),
('Category', 'Category', '', '', 1)
]
)
def upd_settings_sub(n):
text_settings = None
for text in bpy.data.texts:
if text.name == '.vpt_settings':
text_settings = text
if text_settings is None:
bpy.ops.text.new()
text_settings = bpy.data.texts[-1]
text_settings.name = '.vpt_settings'
while len(text_settings.lines) < 30:
text_settings.write("\n")
# MIDI
if n == 0:
text_settings.lines[0].body = str(int(bpy.context.window_manager.autorun))
elif n == 1:
text_settings.lines[1].body = bpy.context.window_manager.midi_in_device
elif n == 2:
text_settings.lines[2].body = bpy.context.window_manager.midi_out_device
elif n == 3:
text_settings.lines[3].body = str(bpy.context.window_manager.rate)
# OSC
elif n == 10:
text_settings.lines[10].body = bpy.context.window_manager.vpt_osc_udp_in
elif n == 11:
text_settings.lines[11].body = str(bpy.context.window_manager.vpt_osc_port_in)
elif n == 12:
text_settings.lines[12].body = bpy.context.window_manager.vpt_osc_udp_out
elif n == 13:
text_settings.lines[13].body = str(bpy.context.window_manager.vpt_osc_port_out)
elif n == 14:
text_settings.lines[n].body = str(bpy.context.window_manager.vpt_osc_in_enable)
elif n == 15:
text_settings.lines[n].body = str(bpy.context.window_manager.vpt_osc_out_enable)
# remote
elif n == 20:
text_settings.lines[20].body = bpy.context.window_manager.vpt_remote_udp_in
elif n == 21:
text_settings.lines[21].body = str(bpy.context.window_manager.vpt_remote_port_in)
elif n == 22:
text_settings.lines[22].body = bpy.context.window_manager.vpt_remote_udp_out
elif n == 23:
text_settings.lines[23].body = str(bpy.context.window_manager.vpt_remote_port_out)
# Restore saved settings
@persistent
def vpt_handler(scene):
global error_device
for text in bpy.data.texts:
if text.name == '.vpt_settings':
# for midi settings
try:
if text.lines[1].body != '':
bpy.context.window_manager.midi_in_device = text.lines[1].body
except:
error_device = True
print("MIDI In device not found")
try:
if text.lines[2].body != '':
bpy.context.window_manager.midi_out_device = text.lines[2].body
except:
error_device = True
print("MIDI Out device not found")
# for OSC settings
try:
if text.lines[10].body != '':
bpy.context.window_manager.vpt_osc_udp_in = text.lines[10].body
except:
print("OSC: Using default input IP")
try:
bpy.context.window_manager.vpt_osc_port_in = int(text.lines[11].body)
except:
print("OSC: Using default input port")
try:
if text.lines[12].body != '':
bpy.context.window_manager.vpt_osc_udp_out = text.lines[12].body
except:
print("OSC: Using default output IP")
try:
bpy.context.window_manager.vpt_osc_port_out = int(text.lines[13].body)
except:
print("OSC: Using default output port")
try:
bpy.context.window_manager.vpt_osc_in_enable = strtobool(text.lines[14].body)
except:
pass
try:
bpy.context.window_manager.vpt_osc_out_enable = strtobool(text.lines[15].body)
except:
pass
# for remote settings
try:
if text.lines[20].body != '':
bpy.context.window_manager.vpt_remote_udp_in = text.lines[20].body
except:
print("remote: Using default input IP")
try:
bpy.context.window_manager.vpt_remote_port_in = int(text.lines[21].body)
except:
print("remote: Using default input port")
try:
if text.lines[22].body != '':
bpy.context.window_manager.vpt_remote_udp_out = text.lines[22].body
except:
print("remote: Using default output IP")
try:
bpy.context.window_manager.vpt_remote_port_out = int(text.lines[23].body)
except:
print("remote: Using default output port")
# This is a hack to start OSC and remote on a fresh project without config yet
'''
try:
bpy.data.texts['.vpt_settings']
except:
bpy.context.window_manager.vpt_osc_port_in = bpy.context.window_manager.vpt_osc_port_in
bpy.context.window_manager.vpt_remote_port_in = bpy.context.window_manager.vpt_remote_port_in
'''
#generate_dict(None, bpy.context) # when the file load, may be useless if scene test
#bpy.ops.vpt.midifile_parse()
cls = (#VPT_Wrapper_gendict,
)
def register():
for c in cls:
register_class(c)
bpy.app.handlers.load_post.append(vpt_handler)
def unregister():
bpy.app.handlers.load_post.remove(vpt_handler)
for c in cls:
unregister_class(c)
if __name__ == "__main__":
register()