Example #1
0
        public AtemSdkClientWrapper(string address, AtemStateBuilderSettings updateSettings, int id)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetExecutingAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
            if (!logRepository.Configured) // Default to all on the console
            {
                BasicConfigurator.Configure(logRepository);
            }

            Id = id;

            _updateSettings = updateSettings;

            _switcherDiscovery = new CBMDSwitcherDiscovery();
            Assert.NotNull(_switcherDiscovery);

            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                _switcherDiscovery.ConnectTo(address, out _sdkSwitcher, out failReason);
            }
            catch (COMException)
            {
                throw new Exception($"SDK Connection failure: {failReason}");
            }

            //_sdkSwitcher.AddCallback(new SwitcherConnectionMonitor()); // TODO - make this monitor work better!

            _sdkState = new AtemSDKStateMonitor(_sdkSwitcher);
            _sdkState.OnStateChange += (s) => OnSdkStateChange?.Invoke(s);
        }
Example #2
0
        public void Discover()
        {
            this.m_switcherDiscovery = new CBMDSwitcherDiscovery();
            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                this.m_switcherDiscovery.ConnectTo(this.BMDDeviceAddress, out this.m_switcher, out failReason);
                this.IsConnected = true;
            }
            catch (COMException exception1)
            {
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new BMDSwitcherLibExeption("Incompatible firmware");

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new BMDSwitcherLibExeption(string.Format("No response from {0}", this.BMDDeviceAddress));

                default:
                    throw new BMDSwitcherLibExeption(string.Format("Unknown Error: {0}", exception1.Message));
                }
            }
            catch (Exception exception2)
            {
                throw new BMDSwitcherLibExeption(string.Format("Unable to connect to switcher: {0}", exception2.Message));
            }
        }
Example #3
0
 public AtemSwitcher(IPAddress ipAddress)
 {
     this.ipAddress                = ipAddress;
     inputs                        = new List <Input>();
     switcherDiscovery             = new CBMDSwitcherDiscovery();
     switcherMonitor               = new SwitcherMonitor();
     switcherMonitor.Disconnected += (s, e) => { Disconnect(); };
 }
Example #4
0
        public Atem()
        {
            //m_mixEffectBlockMonitor = new MixEffectBlockMonitor();
            //m_mixEffectBlockMonitor.ProgramInputChanged += new SwitcherEventHandler((s, a) => OnProgramInputChanged());
            //m_mixEffectBlockMonitor.PreviewInputChanged += new SwitcherEventHandler((s, a) => OnProgramInputChanged());

            m_switcherDiscovery = new CBMDSwitcherDiscovery();
            if (m_switcherDiscovery == null)
            {
                // TODO: Raise exeception
            }

            SwitcherDisconnected();             // start with switcher disconnected
        }
Example #5
0
    public void SwitcherDisconnected()
    {
        if (m_mixEffectBlock != null)
        {
            // Remove callback
            m_mixEffectBlock.RemoveCallback(m_mixEffectBlockMonitor);

            // Release reference
            m_mixEffectBlock = null;
        }

        if (m_switcherDiscovery != null)
        {
            m_switcherDiscovery = null;
        }
    }
Example #6
0
        public SwitcherControl(System.Windows.Threading.Dispatcher dispatcher, ReportView reportProgrammView, ReportProgress progress)
        {
            m_switcherMonitor = new SwitcherMonitor();
            m_switcherMonitor.SwitcherDisconnected += new SwitcherEventHandler((s, a) => dispatcher.Invoke((Action)(() => SwitcherDisconnected())));
            m_mixEffectBlockMonitor = new MixEffectBlockMonitor();
            m_mixEffectBlockMonitor.TransitionPositionChanged += new SwitcherEventHandler((s, a) => dispatcher.Invoke((Action)(() => UpdateSliderPosition())));
            m_mixEffectBlockMonitor.InTransitionChanged       += new SwitcherEventHandler((s, a) => dispatcher.Invoke((Action)(() => OnInTransitionChanged())));

            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
            _reportProgrammView = reportProgrammView;
            _progress           = progress;
        }
Example #7
0
    private void ConnectAtem(string connectIp)
    {
        m_switcherDiscovery = new CBMDSwitcherDiscovery();
        if (m_switcherDiscovery == null)
        {
            Debug.LogError("Could not create Switcher Discovery Instance.\nATEM Switcher Software may not be installed.");
        }

        _BMDSwitcherConnectToFailure failReason = 0;
        string address = connectIp;

        try
        {
            // Note that ConnectTo() can take several seconds to return, both for success or failure,
            // depending upon hostname resolution and network response times, so it may be best to
            // do this in a separate thread to prevent the main GUI thread blocking.
            m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
        }
        catch (COMException)
        {
            // An exception will be thrown if ConnectTo fails. For more information, see failReason.
            switch (failReason)
            {
            case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                Debug.LogError("No response from Switcher");
                break;

            case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                Debug.LogError("Switcher has incompatible firmware");
                break;

            default:
                Debug.LogError("Connection failed for unknown reason");
                break;
            }
            return;
        }
    }
        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
        }
