~martijnbraam/pyatem

pyatem/gtk_switcher/upstreamkey.py -rw-r--r-- 14.6 KiB
ed164087Martijn Braam i18n: update translation files from source 4 days ago
                                                                                
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
from gi.repository import Gtk, GObject, Gdk

from gtk_switcher.template_i18n import TemplateLocale
from pyatem.command import KeyFillCommand, KeyPropertiesDveCommand, KeyTypeCommand, KeyCutCommand, \
    KeyPropertiesLumaCommand, KeyerKeyframeSetCommand, KeyerKeyframeRunCommand
from pyatem.field import TransitionSettingsField, KeyPropertiesDveField, KeyPropertiesLumaField


@TemplateLocale(resource_path='/nl/brixit/switcher/ui/upstream-keyer.glade')
class UpstreamKeyer(Gtk.Frame):
    __gtype_name__ = 'UpstreamKeyer'

    keyer_stack = Gtk.Template.Child()
    mask_top = Gtk.Template.Child()
    mask_bottom = Gtk.Template.Child()
    mask_left = Gtk.Template.Child()
    mask_right = Gtk.Template.Child()
    mask_en = Gtk.Template.Child()

    luma_fill = Gtk.Template.Child()
    luma_key = Gtk.Template.Child()
    luma_premultiplied = Gtk.Template.Child()
    luma_clip = Gtk.Template.Child()
    luma_clip_adj = Gtk.Template.Child()
    luma_gain = Gtk.Template.Child()
    luma_gain_adj = Gtk.Template.Child()
    luma_invert = Gtk.Template.Child()

    dve_fill = Gtk.Template.Child()
    dve_shadow_en = Gtk.Template.Child()

    dve_pos_x_adj = Gtk.Template.Child()
    dve_pos_y_adj = Gtk.Template.Child()
    dve_size_x_adj = Gtk.Template.Child()
    dve_size_y_adj = Gtk.Template.Child()
    dve_light_angle_adj = Gtk.Template.Child()
    dve_light_altitude_adj = Gtk.Template.Child()

    dve_border_en = Gtk.Template.Child()
    dve_border_color = Gtk.Template.Child()
    dve_border_opacity = Gtk.Template.Child()
    dve_border_outer_width_adj = Gtk.Template.Child()
    dve_border_inner_width_adj = Gtk.Template.Child()
    dve_border_outer_soften_adj = Gtk.Template.Child()
    dve_border_inner_soften_adj = Gtk.Template.Child()
    dve_border_bevel_position_adj = Gtk.Template.Child()
    dve_border_bevel_soften_adj = Gtk.Template.Child()

    dve_set_a = Gtk.Template.Child()
    dve_set_b = Gtk.Template.Child()

    def __init__(self, index, keyer, connection):
        self.index = index
        self.keyer = keyer
        self.connection = connection

        self.model_changing = False
        self.slider_held = False

        super(Gtk.Frame, self).__init__()
        self.init_template()

    def set_class(self, widget, classname, state):
        if state:
            widget.get_style_context().add_class(classname)
        else:
            widget.get_style_context().remove_class(classname)

    def set_fill_model(self, model):
        self.model_changing = True
        self.dve_fill.set_model(model)
        self.luma_fill.set_model(model)
        self.model_changing = False

    def set_key_model(self, model):
        self.model_changing = True
        self.luma_key.set_model(model)
        self.model_changing = False

    def on_key_properties_base_change(self, data):
        self.model_changing = True
        self.dve_fill.set_active_id(str(data.fill_source))
        self.luma_fill.set_active_id(str(data.fill_source))
        self.luma_key.set_active_id(str(data.key_source))

        if data.type == 0:
            self.keyer_stack.set_visible_child_name('key_luma')
        elif data.type == 1:
            self.keyer_stack.set_visible_child_name('key_chroma')
        elif data.type == 2:
            self.keyer_stack.set_visible_child_name('key_pattern')
        elif data.type == 3:
            self.keyer_stack.set_visible_child_name('key_dve')

        self.model_changing = False

        if data.type != 3:
            self.set_class(self.mask_en, 'active', data.mask_enabled)

            self.mask_top.set_text(str(data.mask_top / 1000))
            self.mask_bottom.set_text(str(data.mask_bottom / 1000))
            self.mask_left.set_text(str(data.mask_left / 1000))
            self.mask_right.set_text(str(data.mask_right / 1000))

    def on_key_properties_luma_change(self, data):
        if not isinstance(data, KeyPropertiesLumaField):
            return

        self.set_class(self.luma_premultiplied, 'active', data.premultiplied)
        self.set_class(self.luma_invert, 'active', data.key_inverted)

        self.luma_clip.set_sensitive(not data.premultiplied)
        self.luma_gain.set_sensitive(not data.premultiplied)

        self.luma_clip_adj.set_value(data.clip)
        self.luma_gain_adj.set_value(data.gain)

    def on_key_properties_dve_change(self, data):
        if not isinstance(data, KeyPropertiesDveField):
            return

        self.set_class(self.dve_shadow_en, 'active', data.shadow_enabled)
        self.set_class(self.dve_border_en, 'active', data.border_enabled)

        self.dve_pos_x_adj.set_value(data.pos_x)
        self.dve_pos_y_adj.set_value(data.pos_y)
        self.dve_size_x_adj.set_value(data.size_x)
        self.dve_size_y_adj.set_value(data.size_y)
        self.dve_light_angle_adj.set_value(data.light_angle)
        self.dve_light_altitude_adj.set_value(data.light_altitude)

        self.dve_border_opacity.set_value(data.border_opacity)
        self.dve_border_outer_width_adj.set_value(data.border_outer_width)
        self.dve_border_inner_width_adj.set_value(data.border_inner_width)
        self.dve_border_outer_soften_adj.set_value(data.border_outer_softness)
        self.dve_border_inner_soften_adj.set_value(data.border_inner_softness)
        self.dve_border_bevel_position_adj.set_value(data.border_bevel_position)
        self.dve_border_bevel_soften_adj.set_value(data.border_bevel_softness)

        r, g, b = data.get_border_color_rgb()
        color = Gdk.RGBA()
        color.red = r
        color.green = g
        color.blue = b
        color.alpha = 1.0
        self.dve_border_color.set_rgba(color)

        self.set_class(self.mask_en, 'active', data.mask_enabled)

        self.mask_top.set_text(str(data.mask_top / 1000))
        self.mask_bottom.set_text(str(data.mask_bottom / 1000))
        self.mask_left.set_text(str(data.mask_left / 1000))
        self.mask_right.set_text(str(data.mask_right / 1000))

    @Gtk.Template.Callback()
    def on_fill_changed(self, widget, *args):
        if self.model_changing:
            return
        source = int(widget.get_active_id())
        cmd = KeyFillCommand(index=self.index, keyer=self.keyer, source=source)
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_key_changed(self, widget, *args):
        if self.model_changing:
            return
        source = int(widget.get_active_id())
        cmd = KeyCutCommand(index=self.index, keyer=self.keyer, source=source)
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_slider_press(self, *args):
        self.slider_held = True

    @Gtk.Template.Callback()
    def on_slider_release(self, *args):
        self.slider_held = False

    @Gtk.Template.Callback()
    def on_dve_pos_x_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, pos_x=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_pos_y_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, pos_y=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_size_x_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, size_x=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_size_y_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, size_y=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_shadow_en_clicked(self, widget):
        state = widget.get_style_context().has_class('active')
        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, shadow_enabled=not state)
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_light_angle_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, angle=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_light_altitude_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, altitude=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_en_clicked(self, widget):
        state = widget.get_style_context().has_class('active')
        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, border_enabled=not state)
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_color_color_set(self, widget):
        color = widget.get_rgba()
        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer)
        cmd.set_border_color_rgb(color.red, color.green, color.blue)
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_opacity_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, border_opacity=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_outer_width_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, outer_width=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_inner_width_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, inner_width=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_outer_soften_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, outer_softness=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_inner_soften_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, inner_softness=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_bevel_soften_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, bevel_softness=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_border_bevel_position_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesDveCommand(index=self.index, keyer=self.keyer, bevel_position=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_keyer_stack_visible_child_notify(self, widget, *args):
        if self.model_changing:
            return
        state = widget.get_visible_child_name()
        if state == 'key_luma':
            cmd = KeyTypeCommand(index=self.index, keyer=self.keyer, type=KeyTypeCommand.LUMA)
        elif state == 'key_chroma':
            cmd = KeyTypeCommand(index=self.index, keyer=self.keyer, type=KeyTypeCommand.CHROMA)
        elif state == 'key_pattern':
            cmd = KeyTypeCommand(index=self.index, keyer=self.keyer, type=KeyTypeCommand.PATTERN)
        elif state == 'key_dve':
            cmd = KeyTypeCommand(index=self.index, keyer=self.keyer, type=KeyTypeCommand.DVE)

        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_luma_premultiplied_clicked(self, widget, *args):
        state = widget.get_style_context().has_class('active')
        cmd = KeyPropertiesLumaCommand(index=self.index, keyer=self.keyer, premultiplied=not state)
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_luma_invert_clicked(self, widget, *args):
        state = widget.get_style_context().has_class('active')
        cmd = KeyPropertiesLumaCommand(index=self.index, keyer=self.keyer, invert_key=not state)
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_luma_clip_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesLumaCommand(index=self.index, keyer=self.keyer, clip=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_luma_gain_adj_value_changed(self, widget):
        if not self.slider_held:
            return

        cmd = KeyPropertiesLumaCommand(index=self.index, keyer=self.keyer, gain=int(widget.get_value()))
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_lock_toggled(self, widget):
        self.set_class(widget, 'program', not widget.get_active)
        self.dve_set_a.set_sensitive(not widget.get_active())
        self.dve_set_b.set_sensitive(not widget.get_active())

    @Gtk.Template.Callback()
    def on_dve_set_a_clicked(self, widget):
        cmd = KeyerKeyframeSetCommand(index=self.index, keyer=self.keyer, keyframe='A')
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_set_b_clicked(self, widget):
        cmd = KeyerKeyframeSetCommand(index=self.index, keyer=self.keyer, keyframe='B')
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_run_full_clicked(self, widget):
        cmd = KeyerKeyframeRunCommand(index=self.index, keyer=self.keyer, run_to='Full')
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_run_a_clicked(self, widget):
        cmd = KeyerKeyframeRunCommand(index=self.index, keyer=self.keyer, run_to='A')
        self.connection.mixer.send_commands([cmd])

    @Gtk.Template.Callback()
    def on_dve_run_b_clicked(self, widget):
        cmd = KeyerKeyframeRunCommand(index=self.index, keyer=self.keyer, run_to='B')
        self.connection.mixer.send_commands([cmd])