예제 #1
0
 private void UpdatePseudoClasses(NotificationPosition position)
 {
     PseudoClasses.Set(":topleft", position == NotificationPosition.TopLeft);
     PseudoClasses.Set(":topright", position == NotificationPosition.TopRight);
     PseudoClasses.Set(":bottomleft", position == NotificationPosition.BottomLeft);
     PseudoClasses.Set(":bottomright", position == NotificationPosition.BottomRight);
 }
예제 #2
0
 public void SetNotificationPosition(NotificationPosition position)
 {
     if (IsActive)
     {
         SteamAPI.SetNotificationPosition((SteamSDK.NotificationPosition)(int) position);
     }
 }
예제 #3
0
        private Position TranslatePosition(NotificationPosition position)
        {
            switch (position)
            {
            case NotificationPosition.BottomRight:
                return(Position.BottomRight);

            case NotificationPosition.Bottom:
                return(Position.Bottom);

            case NotificationPosition.BottomLeft:
                return(Position.BottomLeft);

            case NotificationPosition.Left:
                return(Position.Left);

            case NotificationPosition.TopLeft:
                return(Position.TopLeft);

            case NotificationPosition.Top:
                return(Position.Top);

            case NotificationPosition.TopRight:
                return(Position.TopRight);

            case NotificationPosition.Right:
                return(Position.Right);

            default:
                throw new ArgumentOutOfRangeException(nameof(position), position, null);
            }
        }
예제 #4
0
        public static void ShowToastInformation(string message, NotificationPosition position)
        {
            Corner c = Corner.BottomLeft;

            switch (position)
            {
            case NotificationPosition.BottomCentre:
                c = Corner.BottomCenter;
                break;

            case NotificationPosition.BottomLeft:
                c = Corner.BottomLeft;
                break;

            case NotificationPosition.BottomRight:
                c = Corner.BottomRight;
                break;

            case NotificationPosition.TopLeft:
                c = Corner.TopLeft;
                break;

            case NotificationPosition.TopCenter:
                c = Corner.TopRight;
                break;
            }

            ShowToastInformation(message, true, c);
        }
예제 #5
0
 public void SetNotificationPosition(NotificationPosition position)
 {
     if(IsActive)
     {
         SteamAPI.SetNotificationPosition((SteamSDK.NotificationPosition)(int)position);
     }
 }
예제 #6
0
        private static string GetTargetPropFromPosition(this NotificationPosition pos)
        {
            switch (pos)
            {
            case NotificationPosition.TopRight:
                return("Y");

            case NotificationPosition.CenterRight:
                return("X");

            case NotificationPosition.BottomRight:
                return("Y");

            case NotificationPosition.BottomCenter:
                return("Y");

            case NotificationPosition.BottomLeft:
                return("Y");

            case NotificationPosition.CenterLeft:
                return("X");

            case NotificationPosition.TopLeft:
                return("Y");

            default:
                return("Y");
            }
        }
예제 #7
0
 internal static void SetNotificationPosition(NotificationPosition notificationPosition)
 {
     if (EnsureGameService())
     {
         m_gameServiceCache.SetNotificationPosition(notificationPosition);
     }
 }
예제 #8
0
        // el parametro de timer con valor 0 se deshabilita
        public void CustomNotification(string msj, NotificationType type, NotificationPosition position, string title = "", bool showConfirmButton = false, int timer = 2000, bool toast = true)
        {
            SetPosition(position.ToString());

            TempData["notification"] = "Swal.fire({customClass:{confirmButton:'btn btn-primary',cancelButton:'btn btn-danger'},position:'" + pos + "',type:'" + type.ToString().ToLower() +
                                       "',title:'" + title + "',text: '" + msj + "',showConfirmButton: " + showConfirmButton.ToString().ToLower() + ",confirmButtonColor: '#4F0DA2',toast: "
                                       + toast.ToString().ToLower() + ",timer: " + timer + "}); ";
        }
 public void UpdatePositioner(NotificationPosition position, int maxCount)
 {
     if (positioner == null)
     {
         positioner = new NotificationPositioner <ToastInfo>();
     }
     positioner.Update(screen.GetWorkingArea(currentScreenPosition), position, maxCount);
 }