Example #9
0
        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
        }
        public MainWindow()
        {
            InitializeComponent();
            _BMDSwitcherConnectToFailure failReason = 0;

            switcherDiscovery = new CBMDSwitcherDiscovery();
            try
            {
                switcherDiscovery.ConnectTo("10.11.12.21", out switcher, out failReason);
            }
            catch (COMException)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    MessageBox.Show("No response from Switcher", "Error");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;

                default:
                    MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
                }
            }

            mixEffectBlock1 = null;

            IBMDSwitcherMixEffectBlockIterator meIterator = null;
            IntPtr meIteratorPtr;
            Guid   meIteratorIID = typeof(IBMDSwitcherMixEffectBlockIterator).GUID;

            switcher.CreateIterator(ref meIteratorIID, out meIteratorPtr);
            if (meIteratorPtr != null)
            {
                meIterator = (IBMDSwitcherMixEffectBlockIterator)Marshal.GetObjectForIUnknown(meIteratorPtr);
            }

            if (meIterator != null)
            {
                meIterator.Next(out mixEffectBlock1);
            }

            if (mixEffectBlock1 == null)
            {
                MessageBox.Show("Unexpected: Could not get first mix effect block", "Error");
            }

            IBMDSwitcherInput         currentInput  = null;
            IBMDSwitcherInputIterator inputIterator = null;
            IntPtr inputIteratorPtr;
            Guid   inputIteratorIID = typeof(IBMDSwitcherInputIterator).GUID;

            switcher.CreateIterator(ref inputIteratorIID, out inputIteratorPtr);
            if (inputIteratorPtr != null)
            {
                inputIterator = (IBMDSwitcherInputIterator)Marshal.GetObjectForIUnknown(inputIteratorPtr);
            }

            if (inputIterator != null)
            {
                inputIterator.Next(out currentInput);
                while (currentInput != null)
                {
                    MixerInput input = new MixerInput(currentInput);
                    inputList.Add(input);
                    inputIterator.Next(out currentInput);
                }
            }

            mixEffectBlock1.AddCallback(monitor);
            monitor.InTransitionChanged += new MixerMonitorEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => InTransitionChanged(s, a))));

            indev = new Sanford.Multimedia.Midi.InputDevice(3);
            indev.ChannelMessageReceived += Indev_ChannelMessageReceived;
            indev.StartRecording();

            mappingList.ItemsSource = inputList;
        }
        private void Run()
        {
            m_switcherDiscovery = new CBMDSwitcherDiscovery();
            if (m_switcherDiscovery == null)
            {
                WaitForExit("Could not create Switcher Discovery Instance.\nATEM Switcher Software may not be installed.");
                return;
            }

            _BMDSwitcherConnectToFailure failReason = 0;
            string address = "10.42.13.99";

            try
            {
                // Note that ConnectTo() can take several seconds to return, both for success or failure,
                // depending upon hostname resolution and network response times, so it may be best to
                // do this in a separate thread to prevent the main GUI thread blocking.
                m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
            }
            catch (COMException)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    WaitForExit("No response from Switcher");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    WaitForExit("Switcher has incompatible firmware");
                    break;

                default:
                    WaitForExit("Connection failed for unknown reason");
                    break;
                }
                return;
            }

            Console.WriteLine("Connected");


            m_mediaPool = m_switcher as IBMDSwitcherMediaPool;
            if (m_mediaPool == null)
            {
                WaitForExit("Failed to cast to media pool");
                return;
            }


            m_mediaPool.CreateFrame(_BMDSwitcherPixelFormat.bmdSwitcherPixelFormat10BitYUVA, 1920, 1080, out IBMDSwitcherFrame frame);
            if (frame == null)
            {
                WaitForExit("Failed to create frame");
                return;
            }

            frame.GetBytes(out IntPtr buffer);
            byte[] frameData = RandomFrame();
            Marshal.Copy(frameData, 0, buffer, 1920 * 1080 * 4);

            Stopwatch sw = new Stopwatch();

            uint max_index = 32;
            uint index     = 0;

            while (true)
            {
                sw.Restart();
                UploadStillSdk(index % max_index, "frame " + index, frame);
                sw.Stop();

                Console.WriteLine("Upload outer #{0} took {1}ms", index, sw.ElapsedMilliseconds);

                Thread.Sleep(100);

                index++;
            }


            // End
            WaitForExit();
        }
        public BMDSwitcherManagement(string address)
        {
            //_synchContext = System.Threading.SynchronizationContext.Current;

            m_switcherMonitor = new SwitcherMonitor();
            m_switcherMonitor.SwitcherDisconnected += OnSwitcherDisconnected;


            m_mixEffectBlockMonitor = new MixEffectBlockMonitor();
            m_mixEffectBlockMonitor.ProgramInputChanged += OnProgramInputChanged;

            m_switcherDiscovery = new CBMDSwitcherDiscovery();

            if (m_switcherDiscovery == null)
            {
                return;
            }

            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                // Note that ConnectTo() can take several seconds to return, both for success or failure,
                // depending upon hostname resolution and network response times, so it may be best to
                // do this in a separate thread to prevent the main GUI thread blocking.
                m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
            }
            catch (COMException)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    //MessageBox.Show("No response from Switcher", "Error");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    //MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;

                default:
                    //MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
                }
                return;
            }

            // Get the switcher name:
            string switcherName;

            m_switcher.GetProductName(out switcherName);
            _switcherName = switcherName;


            // Install SwitcherMonitor callbacks:
            m_switcher.AddCallback(m_switcherMonitor);

            m_switcher.IterateInput((i) =>
            {
                InputMonitor newInputMonitor = new InputMonitor(i);

                i.AddCallback(newInputMonitor);
                newInputMonitor.LongNameChanged += new SwitcherEventHandler(OnInputLongNameChanged);
                m_inputMonitors.Add(newInputMonitor);
            });

            // We want to get the first Mix Effect block (ME 1). We create a ME iterator,
            // and then get the first one:
            m_mixEffectBlock1 = m_switcher.GetFirstMixEffectBlock();

            if (m_mixEffectBlock1 != null)
            {
                m_mixEffectBlock1.AddCallback(m_mixEffectBlockMonitor);
                UpdatePrograms();
                this.Connected = true;
            }

            m_audioMixer = m_switcher.GetBMDSwitcherAudioMixer();

            m_audioMixer.IterateAudioInput(i => { _audioInputs.Add(i); });
        }
