public SwitcherPanel() { InitializeComponent(); // Populate the mainThreadId with the current thread id (since it's the main one) mainThreadId = Thread.CurrentThread.ManagedThreadId; // All interactions with the ATEM switcher need to happen on the background thread. Trying to interact // with the DLL from any thread other than the thread it was created on will cause an exception. // All interactions with the GUI need to happen on the main thread. // This means we keep doing a lot of switching between main and background threads via new Thread() and this.Invoke() new Thread(() => { m_switcherMonitor = new SwitcherMonitor(); // note: this invoke pattern ensures our callback is called in the main thread. We are making double // use of lambda expressions here to achieve this. // Essentially, the events will arrive at the callback class (implemented by our monitor classes) // on a separate thread. We must marshal these to the main thread, and we're doing this by calling // invoke on the Windows Forms object. The lambda expression is just a simplification. m_switcherMonitor.SwitcherDisconnected += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => SwitcherDisconnected()))); m_mixEffectBlockMonitor = new MixEffectBlockMonitor(); m_mixEffectBlockMonitor.ProgramInputChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => UpdateProgramButtonSelection()))); m_mixEffectBlockMonitor.PreviewInputChanged += new SwitcherEventHandler((s, a) => UpdatePreviewButtonSelection()); m_mixEffectBlockMonitor.TransitionFramesRemainingChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => UpdateTransitionFramesRemaining()))); m_mixEffectBlockMonitor.TransitionPositionChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => UpdateSliderPosition()))); m_mixEffectBlockMonitor.InTransitionChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => OnInTransitionChanged()))); m_switcherDiscovery = new CBMDSwitcherDiscovery(); if (m_switcherDiscovery == null) { this.Invoke((Action)(() => { MessageBox.Show("Could not create Switcher Discovery Instance.\nATEM Switcher Software may not be installed.", "Error"); })); Environment.Exit(1); } }).Start(); SwitcherDisconnected(); // start with switcher disconnected }
public Theater8() { InitializeComponent(); m_switcherMonitor = new SwitcherMonitor(); // note: this invoke pattern ensures our callback is called in the main thread. We are making double // use of lambda expressions here to achieve this. // Essentially, the events will arrive at the callback class (implemented by our monitor classes) // on a separate thread. We must marshell these to the main thread, and we're doing this by calling // invoke on the Windows Forms object. The lambda expression is just a simplification. m_switcherMonitor.SwitcherDisconnected += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => SwitcherDisconnected()))); m_mixEffectBlockMonitor = new MixEffectBlockMonitor(); //m_mixEffectBlockMonitor.TransitionFramesRemainingChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => UpdateTransitionFramesRemaining()))); //m_mixEffectBlockMonitor.TransitionPositionChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => UpdateSliderPosition()))); //m_mixEffectBlockMonitor.InTransitionChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => OnInTransitionChanged()))); //m_mixEffectBlockMonitor.FadeToBlackFramesRemainingChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => FTBRateChanged()))); //m_mixEffectBlockMonitor.FadeToBlackRateChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => FTBRateChanged()))); //m_mixEffectBlockMonitor.InFadeToBlackChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => InFadeToBlackChanged()))); //m_mixEffectBlockMonitor.PreviewTransitionChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => PreviewTransitionChanged()))); m_mixEffectBlockMonitor.ProgramInputChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => ProgramInputChanged()))); //m_mixEffectBlockMonitor.PreviewInputChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => PreviewInputChanged()))); m_transitionMonitor = new TransitionMonitor();/* m_transitionMonitor.NextTransitionSelectionChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => TransitionSelectionChanged()))); m_transitionMonitor.NextTransitionStyleChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => NextTransitionStyleChanged()))); m_transitionMonitor.TransitionSelectionChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => TransitionSelectionChanged()))); m_transitionMonitor.TransitionStyleChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => TransitionStyleChanged()))); */ m_keyMonitor = new KeyMonitor(); //m_keyMonitor.CanBeDVEKeyChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerCanBeDVEKeyChanged()))); //m_keyMonitor.InputCutChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerInputCutChanged()))); //m_keyMonitor.InputFillChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerInputFillChanged()))); //m_keyMonitor.MaskBottomChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerMaskBottomChanged()))); //m_keyMonitor.MaskedChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerMaskedChanged()))); //m_keyMonitor.MaskLeftChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerMaskLeftChanged()))); //m_keyMonitor.MaskRightChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerMaskRightChanged()))); //m_keyMonitor.MaskTopChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerMaskTopChanged()))); m_keyMonitor.OnAirChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerOnAirChanged()))); //m_keyMonitor.TypeChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => KeyerTypeChanged()))); m_auxMonitor = new InputAuxMonitor(); m_auxMonitor.InputSourceChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => InputAuxChanged()))); m_dkeyMonitor = new DownStreamKeyMonitor();/* //m_dkeyMonitor.ClipChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerClipChanged()))); m_dkeyMonitor.FramesRemainingChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerFramesRemainingChanged()))); //m_dkeyMonitor.GainChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerGainChanged()))); //m_dkeyMonitor.InputCutChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerInputCutChanged()))); //m_dkeyMonitor.InputFillChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerInputFillChanged()))); //m_dkeyMonitor.InverseChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerInverseChanged()))); m_dkeyMonitor.IsAutoTransitioningChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerIsAutoTransitioningChanged()))); //m_dkeyMonitor.IsTransitioningChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerIsTransitioningChanged()))); //m_dkeyMonitor.MaskBottomChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerMaskBottomChanged()))); //m_dkeyMonitor.MaskedChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerMaskedChanged()))); //m_dkeyMonitor.MaskLeftChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerMaskLeftChanged()))); //m_dkeyMonitor.MaskRightChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerMaskRightChanged()))); //m_dkeyMonitor.MaskTopChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerMaskTopChanged()))); m_dkeyMonitor.OnAirChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerOnAirChanged()))); //m_dkeyMonitor.PreMultipliedChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerPreMultipliedChanged()))); m_dkeyMonitor.RateChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerFramesRemainingChanged()))); m_dkeyMonitor.TieChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => DKeyerTieChanged()))); */ m_audioMixerMonitor = new AudioMixerMonitor();/* m_audioMixerMonitor.ProgramOutBalanceChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioProgramOutBalanceChanged()))); m_audioMixerMonitor.ProgramOutGainChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioProgramOutGainChanged()))); m_audioMixerMonitor.ProgramOutLevelNotificationChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioProgramOutLevelNotificationChanged()))); */ m_audioOutputMonitor = new AudioMixerMonitorOutputMonitor();/* m_audioOutputMonitor.DimChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioOutputDimChanged()))); //m_audioOutputMonitor.DimLevelChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioOutputDimLevelChanged()))); m_audioOutputMonitor.GainChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioOutputGainChanged()))); //m_audioOutputMonitor.LevelNotificationChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioOutputLevelNotificationChanged()))); m_audioOutputMonitor.MonitorEnableChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioOutputEnableChanged()))); m_audioOutputMonitor.MuteChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioOutputMuteChanged()))); //m_audioOutputMonitor.SoloChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioOutputSoloChanged()))); //m_audioOutputMonitor.SoloInputChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioOutputSoloInputChanged()))); */ m_audioInputMonitor = new AudioInputMonitor(); /* m_audioInputMonitor.BalanceChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioBalanceChanged()))); m_audioInputMonitor.GainChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioGainChanged()))); m_audioInputMonitor.IsMixedInChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioIsMixedInChanged()))); m_audioInputMonitor.LevelNotificationChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioLevelNotificationChanged()))); m_audioInputMonitor.MixOptionChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioMixOptionChanged()))); */ m_switcherDiscovery = new CBMDSwitcherDiscovery(); if (m_switcherDiscovery == null) { MessageBox.Show("Could not create Switcher Discovery Instance.\nATEM Switcher Software may not be installed.", "Error"); Environment.Exit(1); } SwitcherDisconnected(); // start with switcher disconnected }