예제 #1
0
        private void _meterTimer_Tick(object sender, EventArgs e)
        {
            if (!ShowMeters)
            {
                return;
            }

            if (this.State == null)
            {
                return;
            }
            if (_meterState == null || _meterState.GetUrl() != this.State.GetUrl())
            {
                _meterState = new vMixAPI.State();
                _meterState.Configure(this.State.Ip, this.State.Port);
                _meterState.CreateAsync();
            }

            if (!_subscribed)
            {
                _meterState.OnStateCreated += _meterState_OnStateCreated;
                _subscribed = true;
            }

            //if ((DateTime.Now - _lastMetering).TotalSeconds > 0.05)
            _meterState.CreateAsync();
        }
예제 #2
0
 private string GetInputNumber(string key, vMixAPI.State state = null)
 {
     try
     {
         return((state ?? State).Inputs.Where(x => x.Key == key).FirstOrDefault().Number.ToString());
     }
     catch (Exception)
     {
         return("-1");
     }
 }
예제 #3
0
        private void RealUpdateActiveProperty(bool skipStateDependency = false, vMixAPI.State stateToCheck = null, vMixAPI.State currentState = null)
        {
            stateToCheck = stateToCheck ?? _internalState;
            currentState = currentState ?? State;

            if ((!IsStateDependent && skipStateDependency) || stateToCheck == null || _activeStateUpdateWorker.IsBusy)
            {
                return;
            }
            _activeStateUpdateWorker.RunWorkerAsync(new State[] { stateToCheck, currentState });
        }
예제 #4
0
        private void ExecutionThread(object _state)
        {
            vMixAPI.State state             = (vMixAPI.State)_state;
            Stack <bool?> _conditions       = new Stack <bool?>();
            int           _waitBeforeUpdate = -1;

            for (int _pointer = 0; _pointer < _commands.Count; _pointer++)
            {
                if (_stopThread)
                {
                    return;
                }
                var cmd  = _commands[_pointer];
                var cond = new bool?(true);
                if (_conditions.Count > 0)
                {
                    cond = _conditions.Peek();
                }
                if ((cond.HasValue && cond.Value) ||
                    (cmd.Action.Function == NativeFunctions.CONDITIONEND ||
                     cmd.Action.Function == NativeFunctions.CONDITION ||
                     cmd.Action.Function == NativeFunctions.HASVARIABLE))
                {
                    if (cmd.Action.Native)
                    {
                        switch (cmd.Action.Function)
                        {
                        case NativeFunctions.TIMER:
                            Thread.Sleep(CalculateExpression <int>(cmd.Parameter));
                            break;

                        case NativeFunctions.UPDATESTATE:
                            Dispatcher.Invoke(() => state?.UpdateAsync());
                            break;

                        case NativeFunctions.UPDATEINTERNALBUTTONSTATE:
                            Dispatcher.Invoke(() => _internalState?.UpdateAsync());
                            break;

                        case NativeFunctions.GOTO:
                            _pointer = CalculateExpression <int>(cmd.Parameter) - 1;
                            break;

                        case NativeFunctions.EXECLINK:
                            Dispatcher.Invoke(() => Messenger.Default.Send <string>(cmd.StringParameter));
                            break;

                        case NativeFunctions.LIVETOGGLE:
                            Dispatcher.Invoke(() => Messenger.Default.Send <LIVEToggleMessage>(new LIVEToggleMessage()
                            {
                                State = 2
                            }));
                            break;

                        case NativeFunctions.LIVEOFF:
                            Dispatcher.Invoke(() => Messenger.Default.Send <LIVEToggleMessage>(new LIVEToggleMessage()
                            {
                                State = 0
                            }));
                            break;

                        case NativeFunctions.LIVEON:
                            Dispatcher.Invoke(() => Messenger.Default.Send <LIVEToggleMessage>(new LIVEToggleMessage()
                            {
                                State = 1
                            }));
                            break;

                        case NativeFunctions.CONDITION:
                            _conditions.Push(cond.HasValue && cond.Value ? new bool?(TestCondition(cmd)) : null);
                            break;

                        case NativeFunctions.HASVARIABLE:
                            _conditions.Push(cond.HasValue && cond.Value ? new bool?(GetVariableIndex(CalculateExpression <int>(cmd.Parameter)) != -1) : null);
                            break;

                        case NativeFunctions.CONDITIONEND:
                            _conditions.Pop();
                            break;

                        case NativeFunctions.SETVARIABLE:
                            var idx = GetVariableIndex(CalculateExpression <int>(cmd.Parameter));
                            if (idx == -1)
                            {
                                Dispatcher.Invoke(() => _variables.Add(new Pair <int, object>()
                                {
                                    A = CalculateExpression <int>(cmd.Parameter), B = CalculateObjectParameter(cmd)
                                }));
                            }
                            else
                            {
                                Dispatcher.Invoke(() => _variables[idx].B = CalculateObjectParameter(cmd));
                            }
                            break;
                        }
                    }
                    else if (state != null)
                    {
                        var input = state.Inputs.Where(x => x.Key == cmd.InputKey).FirstOrDefault()?.Number;

                        if (!cmd.Action.StateDirect)
                        {
                            state.SendFunction(string.Format(cmd.Action.FormatString, cmd.InputKey, CalculateExpression <int>(cmd.Parameter), Dispatcher.Invoke(() => CalculateObjectParameter(cmd)), CalculateExpression <int>(cmd.Parameter) - 1, input.HasValue ? input.Value : 0), false);
                        }
                        else
                        {
                            var path  = string.Format(cmd.Action.ActiveStatePath, cmd.InputKey, CalculateExpression <int>(cmd.Parameter), Dispatcher.Invoke(() => CalculateObjectParameter(cmd)), CalculateExpression <int>(cmd.Parameter) - 1, input.HasValue ? input.Value : 0);
                            var value = cmd.Action.StateValue == "Input" ? (object)cmd.InputKey : (cmd.Action.StateValue == "String" ? Dispatcher.Invoke(() => CalculateObjectParameter(cmd)).ToString() : (object)CalculateExpression <int>(cmd.Parameter));
                            SetValueByPath(state, path, value);
                            int flag = 0;
                            while (GetValueByPath(state, path) != value)
                            {
                                Thread.Sleep(50);
                                if (_stopThread)
                                {
                                    return;
                                }
                                if (++flag > 10)
                                {
                                    break;
                                }
                            }
                        }
                        _waitBeforeUpdate = Math.Max(_internalState.Transitions[cmd.Action.TransitionNumber].Duration, _waitBeforeUpdate);
                    }
                }
            }
            _conditions.Clear();
            ThreadPool.QueueUserWorkItem((x) =>
            {
                Enabled = true;
                Thread.Sleep(_waitBeforeUpdate);
                _waitBeforeUpdate = -1;
                Dispatcher.Invoke(() => _internalState.UpdateAsync());
            });
        }