예제 #10
0
            private void StreamSource(ISource aSource)
            {
                SendResponse("200 OK");

                iSocket.Send(iWavFileHeader);

                const int kAudioChunkBytes = 144 * 1024;
                const int kAudioChunks     = 4;

                CaptureBuffer capture = CreateCaptureBuffer(aSource, kAudioChunks * kAudioChunkBytes);

                int offset = 0;

                NotificationPosition[] notifications = new NotificationPosition[kAudioChunks];
                WaitHandle[]           handles       = new WaitHandle[kAudioChunks];

                for (uint i = 0; i < kAudioChunks; i++)
                {
                    NotificationPosition notification = new NotificationPosition();
                    notification.Offset = offset;
                    notification.Event  = new ManualResetEvent(false);
                    handles[i]          = notification.Event;
                    notifications[i]    = notification;
                    offset += kAudioChunkBytes;
                }

                capture.SetNotificationPositions(notifications);

                // Rotate notifications

                for (uint i = 0; i < kAudioChunks - 1; i++)
                {
                    WaitHandle a = handles[i];
                    handles[i]     = handles[i + 1];
                    handles[i + 1] = a;
                }

                byte[] audio = new byte[kAudioChunkBytes];

                capture.Start(true);

                try
                {
                    while (true)
                    {
                        int x = WaitHandle.WaitAny(handles);
                        ManualResetEvent manual = handles[x] as ManualResetEvent;
                        manual.Reset();
                        capture.Read <byte>(audio, 0, kAudioChunkBytes, notifications[x].Offset, false);
                        iSocket.Send(audio);
                    }
                }
                catch (SocketException)
                {
                }

                capture.Stop();
            }
        public static void UpdateAreaPosition(string areaName = "", NotificationPosition notificationPosition = NotificationPosition.BottomRight)
        {
            var area = Areas?.FirstOrDefault(a => a.Name == areaName);

            if (area != null)
            {
                area.Position = notificationPosition;
            }
        }
예제 #12
0
        public void run()
        {
            directSound = new DirectSound();


            IntPtr hwnd = GetDesktopWindow();

            // Set Cooperative Level to PRIORITY (priority level can call the SetFormat and Compact methods)
            directSound.SetCooperativeLevel(hwnd, CooperativeLevel.Priority);

            // Create PrimarySoundBuffer
            var primaryBufferDesc = new SoundBufferDescription();

            primaryBufferDesc.Flags          = BufferFlags.PrimaryBuffer;
            primaryBufferDesc.AlgorithmFor3D = Guid.Empty;

            primarySoundBuffer = new PrimarySoundBuffer(directSound, primaryBufferDesc);


            // Create SecondarySoundBuffer
            int soundLatencyInMilliseconds = 100;

            var secondaryBufferDesc = new SoundBufferDescription();

            secondaryBufferDesc.BufferBytes = soundStreamer.waveFormat.ConvertLatencyToByteSize(soundLatencyInMilliseconds);
            secondaryBufferDesc.Format      = soundStreamer.waveFormat;
            secondaryBufferDesc.Flags       = BufferFlags.GetCurrentPosition2 | BufferFlags.ControlPositionNotify | BufferFlags.GlobalFocus |
                                              BufferFlags.ControlVolume | BufferFlags.StickyFocus | BufferFlags.Trueplayposition;
            secondaryBufferDesc.AlgorithmFor3D = Guid.Empty;



            secondarySoundBuffer = new SecondarySoundBuffer(directSound, secondaryBufferDesc);



            NotificationPosition n = new NotificationPosition();

            n.Offset     = (secondaryBufferDesc.BufferBytes / 4) * 1;
            n.WaitHandle = soundStreamer.wait;

            NotificationPosition n2 = new NotificationPosition();

            n2.Offset     = (secondaryBufferDesc.BufferBytes / 4) * 3;
            n2.WaitHandle = soundStreamer.wait;

            secondarySoundBuffer.SetNotificationPositions(new NotificationPosition[] { n, n2 });

            soundStreamerThread = new Thread(soundStreamer.loop);
            soundStreamer.secondarySoundBuffer = secondarySoundBuffer;
            soundStreamerThread.Start();


            // play the sound
            secondarySoundBuffer.Play(0, PlayFlags.Looping);
        }
예제 #13
0
        public DXWavePlayer(int device, int BufferByteSize, DataRequestDelegate fillProc)
        {
            if (BufferByteSize < 1000)
            {
                throw new ArgumentOutOfRangeException("BufferByteSize", "minimal size of buffer is 1000 bytes");
            }

            _buffersize  = BufferByteSize;
            _requestproc = fillProc;
            var devices = DirectSound.GetDevices();

            if (device <= 0 || device >= devices.Count)
            {
                device = 0;
            }

            _outputDevice = new DirectSound(devices[device].DriverGuid);


            System.Windows.Interop.WindowInteropHelper wh = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow);
            _outputDevice.SetCooperativeLevel(wh.Handle, CooperativeLevel.Priority);

            _buffDescription             = new SoundBufferDescription();
            _buffDescription.Flags       = BufferFlags.ControlPositionNotify | BufferFlags.ControlFrequency | BufferFlags.ControlEffects | BufferFlags.GlobalFocus | BufferFlags.GetCurrentPosition2;
            _buffDescription.BufferBytes = BufferByteSize * InternalBufferSizeMultiplier;

            WaveFormat format = new WaveFormat(16000, 16, 1);

            _buffDescription.Format = format;

            _soundBuffer  = new SecondarySoundBuffer(_outputDevice, _buffDescription);
            _synchronizer = new AutoResetEvent(false);

            NotificationPosition[] nots = new NotificationPosition[InternalBufferSizeMultiplier];

            NotificationPosition not;
            int bytepos = 800;

            for (int i = 0; i < InternalBufferSizeMultiplier; i++)
            {
                not            = new NotificationPosition();
                not.Offset     = bytepos;
                not.WaitHandle = _synchronizer;
                nots[i]        = not;
                bytepos       += BufferByteSize;
            }

            _soundBuffer.SetNotificationPositions(nots);


            _waitThread = new Thread(new ThreadStart(DataRequestThread))
            {
                Name = "MyWavePlayer.DataRequestThread"
            };
            _waitThread.Start();
        }