Example #13
0
        public MainWindow()
        {
            InitializeComponent();

            m_switcherMonitor = new SwitcherMonitor();

            m_audioInputMonitor     = new AudioInputMonitor();
            m_mixEffectBlockMonitor = new MixEffectBlockMonitor();
            m_transitionMonitor     = new TransitionMonitor();
            m_dkeyMonitor           = new DownStreamKeyMonitor();

            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

            _BMDSwitcherConnectToFailure failReason = 0;
            string address = "192.168.30.8";

            try
            {
                // Note that ConnectTo() can take several seconds to return, both for success or failure,
                // depending upon hostname resolution and network response times, so it may be best to
                // do this in a separate thread to prevent the main GUI thread blocking.
                m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
            }
            catch (COMException)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    MessageBox.Show("No response from Switcher", "Error");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;

                default:
                    MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
                }
                return;
            }

            m_mixEffectBlockMonitor.ProgramInputChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => UpdateProgramButtonSelection())));
            m_mixEffectBlockMonitor.PreviewInputChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => UpdatePreviewButtonSelection())));
            m_mixEffectBlockMonitor.TransitionFramesRemainingChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => UpdateTransitionFramesRemaining())));
            m_mixEffectBlockMonitor.TransitionPositionChanged        += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => UpdateSliderPosition())));
            m_mixEffectBlockMonitor.InTransitionChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => OnInTransitionChanged())));

            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.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.DimLevelChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.GainChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.LevelNotificationChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.MonitorEnableChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.MuteChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.SoloInputChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloInputChanged())));

            m_audioInputMonitor = new AudioInputMonitor();
            //m_audioInputMonitor.IsMixedInChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloInputChanged())));
            //m_audioInputMonitor.MixOptionChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioInputMonitor.BalanceChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloInputChanged())));
            //m_audioInputMonitor.GainChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioInputMonitor.IsMixedInChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioInputMonitor.LevelNotificationChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioInputMonitor.MixOptionChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));


            //m_transitionMonitor.TransitionStyleChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => OnNextTransitionStyleChanged())));
            //m_dkeyMonitor. += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => OnNextTransitionStyleChanged())));

            SwitcherConnected();
        }