コード例 #1
0
ファイル: Switcher.cs プロジェクト: cleitet/atemlib
        public void Connect()
        {
            if (this.connected)
            {
                return;
            }

            IBMDSwitcherDiscovery        switcherDiscovery = new CBMDSwitcherDiscovery();
            _BMDSwitcherConnectToFailure failReason        = 0;

            try
            {
                switcherDiscovery.ConnectTo(this.deviceAddress, out this.switcher, out failReason);
                this.connected = true;
            }
            catch (COMException ex)
            {
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new SwitcherLibException("Incompatible firmware");

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new SwitcherLibException(String.Format("No response from {0}", this.deviceAddress));

                default:
                    throw new SwitcherLibException(String.Format("Unknown Error: {0}", ex.Message));
                }
            }
            catch (Exception ex)
            {
                throw new SwitcherLibException(String.Format("Unable to connect to switcher: {0}", ex.Message));
            }
        }
コード例 #2
0
        public void ConnectTo(String address)
        {
            IBMDSwitcherDiscovery discovery = new CBMDSwitcherDiscovery();

            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                IBMDSwitcher switcher;
                // 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.
                discovery.ConnectTo(address, out switcher, out failReason);
                Switcher = switcher;
            }
            catch (COMException ex)
            {
                Switcher = null;
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new Exception("No response from Switcher", ex);

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new Exception("Switcher has incompatible firmware", ex);

                default:
                    throw new Exception("Connection failed for unknown reason", ex);
                }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            // Create switcher discovery object
            IBMDSwitcherDiscovery discovery = new CBMDSwitcherDiscovery();

            // Connect to switcher
            IBMDSwitcher switcher;
            _BMDSwitcherConnectToFailure failureReason;

            discovery.ConnectTo("192.168.10.240", out switcher, out failureReason);
            Console.WriteLine("Connected to switcher");

            var atem = new AtemSwitcher(switcher);

            // Get reference to various objects
            IBMDSwitcherMixEffectBlock           me0 = atem.MixEffectBlocks.First();
            IBMDSwitcherTransitionParameters     me0TransitionParams     = me0 as IBMDSwitcherTransitionParameters;
            IBMDSwitcherTransitionWipeParameters me0WipeTransitionParams = me0 as IBMDSwitcherTransitionWipeParameters;
            IBMDSwitcherInput input4 = atem.SwitcherInputs
                                       .Where((i, ret) => {
                _BMDSwitcherPortType type;
                i.GetPortType(out type);
                return(type == _BMDSwitcherPortType.bmdSwitcherPortTypeExternal);
            })
                                       .ElementAt(4);

            // Setup the transition
            Console.WriteLine("Setting preview input");
            me0.SetPreviewInput(GetInputId(input4));

            Console.WriteLine("Setting next transition selection");
            me0TransitionParams.SetNextTransitionSelection(_BMDSwitcherTransitionSelection.bmdSwitcherTransitionSelectionBackground);

            Console.WriteLine("Setting next transition style");
            me0TransitionParams.SetNextTransitionStyle(_BMDSwitcherTransitionStyle.bmdSwitcherTransitionStyleWipe);

            Console.WriteLine("Setting transition style");
            me0WipeTransitionParams.SetPattern(_BMDSwitcherPatternStyle.bmdSwitcherPatternStyleRectangleIris);

            Console.WriteLine("Setting transition rate");
            me0WipeTransitionParams.SetRate(60);

            // Perform the transition
            Console.WriteLine("Performing auto transition");
            me0.PerformAutoTransition();
            System.Threading.Thread.Sleep(2000);
            System.Threading.Thread.Sleep(1000);
            me0.PerformAutoTransition();

            Console.Write("Press ENTER to exit...");
            Console.ReadLine();
        }
コード例 #4
0
        public VisionService(String IP)
        {
            if (!MainForm.IGNORE_VISION)
            {
                _BMDSwitcherConnectToFailure failReason = 0;

                CBMDSwitcherDiscovery switcher_discovery = new CBMDSwitcherDiscovery();
                if (switcher_discovery == null)
                {
                    throw new Exception("ATEM Switcher Software not installed");
                }

                try
                {
                    switcher_discovery.ConnectTo(IP, out this.Switcher, out failReason);
                }
                catch (COMException)
                {
                    switch (failReason)
                    {
                    case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                        throw new Exception("No response from Switcher at " + IP);

                    case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                        throw new Exception("Switcher at " + IP + " has incompatible firmware");

                    default:
                        throw new Exception("Connection to " + IP + " failed for unknown reason");
                    }
                }

                if (this.Switcher != null)
                {
                    IntPtr input_iterator_ptr;
                    this.Switcher.CreateIterator(typeof(IBMDSwitcherInputIterator).GUID, out input_iterator_ptr);
                    if (input_iterator_ptr != null)
                    {
                        this.InputIterator = (IBMDSwitcherInputIterator)Marshal.GetObjectForIUnknown(input_iterator_ptr);
                    }
                    else
                    {
                        this.Switcher = null;
                    }
                }
            }
        }