예제 #14
0
        public void Start()
        {
            if (_Running)
            {
                throw new InvalidOperationException();
            }

            if (_CaptureDevice == null)
            {
                _CaptureDevice = new DirectSoundCapture(new Guid(_Guid));
            }

            _WaveFormat.FormatTag             = WaveFormatTag.Pcm; // Change to WaveFormatTag.IeeeFloat for float
            _WaveFormat.BitsPerSample         = 16;                // Set this to 32 for float
            _WaveFormat.BlockAlignment        = (short)(_Channels * (_WaveFormat.BitsPerSample / 8));
            _WaveFormat.Channels              = _Channels;
            _WaveFormat.SamplesPerSecond      = (int)(SampleRateKhz * 1000D);
            _WaveFormat.AverageBytesPerSecond =
                _WaveFormat.SamplesPerSecond *
                _WaveFormat.BlockAlignment;

            _BufferPortionCount = 2;

            _BufferDescription.BufferBytes = _BufferSize * sizeof(short) * _BufferPortionCount * _Channels;
            _BufferDescription.Format      = _WaveFormat;
            _BufferDescription.WaveMapped  = false;

            _CaptureBuffer = new CaptureBuffer(_CaptureDevice, _BufferDescription);

            _BufferPortionSize = _CaptureBuffer.SizeInBytes / _BufferPortionCount;
            _Notifications     = new List <NotificationPosition>();

            for (int i = 0; i < _BufferPortionCount; i++)
            {
                var notification = new NotificationPosition {
                    Offset = _BufferPortionCount - 1 + (_BufferPortionSize * i), Event = new AutoResetEvent(false)
                };
                _Notifications.Add(notification);
            }

            _CaptureBuffer.SetNotificationPositions(_Notifications.ToArray());
            _WaitHandles = new WaitHandle[_Notifications.Count];

            for (int i = 0; i < _Notifications.Count; i++)
            {
                _WaitHandles[i] = _Notifications[i].Event;
            }

            _CaptureThread = new Thread(_DoCapture)
            {
                Name = "DirectSoundCapture", IsBackground = true
            };

            _Running = true;
            _CaptureThread.Start();
        }
예제 #15
0
        public void Alert(string message, NotificationPosition position, NotificationType notificationType)
        {
            var msg = "toastr." + notificationType + "('" + message + "')";

            TempData["notification"] = msg;

            var positions = new ClientNotifications.Helpers.NotificationHelper().position();

            TempData["options"] = JsonConvert.SerializeObject(new{ positionClass = positions[position] });
        }
예제 #16
0
        public void Play()
        {
            pos        = new NotificationPosition();
            pos.Offset = BufferSize - 1;
            pos.Event  = new AutoResetEvent(false);

            CurrentBuffer.SetNotificationPositions(new NotificationPosition[] { pos });

            CurrentBuffer.Play(0, PlayFlags.None);
        }
예제 #17
0
        private static void SetWindowPosition(NotificationPosition position)
        {
            double left         = 0;
            double top          = 0;
            double margin       = 10;
            double screenWidth  = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            double screenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            double windowWidth  = _window.Width;
            double windowHeight = _window.Height;

            switch (position)
            {
            case NotificationPosition.CenterBottom:
            case NotificationPosition.CenterMidle:
            case NotificationPosition.CenterTop:
                left = (screenWidth - windowWidth) / 2;
                break;

            case NotificationPosition.LeftBottom:
            case NotificationPosition.LeftMidle:
            case NotificationPosition.LeftTop:
                left = margin;
                break;

            case NotificationPosition.RightBottom:
            case NotificationPosition.RightMidle:
            case NotificationPosition.RightTop:
                left = (screenWidth - windowWidth) - margin;
                break;
            }

            switch (position)
            {
            case NotificationPosition.CenterTop:
            case NotificationPosition.LeftTop:
            case NotificationPosition.RightTop:
                top = margin;
                break;

            case NotificationPosition.CenterMidle:
            case NotificationPosition.LeftMidle:
            case NotificationPosition.RightMidle:
                top = (screenHeight - windowHeight) / 2;
                break;

            case NotificationPosition.CenterBottom:
            case NotificationPosition.LeftBottom:
            case NotificationPosition.RightBottom:
                top = (screenHeight - windowHeight) - margin;
                break;
            }

            _window.Left = left;
            _window.Top  = top;
        }
