forked from elgarf/vMixUTC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.cs
237 lines (188 loc) · 8.49 KB
/
Input.cs
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Xml.Serialization;
namespace vMixAPI
{
[Serializable]
public class Input : DependencyObject, INotifyPropertyChanged
{
[XmlIgnore]
public int Index
{
get
{
return Number + 1;
}
}
[XmlIgnore]
public int ID
{
get
{
var inputsCfg = 0;
foreach (var item in Elements)
{
inputsCfg += item.ID % (65536 * 15);
}
return ((Title + Type + Duration.ToString()).GetHashCode() + inputsCfg);
}
}
State _controlledState;
[XmlIgnore]
public State ControlledState { get { return _controlledState; } set {
foreach (var item in Elements)
item.ControlledState = value;
/*foreach (var item in Overlays)
item.ControlledState = value;*/
_controlledState = value;
} }
[XmlAttribute("key")]
public string Key { get; set; }
[XmlAttribute("number")]
public int Number { get; set; }
[XmlAttribute("type")]
public string Type { get; set; }
[XmlAttribute("title")]
public string Title { get; set; }
[XmlText()]
public string InnerTitle { get; set; }
[XmlAttribute("state")]
public string State { get; set; }
[XmlAttribute("position")]
///Position can be not actual, call State.Update() before read
public int Position
{
get { return (int)GetValue(PositionProperty); }
set { SetValue(PositionProperty, value); RaisePropertyChanged("Position"); }
}
// Using a DependencyProperty as the backing store for Position. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PositionProperty =
DependencyProperty.Register("Position", typeof(int), typeof(Input), new PropertyMetadata(0, InternalPropertyChanged));
private static void InternalPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (vMixAPI.State.IsInitializing)
return;
switch (e.Property.Name)
{
case "Position":
((Input)d).ControlledState.InputSetPosition(((Input)d).Number, (int)e.NewValue);
break;
case "SelectedIndex":
((Input)d).ControlledState.InputSelectIndex(((Input)d).Number.ToString(), (int)e.NewValue);
break;
case "Loop":
if ((bool)e.NewValue)
((Input)d).ControlledState.InputLoopOn(((Input)d).Number);
else
((Input)d).ControlledState.InputLoopOff(((Input)d).Number);
break;
case "Muted":
if (e.NewValue != e.OldValue)
((Input)d).ControlledState.Audio(((Input)d).Number);
break;
}
}
[XmlAttribute("duration")]
public int Duration { get; set; }
[XmlAttribute("selectedIndex")]
public int SelectedIndex
{
get { return (int)GetValue(SelectedIndexProperty); }
set { SetValue(SelectedIndexProperty, value); RaisePropertyChanged("SelectedIndex"); }
}
// Using a DependencyProperty as the backing store for SelectedIndex. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectedIndexProperty =
DependencyProperty.Register("SelectedIndex", typeof(int), typeof(Input), new PropertyMetadata(0, InternalPropertyChanged));
[XmlAttribute("muted")]
public bool Muted
{
get { return (bool)GetValue(MutedProperty); }
set { SetValue(MutedProperty, value); RaisePropertyChanged("Muted"); }
}
// Using a DependencyProperty as the backing store for Muted. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MutedProperty =
DependencyProperty.Register("Muted", typeof(bool), typeof(Input), new PropertyMetadata(false, InternalPropertyChanged));
[XmlAttribute("loop")]
public bool Loop
{
get { return (bool)GetValue(LoopProperty); }
set { SetValue(LoopProperty, value); RaisePropertyChanged("Loop"); }
}
// Using a DependencyProperty as the backing store for Loop. This enables animation, styling, binding, etc...
public static readonly DependencyProperty LoopProperty =
DependencyProperty.Register("Loop", typeof(bool), typeof(Input), new PropertyMetadata(false, InternalPropertyChanged));
[XmlAttribute("meterF1")]
public double MeterF1
{
get { return (double)GetValue(MeterF1Property); }
set { SetValue(MeterF1Property, value); }
}
// Using a DependencyProperty as the backing store for MeterF1. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MeterF1Property =
DependencyProperty.Register("MeterF1", typeof(double), typeof(Input), new PropertyMetadata(default(double)));
[XmlAttribute("meterF2")]
public double MeterF2
{
get { return (double)GetValue(MeterF2Property); }
set { SetValue(MeterF2Property, value); }
}
// Using a DependencyProperty as the backing store for MeterF1. This enables animation, styling, binding, etc...
public static readonly DependencyProperty VolumeProperty =
DependencyProperty.Register("Volume", typeof(double), typeof(Input), new PropertyMetadata(default(double)));
[XmlAttribute("volume")]
public double Volume
{
get { return (double)GetValue(VolumeProperty); }
set {
/*ControlledState?.SendFunction("Function", "SetVolume",
"Value", ((int)value).ToString(),
"Input", Key);*/
SetValue(VolumeProperty, value);
}
}
// Using a DependencyProperty as the backing store for MeterF1. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MeterF2Property =
DependencyProperty.Register("MeterF2", typeof(double), typeof(Input), new PropertyMetadata(default(double)));
[XmlAttribute("audiobusses")]
public string Audiobusses
{
get { return (string)GetValue(AudiobussesProperty); }
set { SetValue(AudiobussesProperty, value); }
}
// Using a DependencyProperty as the backing store for Audiobusses. This enables animation, styling, binding, etc...
public static readonly DependencyProperty AudiobussesProperty =
DependencyProperty.Register("Audiobusses", typeof(string), typeof(Input), new PropertyMetadata("M"));
[XmlElement(typeof(InputText), ElementName = "text"),
XmlElement(typeof(InputOverlay), ElementName = "overlay"),
XmlElement(typeof(InputPosition), ElementName = "position"),
XmlElement(typeof(InputImage), ElementName = "image")]
public ObservableCollection<InputBase> Elements { get; set; }
[XmlArray("list"), XmlArrayItem(ElementName = "item")]
public ObservableCollection<string> Items { get; set; }
public Input()
{
Elements = new ObservableCollection<InputBase>();
Elements.CollectionChanged += Elements_CollectionChanged;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
private void Elements_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
foreach (var item in e.NewItems.OfType<InputBase>())
{
item.InputNumber = this.Number;
item.InputKey = this.Key;
item.ControlledState = this.ControlledState;
}
}
}
}