コード例 #5
0
        public VisionService(String IP)
        {
            if (!MainForm.IGNORE_VISION)
            {
                _BMDSwitcherConnectToFailure failReason = 0;

                CBMDSwitcherDiscovery switcher_discovery = new CBMDSwitcherDiscovery();
                if (switcher_discovery == null)
                {
                    throw new Exception("ATEM Switcher Software not installed");
                }

                try
                {
                    switcher_discovery.ConnectTo(IP, out this.Switcher, out failReason);
                }
                catch (COMException)
                {
                    switch (failReason)
                    {
                        case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                            throw new Exception("No response from Switcher at " + IP);
                        case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                            throw new Exception("Switcher at " + IP + " has incompatible firmware");
                        default:
                            throw new Exception("Connection to " + IP + " failed for unknown reason");
                    }
                }

                if (this.Switcher != null)
                {
                    IntPtr input_iterator_ptr;
                    this.Switcher.CreateIterator(typeof(IBMDSwitcherInputIterator).GUID, out input_iterator_ptr);
                    if (input_iterator_ptr != null)
                    {
                        this.InputIterator = (IBMDSwitcherInputIterator)Marshal.GetObjectForIUnknown(input_iterator_ptr);
                    }
                    else
                    {
                        this.Switcher = null;
                    }
                }
            }
        }
コード例 #6
0
        public void connect()
        {
            if (is_connecting || is_connected)
            {
                return;
            }

            // Connect to switcher
            _BMDSwitcherConnectToFailure failureReason = 0;

            is_connecting = true;
            try
            {
                CBMDSwitcherDiscovery atem_discovery = new CBMDSwitcherDiscovery();
                atem_discovery.ConnectTo(atem_ip, out atem_switcher, out failureReason);
                Log.Debug("Connected to ATEM");
            }
            catch (COMException comEx)
            {
                Log.Error("Failed to connect to ATM, got error: " + comEx.Message);
                atem_switcher = null;
            }
            finally
            {
                if (failureReason == 0 && atem_switcher != null)
                {
                    switcherConnected();
                    if (inputs != null && inputs[0] != null && inputs[1] != null && inputs[2] != null && inputs[3] != null)
                    {
                        is_connected = true;
                    }
                    else
                    {
                        is_connected = false;
                    }
                }
                else
                {
                    is_connected = false;
                }
                is_connecting = false;
            }
        }
コード例 #7
0
        IBMDSwitcher ConnectImpl()
        {
            if (string.IsNullOrEmpty(_ipaddress))
            {
                Console.WriteLine("Warning: IP address has not been initialized. I do not like your chances.");
            }

            if (_switcher == null || !_isConnected)
            {
                var discovery = new CBMDSwitcherDiscovery();
                _BMDSwitcherConnectToFailure failure = 0;
                try
                {
                    discovery.ConnectTo(_ipaddress, out _switcher, out failure);
                }
                catch (System.Runtime.InteropServices.COMException e)
                {
                    _logger.LogWarning(e, $"Could not connect: {failure}");
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Could not connect");
                }
                if (failure == 0)
                {
                    _isConnected = true;
                    _switcher.AddCallback(this);
                    _switcher.GetProductName(out string productName);
                    _logger.LogInformation($"Happy Days... connected to {productName}@{_ipaddress}!");
                }
                else
                {
                    _logger.LogWarning(failure.ToString());
                }
            }

            return(_switcher);
        }
コード例 #8
0
        private void ButtonConnect_Click(object sender, RoutedEventArgs e)
        {
            bSwitcherDiscovery = new CBMDSwitcherDiscovery();
            if (bSwitcherDiscovery == null)
            {
                MessageBox.Show("Could not create Switcher Discovery Instance.\n"
                                + "ATEM Switcher Software may not be installed.", "Error");
                return;
            }

            string deviceAddress = TextBoxSwitcherIPAddress.Text;
            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                bSwitcherDiscovery.ConnectTo(deviceAddress, out bSwitcher, out failReason);
            }
            catch (COMException)
            {
                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;
            }

            OnSwitcherConnected();
        }
コード例 #9
0
ファイル: Switcher.cs プロジェクト: imorrish/atemlib
        public void Connect()
        {
            if (this.connected)
            {
                return;
            }

            IBMDSwitcherDiscovery switcherDiscovery = new CBMDSwitcherDiscovery();
            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                switcherDiscovery.ConnectTo(this.deviceAddress, out this.switcher, out failReason);
                this.connected = true;

                // Get the first Mix Effect block (ME 1).
                m_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)
                    return;

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

                if (m_mixEffectBlock1 == null)
                {
                    throw new SwitcherLibException("Unexpected: Could not get first mix effect block");

                }

                // Get the second Mix Effect block (ME 2).
                m_mixEffectBlock2 = null;
                if (meIterator != null)
                {
                    meIterator.Next(out m_mixEffectBlock2);
                }

            }
            catch (COMException ex)
            {
                switch (failReason)
                {
                    case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                        throw new SwitcherLibException("Incompatible firmware");

                    case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                        throw new SwitcherLibException(String.Format("No response from {0}", this.deviceAddress));

                    default:
                        throw new SwitcherLibException(String.Format("Unknown Error: {0}", ex.Message));
                }
            }
            catch (Exception ex)
            {
                throw new SwitcherLibException(String.Format("Unable to connect to switcher: {0}", ex.Message));
            }
        }