예제 #18
0
            public void Start()
            {
                if (this.running)
                {
                    throw new InvalidOperationException();
                }

                if (this.captureDevice == null)
                {
                    this.captureDevice = new DirectSoundCapture(guid);
                }

                this.waveFormat.FormatTag             = WaveFormatTag.Pcm; // Change to WaveFormatTag.IeeeFloat for float
                this.waveFormat.BitsPerSample         = 16;                // Set this to 32 for float
                this.waveFormat.BlockAlignment        = (short)(channels * (waveFormat.BitsPerSample / 8));
                this.waveFormat.Channels              = this.channels;
                this.waveFormat.SamplesPerSecond      = (int)(this.SampleRateKHz * 1000D);
                this.waveFormat.AverageBytesPerSecond =
                    this.waveFormat.SamplesPerSecond *
                    this.waveFormat.BlockAlignment;

                this.bufferPortionCount = 2;

                this.bufferDescription.BufferBytes = this.bufferSize * sizeof(short) * bufferPortionCount * this.channels;
                this.bufferDescription.Format      = this.waveFormat;
                this.bufferDescription.WaveMapped  = false;

                this.buffer = new CaptureBuffer(this.captureDevice, this.bufferDescription);

                this.bufferPortionSize = this.buffer.SizeInBytes / this.bufferPortionCount;
                this.notifications     = new List <NotificationPosition>();

                for (int i = 0; i < this.bufferPortionCount; i++)
                {
                    NotificationPosition notification = new NotificationPosition();
                    notification.Offset = this.bufferPortionCount - 1 + (bufferPortionSize * i);
                    notification.Event  = new AutoResetEvent(false);
                    this.notifications.Add(notification);
                }

                this.buffer.SetNotificationPositions(this.notifications.ToArray());
                this.waitHandles = new WaitHandle[this.notifications.Count];

                for (int i = 0; i < this.notifications.Count; i++)
                {
                    this.waitHandles[i] = this.notifications[i].Event;
                }

                this.captureThread = new Thread(new ThreadStart(this.CaptureThread));
                this.captureThread.IsBackground = true;

                this.running = true;
                this.captureThread.Start();
            }
        /// <summary>
        /// Creates an instance of the <see cref="NotificationManager"/>
        /// </summary>
        /// <param name="mainNotificationPosition">The position where notifications with no custom area should
        /// be displayed</param>
        /// <param name="dispatcher">The <see cref="Dispatcher"/> that should be used</param>
        public NotificationManager(NotificationPosition mainNotificationPosition,
                                   Dispatcher?dispatcher)
        {
            _mainNotificationPosition = mainNotificationPosition;

            if (dispatcher == null)
            {
                dispatcher = Application.Current?.Dispatcher ?? Dispatcher.CurrentDispatcher;
            }

            _dispatcher = dispatcher;
        }
예제 #20
0
        private static Grid ModifyGridByPosition(this Grid grid, NotificationPosition pos)
        {
            int pad = 10;

            switch (pos)
            {
            case NotificationPosition.TopRight:
                grid.VerticalAlignment   = VerticalAlignment.Top;
                grid.HorizontalAlignment = HorizontalAlignment.Right;
                grid.Margin = new Thickness(0, YOffset.Negate(), pad, 0);
                break;

            case NotificationPosition.CenterRight:
                grid.VerticalAlignment   = VerticalAlignment.Center;
                grid.HorizontalAlignment = HorizontalAlignment.Right;
                break;

            case NotificationPosition.BottomRight:
                grid.VerticalAlignment   = VerticalAlignment.Bottom;
                grid.HorizontalAlignment = HorizontalAlignment.Right;
                grid.Margin = new Thickness(0, 0, pad, YOffset.Negate());
                break;

            case NotificationPosition.BottomCenter:
                grid.VerticalAlignment   = VerticalAlignment.Bottom;
                grid.HorizontalAlignment = HorizontalAlignment.Center;
                grid.Margin = new Thickness(0, 0, 0, YOffset.Negate());
                break;

            case NotificationPosition.BottomLeft:
                grid.VerticalAlignment   = VerticalAlignment.Bottom;
                grid.HorizontalAlignment = HorizontalAlignment.Left;
                grid.Margin = new Thickness(pad, 0, 0, YOffset.Negate());
                break;

            case NotificationPosition.CenterLeft:
                grid.VerticalAlignment   = VerticalAlignment.Center;
                grid.HorizontalAlignment = HorizontalAlignment.Left;
                grid.Margin = new Thickness(0);
                break;

            case NotificationPosition.TopLeft:
                grid.VerticalAlignment   = VerticalAlignment.Top;
                grid.HorizontalAlignment = HorizontalAlignment.Left;
                grid.Margin = new Thickness(pad, YOffset.Negate(), 0, 0);
                break;

            default:
                break;
            }
            return(grid);
        }
 private void Update(object sender, RoutedEventArgs e)
 {
     int ret = 0;
     foreach (RadioButton rb in SelectorGrid.Children)
     {
         if (rb.IsChecked == true)
         {
             ret = Convert.ToInt32(rb.Tag);
             break;
         }
     }
     Position = (NotificationPosition)ret;
 }
예제 #22
0
        private static Grid GetGrid(string name, NotificationPosition pos, NotificationType type, string txt)
        {
            var grid = new Grid
            {
                Name = name,
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin     = new Thickness(0),
                Visibility = Visibility.Visible
            }.ModifyGridByPosition(pos);

            grid.Children.Add(GetStackPanel(type, txt));
            return(grid);
        }
