public void Dispose()
        {
            Stop();

            foreach (var outputChannel1 in OutputChannels.ToArray())
            {
                foreach (var outputChannel2 in OutputChannels)
                {
                    if (outputChannel1 != outputChannel2)
                    {
                        ManagedBass.Bass.ChannelRemoveLink(outputChannel1.Handle, outputChannel2.Handle);
                    }
                }

                OutputChannels.Remove(outputChannel1);

                outputChannel1.Dispose();
            }

            OutgoingConnections.Clear();

            var networkChannel = SourceChannel as NetworkChannel;

            if (networkChannel != null)
            {
                networkChannel.DownloadComplete -= OnDownloadComplete;
            }

            SourceChannel.MediaEnded -= OnMediaEnded;
            SourceChannel.Dispose();

            Disposed?.Invoke(this, EventArgs.Empty);
        }
示例#2
0
        /// <summary>
        /// Connects this Neuron to the <paramref name="nextNeuron" />
        /// </summary>
        /// <param name="nextNeuron">The Neuron to connect to.</param>
        internal void ConnectTo([NotNull] Neuron nextNeuron)
        {
            if (nextNeuron == null)
            {
                throw new ArgumentNullException(nameof(nextNeuron));
            }

            OutgoingConnections.Add(new NeuronConnection(nextNeuron));
        }
示例#3
0
        /// <summary>
        /// Evaluates the values from the incoming connections, averages them by the count of connections,
        /// and calculates the Neuron's Value, which is then passed on to any outgoing connections.
        /// </summary>
        internal void Evaluate()
        {
            if (_numInputs > 0)
            {
                Value = _sum / _numInputs;
                _sum  = 0;
            }

            OutgoingConnections.Each(c => c.Fire(Value));
        }
        public void RemoveOutgoingConnection(IOutputAudioDevice audioDevice)
        {
            var playbackDevice = audioDevice.AsPlayback();

            var splitterChannel = OutputChannels.Single(c => c.Device == playbackDevice);

            OutputChannels.Remove(splitterChannel);

            foreach (var outputChannel in OutputChannels)
            {
                ManagedBass.Bass.ChannelRemoveLink(splitterChannel.Handle, outputChannel.Handle);
                ManagedBass.Bass.ChannelRemoveLink(outputChannel.Handle, splitterChannel.Handle);
            }

            OutgoingConnections.Remove(audioDevice);

            splitterChannel.Dispose();
        }
        public void AddOutgoingConnection(IOutputAudioDevice audioDevice)
        {
            var playbackDevice = audioDevice.AsPlayback();

            playbackDevice.Init();

            var splitterChannel = new SplitChannel(SourceChannel)
            {
                Device = playbackDevice,
                Volume = Volume
            };

            if (splitterChannel.Device != playbackDevice)
            {
                splitterChannel.Dispose();

                throw new InvalidOperationException($"Cannot set outgoing connection for device {audioDevice}");
            }

            foreach (var outputChannel in OutputChannels)
            {
                outputChannel.Link(splitterChannel.Handle);
                splitterChannel.Link(outputChannel.Handle);
            }

            OutputChannels.Add(splitterChannel);

            OutgoingConnections.Add(audioDevice);

            if (IsPlaying)
            {
                foreach (var outputChannel in OutputChannels)
                {
                    Logger.Debug("AddOutgoingConnection: Before pause for outputChannel device {device} position = {position}", outputChannel.Device, outputChannel.Position);

                    outputChannel.Pause();

                    Logger.Debug("AddOutgoingConnection: After pause for outputChannel device {device} position = {position}", outputChannel.Device, outputChannel.Position);
                }

                var position = OutputChannels.Min(c => c.Position);

                Logger.Debug("AddOutgoingConnection: MinPosition = {position}", position);

                foreach (var outputChannel in OutputChannels)
                {
                    Logger.Debug("AddOutgoingConnection: Before updating position for outputChannel device {device} position = {position}", outputChannel.Device, outputChannel.Position);

                    // Set position few times, because sometimes once isn't working
                    var i = 5;
                    while (i-- > 0)
                    {
                        outputChannel.Position = position;
                    }

                    Logger.Debug("AddOutgoingConnection: After updating position for outputChannel device {device} position = {position}", outputChannel.Device, outputChannel.Position);
                }

                Play();
            }
        }
示例#6
0
        public void RemoveOutgoingConnection(IOutputAudioDevice audioDevice)
        {
            OutgoingConnections.Remove(audioDevice);

            _playback?.RemoveOutgoingConnection(audioDevice);
        }
示例#7
0
        public void AddOutgoingConnection(IOutputAudioDevice audioDevice)
        {
            OutgoingConnections.Add(audioDevice);

            _playback?.AddOutgoingConnection(audioDevice);
        }