コード例 #10
0
        public Switcher(string ipAddress)
        {
            var options = new PusherOptions
            {
                Cluster   = "us2",
                Encrypted = true
            };

            pusher = new Pusher(
                "1137245",
                "f9cabd4c01730143d579",
                "3b87a4daf5b3f26ee1be",
                options);


            IBMDSwitcherDiscovery        discovery = new CBMDSwitcherDiscovery();
            _BMDSwitcherConnectToFailure failureReason;

            discovery.ConnectTo(ipAddress, out m_switcher, out failureReason);


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

            m_mixEffectBlockMonitor = new MixEffectBlockMonitor();
            m_mixEffectBlockMonitor.ProgramInputChanged += OnSwitcherProgramChange;
            m_mixEffectBlockMonitor.PreviewInputChanged += OnSwitcherPreviewChange;

            m_switcher.AddCallback(m_switcherMonitor);

            IBMDSwitcherInput input = null;

            // We create input monitors for each input. To do this we iterate over all inputs:
            // This will allow us to update the combo boxes when input names change:
            IBMDSwitcherInputIterator inputIterator = null;
            IntPtr inputIteratorPtr;
            Guid   inputIteratorIID = typeof(IBMDSwitcherInputIterator).GUID;

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

            if (inputIterator != null)
            {
                input = null;
                inputIterator.Next(out input);
                while (input != null)
                {
                    InputMonitor newInputMonitor = new InputMonitor(input);
                    input.AddCallback(newInputMonitor);

                    m_inputMonitors.Add(newInputMonitor);

                    inputIterator.Next(out input);
                }
            }


            //if (m_mixEffectBlock1 != null)
            //{
            //    // Remove callback
            //    m_mixEffectBlock1.RemoveCallback(m_mixEffectBlockMonitor);

            //    // Release reference
            //    m_mixEffectBlock1 = null;
            //}

            //if (m_switcher != null)
            //{
            //    // Remove callback:
            //    m_switcher.RemoveCallback(m_switcherMonitor);

            //    // release reference:
            //    m_switcher = null;
            //}


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

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

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

            if (meIterator == null)
            {
                return;
            }

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


            // Install MixEffectBlockMonitor callbacks:
            m_mixEffectBlock1.AddCallback(m_mixEffectBlockMonitor);



            // Get an input iterator.
            inputIterator    = null;
            inputIteratorIID = typeof(IBMDSwitcherInputIterator).GUID;
            m_switcher.CreateIterator(ref inputIteratorIID, out inputIteratorPtr);
            if (inputIteratorPtr != null)
            {
                inputIterator = (IBMDSwitcherInputIterator)Marshal.GetObjectForIUnknown(inputIteratorPtr);
            }

            if (inputIterator == null)
            {
                return;
            }

            input = null;
            inputIterator.Next(out input);
            while (input != null)
            {
                string inputName;
                long   inputId;

                input.GetInputId(out inputId);
                input.GetLongName(out inputName);

                // Add items to list:
                m_output_list.Add(new StringObjectPair <long>(inputName, inputId));
                //m_output_list.Add(new StringObjectPair<long>(inputName, inputId));

                inputIterator.Next(out input);
            }



            //while (true)
            //{

            //}
        }
コード例 #11
0
        public void Connect()
        {
            if (this.connected)
            {
                return;
            }

            IBMDSwitcherDiscovery        switcherDiscovery = new CBMDSwitcherDiscovery();
            _BMDSwitcherConnectToFailure failReason        = 0;

            try
            {
                switcherDiscovery.ConnectTo(this.deviceAddress, out this.switcher, out failReason);
                this.connected = true;

                // Get the first Mix Effect block (ME 1).
                m_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)
                {
                    return;
                }

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

                if (m_mixEffectBlock1 == null)
                {
                    throw new SwitcherLibException("Unexpected: Could not get first mix effect block");
                }

                // Get the second Mix Effect block (ME 2).
                m_mixEffectBlock2 = null;
                if (meIterator != null)
                {
                    meIterator.Next(out m_mixEffectBlock2);
                }
            }
            catch (COMException ex)
            {
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new SwitcherLibException("Incompatible firmware");

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new SwitcherLibException(String.Format("No response from {0}", this.deviceAddress));

                default:
                    throw new SwitcherLibException(String.Format("Unknown Error: {0}", ex.Message));
                }
            }
            catch (Exception ex)
            {
                throw new SwitcherLibException(String.Format("Unable to connect to switcher: {0}", ex.Message));
            }
        }