예제 #23
0
 public static void SetNotification(bool Visible, string Text, NotificationPosition Position)
 {
     if (IsRegistered)
     {
         using (var parameters = new Parameters())
         {
             APICall(parameters
                     .AddInt((int)Function.SetNotification)
                     .AddInt((int)Id)
                     .AddInt((int)(Visible ? 1 : 0))
                     .AddString(Text)
                     .AddInt((int)Position));
         }
     }
 }
예제 #24
0
        public AudioCapture()
        {
            try
            {
                directSoundCapture = new DirectSoundCapture();
            }
            catch
            {
                throw new AudioCaptureException("Could not open recording device");
            }
            //var directSoundCaps = directSoundCapture.Capabilities;

            // Default 44.1kHz 16-bit stereo PCM
            waveFormat = new WaveFormat();

            // Set the buffer size.
            // Note that the buffer position will roll over to 0 when the buffer fills up,
            // so set the notification position's offset to one less than the buffer size.
            bufferSize      = waveFormat.ConvertLatencyToByteSize(latency);
            numberOfSamples = bufferSize / waveFormat.BlockAlign;

            // Create audio capture buffer
            captureBufferDesc             = new CaptureBufferDescription();
            captureBufferDesc.Format      = waveFormat;
            captureBufferDesc.BufferBytes = bufferSize;
            captureBuffer = new CaptureBuffer(directSoundCapture, captureBufferDesc);

            // Wait events allow the thread to wait asynchronously for the buffer to fill
            var evt = new AutoResetEvent(false);

            fullEvent = new WaitHandle[] { evt };

            // Notify the thread when the buffer is full
            var nf = new NotificationPosition();

            nf.Offset     = bufferSize - 1;
            nf.WaitHandle = fullEvent[0];
            var nfs = new NotificationPosition[] { nf };

            captureBuffer.SetNotificationPositions(nfs);

            // Start the processing thread
            thread = new Thread(new ThreadStart(Process));
            thread.IsBackground = true; // Allow application to exit
            thread.Start();
        }
        public void Update(Rect screen, NotificationPosition position, int maxCount)
        {
            if (this.screen == screen && this.position == position && this.maxCount == maxCount)
            {
                return;
            }
            this.screen   = screen;
            this.position = position;
            this.maxCount = maxCount;
            List <ItemInfo> visible = CloneItemsCollection().Where(i => i != null).ToList();

            items.Clear();
            foreach (ItemInfo info in visible)
            {
                Add(info.value, info.size.Width, info.size.Height);
            }
        }
예제 #26
0
        public DxPlaySound(int frequency)
        {
            device = new DirectSound();                                              //音频设备对象

            IntPtr hwnd = new WindowInteropHelper(DisPlayWindow.HMainWindow).Handle; //设置窗口句柄

            device.SetCooperativeLevel(hwnd, CooperativeLevel.Priority);

            //设置Wav音频文件对象属性
            WaveFormat waveformat = SetWaveFormat(frequency);

            //设置通知对象
            mNotifySize = waveformat.AverageBytesPerSecond / 5;        //0.2S数据
            int mainBufferSize = waveformat.AverageBytesPerSecond * 2; //  2s数据长度

            cNotifyNum = mainBufferSize / mNotifySize;                 //通知个数 10 == 2s/0.2s

            //设置主缓存区
            SoundBufferDescription sndBufferDesc = new SoundBufferDescription
            {
                SizeInBytes = mainBufferSize,
                Format      = waveformat,
                Flags       = BufferFlags.ControlPositionNotify | BufferFlags.ControlFrequency | BufferFlags.GlobalFocus | BufferFlags.GetCurrentPosition2
            };

            scdBuffer = new SecondarySoundBuffer(device, sndBufferDesc); //为声音建立二级缓存

            if (scdBuffer != null)
            {
                mNotificationEvent = new AutoResetEvent(false);
                isRunning          = true;
                Task.Factory.StartNew(NotifyThread);
                NotificationPosition[] positionNotify = new NotificationPosition[cNotifyNum]; //通知数组
                for (int i = 0; i < cNotifyNum; i++)
                {
                    positionNotify[i].Offset = mNotifySize * (i + 1) - 1;
                    positionNotify[i].Event  = mNotificationEvent;
                }
                scdBuffer.SetNotificationPositions(positionNotify);
            }
        }
예제 #27
0
        public override void Start()
        {
            if (this.isCapturing)
            {
                throw new InvalidOperationException("Capture is in process");
            }

            this.isCapturing  = true;
            this.bufferLength = this.Format.AverageBytesPerSecond * bufferSeconds;

            CaptureBufferDescription desciption = new CaptureBufferDescription();

            desciption.Format      = this.Format;
            desciption.BufferBytes = bufferLength;

            this.captureDevice = new DirectSoundCapture();
            this.captureBuffer = new CaptureBuffer(captureDevice, desciption);

            int waitHandleCount = bufferSeconds * notifyPointsInSecond;

            NotificationPosition[] notificationPositions = new NotificationPosition[waitHandleCount];

            for (int i = 0; i < waitHandleCount; i++)
            {
                NotificationPosition position = new NotificationPosition();
                position.Offset = (i + 1) * bufferLength / notificationPositions.Length - 1;
                position.Event  = positionEvent;

                notificationPositions[i] = position;
            }

            this.captureBuffer.SetNotificationPositions(notificationPositions);

            this.terminatedEvent.Reset();
            this.captureThread      = new Thread(new ThreadStart(this.CaptureLoop));
            this.captureThread.Name = "Sound capture";
            this.captureThread.Start();
        }
예제 #28
0
        /// <summary>
        ///   Worker thread.
        /// </summary>
        ///
        private void WorkerThread()
        {
            // Get the selected capture device
            DirectSoundCapture captureDevice = new DirectSoundCapture(device);


            // Set the capture format
            WaveFormat format = new WaveFormat();

            format.Channels              = 1;
            format.SamplesPerSecond      = sampleRate;
            format.FormatTag             = sampleFormat.ToWaveFormat();
            format.BitsPerSample         = (short)Signal.GetSampleSize(sampleFormat);
            format.BlockAlignment        = (short)(format.BitsPerSample / 8);
            format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlignment;

            // Setup the capture buffer
            CaptureBufferDescription captureBufferDescription = new CaptureBufferDescription();

            captureBufferDescription.Format         = format;
            captureBufferDescription.BufferBytes    = 2 * desiredCaptureSize * format.BlockAlignment;
            captureBufferDescription.WaveMapped     = true;
            captureBufferDescription.ControlEffects = false;

            CaptureBuffer captureBuffer = null;

            NotificationPosition[] notifications = new NotificationPosition[2];

            try
            {
                captureBuffer = new CaptureBuffer(captureDevice, captureBufferDescription);

                // Setup the notification positions
                int bufferPortionSize = captureBuffer.SizeInBytes / 2;
                notifications[0]        = new NotificationPosition();
                notifications[0].Offset = bufferPortionSize - 1;
                notifications[0].Event  = new AutoResetEvent(false);
                notifications[1]        = new NotificationPosition();
                notifications[1].Offset = bufferPortionSize - 1 + bufferPortionSize;
                notifications[1].Event  = new AutoResetEvent(false);
                captureBuffer.SetNotificationPositions(notifications);

                // Make a copy of the wait handles
                WaitHandle[] waitHandles = new WaitHandle[notifications.Length];
                for (int i = 0; i < notifications.Length; i++)
                {
                    waitHandles[i] = notifications[i].Event;
                }



                // Start capturing
                captureBuffer.Start(true);


                if (sampleFormat == SampleFormat.Format32BitIeeeFloat)
                {
                    float[] currentSample = new float[desiredCaptureSize];

                    while (!stopEvent.WaitOne(0, true))
                    {
                        int bufferPortionIndex = WaitHandle.WaitAny(waitHandles);
                        captureBuffer.Read(currentSample, 0, currentSample.Length, bufferPortionSize * bufferPortionIndex);
                        OnNewFrame(currentSample);
                    }
                }
                else if (sampleFormat == SampleFormat.Format16Bit)
                {
                    short[] currentSample = new short[desiredCaptureSize];

                    while (!stopEvent.WaitOne(0, true))
                    {
                        int bufferPortionIndex = WaitHandle.WaitAny(waitHandles);
                        captureBuffer.Read(currentSample, 0, currentSample.Length, bufferPortionSize * bufferPortionIndex);
                        OnNewFrame(currentSample);
                    }
                }
            }
            catch (Exception ex)
            {
                if (AudioSourceError != null)
                {
                    AudioSourceError(this, new AudioSourceErrorEventArgs(ex.Message));
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                if (captureBuffer != null)
                {
                    captureBuffer.Stop();
                    captureBuffer.Dispose();
                }

                if (captureDevice != null)
                {
                    captureDevice.Dispose();
                }

                for (int i = 0; i < notifications.Length; i++)
                {
                    if (notifications[i].Event != null)
                    {
                        notifications[i].Event.Close();
                    }
                }
            }
        }
예제 #29
0
        public NotificationWindow(TrackViewModel track, byte[] artworkData, NotificationPosition position, bool showControls, int maxSecondsVisible) : base()
        {
            this.InitializeComponent();

            this.maxSecondsVisible = maxSecondsVisible;

            int notificationHeight = 66 + 2 * this.notificationShadowSize;
            int notificationWidth  = 286 + 2 * this.notificationShadowSize;

            if (showControls)
            {
                notificationHeight           += 40;
                notificationWidth            += 90;
                this.ControlsPanel.Visibility = Visibility.Visible;
                this.VolumePanel.Visibility   = Visibility.Visible;
            }
            else
            {
                this.ControlsPanel.Visibility = Visibility.Collapsed;
                this.VolumePanel.Visibility   = Visibility.Collapsed;
            }

            if (track != null)
            {
                this.TextBoxTitle.Text  = string.IsNullOrEmpty(track.TrackTitle) ? track.FileName : track.TrackTitle;
                this.TextBoxArtist.Text = track.ArtistName;
            }
            else
            {
                this.TextBoxTitle.Text  = ResourceUtils.GetString("Language_Title");
                this.TextBoxArtist.Text = ResourceUtils.GetString("Language_Artist");
            }

            this.ToolTipTitle.Text  = this.TextBoxTitle.Text;
            this.ToolTipArtist.Text = this.TextBoxArtist.Text;

            if (artworkData != null)
            {
                try
                {
                    // Width and Height are 300px. They need to be big enough, otherwise the picture is blurry
                    this.CoverPicture.Source = ImageUtils.ByteToBitmapImage(artworkData, 300, 300, 0);
                    this.CloseBorder.Opacity = 1.0;
                }
                catch (Exception)
                {
                    // Swallow
                }
            }
            else
            {
                this.CloseBorder.Opacity = 0.4;
            }


            Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
            {
                Rect desktopWorkingArea = System.Windows.SystemParameters.WorkArea;

                // First, set the position
                switch (position)
                {
                case NotificationPosition.BottomLeft:
                    // Bottom left
                    this.Left = desktopWorkingArea.Left + this.notificationMarginFromScreen;
                    this.Top  = desktopWorkingArea.Bottom - notificationHeight - this.notificationMarginFromScreen;
                    break;

                case NotificationPosition.TopLeft:
                    // Top left
                    this.Left = desktopWorkingArea.Left + this.notificationMarginFromScreen;
                    this.Top  = desktopWorkingArea.Top + this.notificationMarginFromScreen;
                    break;

                case NotificationPosition.TopRight:
                    // Top right
                    this.Left = desktopWorkingArea.Right - notificationWidth - this.notificationMarginFromScreen;
                    this.Top  = desktopWorkingArea.Top + this.notificationMarginFromScreen;
                    break;

                case NotificationPosition.BottomRight:
                    // Bottom right
                    this.Left = desktopWorkingArea.Right - notificationWidth - this.notificationMarginFromScreen;
                    this.Top  = desktopWorkingArea.Bottom - notificationHeight - this.notificationMarginFromScreen;
                    break;

                default:
                    break;
                }

                // After setting the position, set the size. The original size op 0px*0px prevents
                // flicker when displaying the popup. Because it briefly appears in the top left
                // corner before getting its desired position.
                this.Width               = notificationWidth;
                this.Height              = notificationHeight;
                this.CoverPicture.Width  = notificationHeight - 2 * this.notificationShadowSize;
                this.CoverPicture.Height = notificationHeight - 2 * this.notificationShadowSize;
                this.CoverTile.Width     = notificationHeight - 2 * this.notificationShadowSize;
                this.CoverTile.Height    = notificationHeight - 2 * this.notificationShadowSize;
            }));

            this.hideTimer.Interval  = TimeSpan.FromSeconds(1);
            this.closeTimer.Interval = TimeSpan.FromSeconds(1);
            this.hideTimer.Tick     += new EventHandler(HideTimer_Tick);
            this.closeTimer.Tick    += new EventHandler(CloseTimer_Tick);
        }
예제 #30
0
 // void
 public void SetOverlayNotificationPosition(NotificationPosition eNotificationPosition /*ENotificationPosition*/)
 {
     platform.ISteamUtils_SetOverlayNotificationPosition(eNotificationPosition);
 }
예제 #31
0
 internal void SetOverlayNotificationPosition(NotificationPosition eNotificationPosition)
 {
     _SetOverlayNotificationPosition(Self, eNotificationPosition);
 }
예제 #32
0
        /// <summary>
        ///   Worker thread.
        /// </summary>
        /// 
        private void WorkerThread()
        {
            // Get the selected capture device
            DirectSoundCapture captureDevice = new DirectSoundCapture(device);


            // Set the capture format
            WaveFormat format = new WaveFormat();
            format.Channels = 1;
            format.SamplesPerSecond = sampleRate;
            format.FormatTag = sampleFormat.ToWaveFormat();
            format.BitsPerSample = (short)Signal.GetSampleSize(sampleFormat);
            format.BlockAlignment = (short)(format.BitsPerSample / 8);
            format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlignment;

            // Setup the capture buffer
            CaptureBufferDescription captureBufferDescription = new CaptureBufferDescription();
            captureBufferDescription.Format = format;
            captureBufferDescription.BufferBytes = 2 * desiredCaptureSize * format.BlockAlignment;
            captureBufferDescription.WaveMapped = true;
            captureBufferDescription.ControlEffects = false;

            CaptureBuffer captureBuffer = null;
            NotificationPosition[] notifications = new NotificationPosition[2];

            try
            {
                captureBuffer = new CaptureBuffer(captureDevice, captureBufferDescription);

                // Setup the notification positions
                int bufferPortionSize = captureBuffer.SizeInBytes / 2;
                notifications[0] = new NotificationPosition();
                notifications[0].Offset = bufferPortionSize - 1;
                notifications[0].Event = new AutoResetEvent(false);
                notifications[1] = new NotificationPosition();
                notifications[1].Offset = bufferPortionSize - 1 + bufferPortionSize;
                notifications[1].Event = new AutoResetEvent(false);
                captureBuffer.SetNotificationPositions(notifications);

                // Make a copy of the wait handles
                WaitHandle[] waitHandles = new WaitHandle[notifications.Length];
                for (int i = 0; i < notifications.Length; i++)
                    waitHandles[i] = notifications[i].Event;



                // Start capturing
                captureBuffer.Start(true);


                if (sampleFormat == SampleFormat.Format32BitIeeeFloat)
                {
                    float[] currentSample = new float[desiredCaptureSize];

                    while (!stopEvent.WaitOne(0, true))
                    {
                        int bufferPortionIndex = WaitHandle.WaitAny(waitHandles);
                        captureBuffer.Read(currentSample, 0, currentSample.Length, bufferPortionSize * bufferPortionIndex);
                        OnNewFrame(currentSample);
                    }
                }
                else if (sampleFormat == SampleFormat.Format16Bit)
                {
                    short[] currentSample = new short[desiredCaptureSize];

                    while (!stopEvent.WaitOne(0, true))
                    {
                        int bufferPortionIndex = WaitHandle.WaitAny(waitHandles);
                        captureBuffer.Read(currentSample, 0, currentSample.Length, bufferPortionSize * bufferPortionIndex);
                        OnNewFrame(currentSample);
                    }
                }
            }
            catch (Exception ex)
            {
                if (AudioSourceError != null)
                    AudioSourceError(this, new AudioSourceErrorEventArgs(ex.Message));
                else throw;
            }
            finally
            {
                if (captureBuffer != null)
                {
                    captureBuffer.Stop();
                    captureBuffer.Dispose();
                }

                if (captureDevice != null)
                    captureDevice.Dispose();

                for (int i = 0; i < notifications.Length; i++)
                    if (notifications[i].Event != null)
                        notifications[i].Event.Close();
            }
        }
예제 #33
0
 public static void ShowNotification(string Text, NotificationPosition Position)
 {
     SetNotification(true, Text, Position);
 }
예제 #34
0
 public static void HideNotification(NotificationPosition Position)
 {
     SetNotification(false, null, Position);
 }
예제 #35
0
  public unsafe void SetNotificationPosition(NotificationPosition position)
  {
      // TODO [vicent] current stub implementation
      return;
 //     ISteamUtils* this2 = <Module>.SteamUtils();
 //     calli(System.Void modopt(System.Runtime.CompilerServices.CallConvCdecl)(System.IntPtr,ENotificationPosition), this2, position, *(*(long*)this2 + 80L));
  }
예제 #36
0
            public void Start()
            {
                if (this.running)
                {
                    throw new InvalidOperationException();
                }

                if (this.captureDevice == null)
                {
                    this.captureDevice = new DirectSoundCapture(guid);
                }

                this.waveFormat.FormatTag = WaveFormatTag.Pcm; // Change to WaveFormatTag.IeeeFloat for float
                this.waveFormat.BitsPerSample = 16; // Set this to 32 for float
                this.waveFormat.BlockAlignment = (short)(channels * (waveFormat.BitsPerSample / 8));
                this.waveFormat.Channels = this.channels;
                this.waveFormat.SamplesPerSecond = (int)(this.SampleRateKHz * 1000D);
                this.waveFormat.AverageBytesPerSecond =
                    this.waveFormat.SamplesPerSecond *
                    this.waveFormat.BlockAlignment;

                this.bufferPortionCount = 2;

                this.bufferDescription.BufferBytes = this.bufferSize * sizeof(short) * bufferPortionCount * this.channels;
                this.bufferDescription.Format = this.waveFormat;
                this.bufferDescription.WaveMapped = false;

                this.buffer = new CaptureBuffer(this.captureDevice, this.bufferDescription);

                this.bufferPortionSize = this.buffer.SizeInBytes / this.bufferPortionCount;
                this.notifications = new List<NotificationPosition>();

                for (int i = 0; i < this.bufferPortionCount; i++)
                {
                    NotificationPosition notification = new NotificationPosition();
                    notification.Offset = this.bufferPortionCount - 1 + (bufferPortionSize * i);
                    notification.Event = new AutoResetEvent(false);
                    this.notifications.Add(notification);
                }

                this.buffer.SetNotificationPositions(this.notifications.ToArray());
                this.waitHandles = new WaitHandle[this.notifications.Count];

                for (int i = 0; i < this.notifications.Count; i++)
                {
                    this.waitHandles[i] = this.notifications[i].Event;
                }

                this.captureThread = new Thread(new ThreadStart(this.CaptureThread));
                this.captureThread.IsBackground = true;

                this.running = true;
                this.captureThread.Start();
            }
예제 #37
0
 public static void SetNotification(bool Visible, string Text, NotificationPosition Position)
 {
     if (IsRegistered)
     {
         using (var parameters = new Parameters())
         {
             APICall(parameters
                 .AddInt((int)Function.SetNotification)
                 .AddInt((int)Id)
                 .AddInt((int)(Visible ? 1 : 0))
                 .AddString(Text)
                 .AddInt((int)Position));
         }
     }
 }