Example #1
0
 public void Stop()
 {
     SoundOutManager.Stop();
     _panSource = null;
     _source    = null;
     RaiseUpdated();
 }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            isMouseDown = false;

            if (interactionState == InteractionState.Selection)
            {
                selectedElements = GetElementsByRectangle(SelectionRectangle);
                interactionState = InteractionState.None;
                Cursor           = Cursors.Default;
            }
            else if (interactionState == InteractionState.Pan)
            {
                if (panSource == PanSource.Mouse)
                {
                    interactionState = InteractionState.None;
                    panSource        = PanSource.None;
                    Cursor           = Cursors.Default;
                }
                else if (panSource == PanSource.Keyboard)
                {
                    Cursor = CursorHelper.LoadFromResource(Properties.Resources.grab);
                }
            }
            else
            {
                interactionState = InteractionState.None;
                Cursor           = Cursors.Default;
            }

            Refresh();
        }
        /// <summary>
        /// Plays the sound.
        /// </summary>
        /// <param name="source">The WaveSource.</param>
        private void Play(IWaveSource source)
        {
            Stop();
            var panSource = new PanSource(source);

            _panSource = panSource;
            _directSoundOut.Initialize(panSource.ToWaveSource());
            _directSoundOut.Play();
        }
Example #4
0
        private async Task <bool> HandlePan(PanSource panSource, double panDelta)
        {
            // Stop the kinetic scrolling while the finger is on the screen
            if (panSource != PanSource.KineticScroll)
            {
                _bottomViewContainer.AbortAnimation(KineticScrollAnimationName);
            }

            if (_bottomViewContainer.ScrollY >= 0.0d && _bottomViewPanDirection == Direction.up && _proportionalTopViewHeight <= _proportionalTopViewHeightMin)
            {
                var bottomViewScrollY = _bottomViewContainer.ScrollY + (-panDelta);

                bottomViewScrollY = Clamp(bottomViewScrollY, 0.0d, _bottomViewContainer.Content.Height - _bottomViewContainer.Height);
                DebugWriteLine($"Scrolling up to: {bottomViewScrollY}");
                await _bottomViewContainer.ScrollToAsync(0.0d, bottomViewScrollY, false);

                return(true);
            }
            else if (_bottomViewContainer.ScrollY > 0.0d && _bottomViewPanDirection == Direction.down && _proportionalTopViewHeight <= _proportionalTopViewHeightMin)
            {
                var bottomViewScrollY = _bottomViewContainer.ScrollY + (-panDelta);

                bottomViewScrollY = Clamp(bottomViewScrollY, 0.0d, _bottomViewContainer.Content.Height - _bottomViewContainer.Height);
                DebugWriteLine($"Scrolling down to: {bottomViewScrollY}");
                await _bottomViewContainer.ScrollToAsync(0.0d, bottomViewScrollY, false);

                return(true);
            }
            else
            {
                // Don't increase if already at maximum && don't decrease if already at minimum
                if (panDelta > 0.0d && _proportionalTopViewHeight >= _proportionalTopViewHeightMax ||
                    panDelta < 0.0d && _proportionalTopViewHeight <= _proportionalTopViewHeightMin)
                {
                    return(false);
                }

                // Don't expand/collapse during kinetic scrolling if not desired
                if (panSource == PanSource.KineticScroll && !ShouldExpandFromKineticScroll)
                {
                    return(false);
                }

                DebugWriteLine($"Panning {_bottomViewPanDirection} to {_panTotal}");
                _panTotal += panDelta;
                _relativeLayout.ForceLayout();

                return(true);
            }
        }
Example #5
0
        /// <summary>
        /// Plays the wave source.
        /// </summary>
        /// <param name="waveSource">The WaveSource.</param>
        internal void Play(IWaveSource waveSource)
        {
            var panSource = new PanSource(waveSource);

            _panSource         = panSource;
            _currentWaveSource = panSource.ToWaveSource();
            _sourceVoice       = StreamingSourceVoice.Create(_xaudio2, _currentWaveSource);
            StreamingSourceVoiceListener.Default.Add(_sourceVoice);
            _playbackState = PlaybackState.Playing;
            IsPlaying      = true;
            if (PlaybackChanged != null)
            {
                PlaybackChanged(this, EventArgs.Empty);
            }
        }
        protected override void OnKeyUp(KeyEventArgs e)
        {
            base.OnKeyUp(e);

            if (e.KeyData == Keys.Space)
            {
                if (interactionState == InteractionState.Pan)
                {
                    interactionState = InteractionState.None;
                    panSource        = PanSource.None;
                    Cursor           = Cursors.Default;
                    Refresh();
                }
            }
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.KeyData == Keys.Space)
            {
                if (interactionState == InteractionState.None)
                {
                    interactionState = InteractionState.Pan;
                    panSource        = PanSource.Keyboard;
                    Cursor           = CursorHelper.LoadFromResource(Properties.Resources.grab);
                    Refresh();
                }
            }
        }
Example #8
0
        public bool OpenFile(string filename, Func <IWaveSource, IWaveSource> oninitcallback)
        {
            if (String.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentException("filename");
            }

            try
            {
                var source = CodecFactory.Instance.GetCodec(filename);
                source = new LoopStream(source);
                (source as LoopStream).EnableLoop = false;

                if (source.WaveFormat.Channels == 1)
                {
                    source = new MonoToStereoSource(source).ToWaveSource(16);
                }
                _panSource = new PanSource(source)
                {
                    Pan = this.Pan
                };
                var _notification = new SimpleNotificationSource(_panSource);
                _notification.DataRead += OnNotification;

                source = _notification.ToWaveSource(16);
                //source = new BufferSource(source, source.WaveFormat.BytesPerSecond * 2);

                _source = source;

                if (oninitcallback != null)
                {
                    SoundOutManager.Initialize(oninitcallback(source));
                }
                else
                {
                    SoundOutManager.Initialize(source);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            RaiseUpdated();
            return(true);
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            controlMouseDownLocation = e.Location;

            isMouseDown = true;

            bool needsRefresh = false;

            mouseHitsSelection = false;

            if (e.Button == MouseButtons.Left)
            {
                // resize
                if (interactionState == InteractionState.None && selectedElements != null && selectedElements.Count == 1)
                {
                    LayoutProperties layoutProperties = new LayoutProperties();
                    layoutProperties.DesignAreaLocation = DesignAreaLocation;
                    layoutProperties.DesignAreaSize     = DesignAreaSize;
                    layoutProperties.ViewportLocation   = ViewportLocation;
                    layoutProperties.ViewportSize       = ViewportSize;
                    layoutProperties.ZoomRatio          = ZoomRatio;

                    foreach (LayoutElement selectedElement in selectedElements)
                    {
                        TransformHandle transformHandle = DesignerHelper.GetTransformHandleType(selectedElement, layoutProperties, e.Location);
                        if (transformHandle != TransformHandle.None)
                        {
                            this.transformHandle = transformHandle;
                            interactionState     = InteractionState.SizeAttempt;
                            needsRefresh         = true;
                        }
                    }
                }

                // click selection
                if (interactionState == InteractionState.None)
                {
                    LayoutElement element = GetElementByLocation(controlMouseDownLocation);
                    if (element != null)
                    {
                        mouseHitsSelection = true;

                        if (KeyboardHelper.IsShiftKeyPressed)
                        {
                            if (!IsElementInSelection(element))
                            {
                                AddElementToSelection(element);
                            }
                            else
                            {
                                RemoveElementFromSelection(element);
                            }
                        }
                        else
                        {
                            if (!IsElementInSelection(element))
                            {
                                ClearSelection();
                                AddElementToSelection(element);
                            }
                        }

                        needsRefresh = true;
                    }
                    else
                    {
                        if (!KeyboardHelper.IsShiftKeyPressed)
                        {
                            ClearSelection();
                            needsRefresh = true;
                        }
                    }
                }
            }

            if (e.Button == MouseButtons.Middle || interactionState == InteractionState.Pan)
            {
                interactionState = InteractionState.Pan;

                if (panSource == PanSource.None)
                {
                    panSource = PanSource.Mouse;
                }

                oldViewportLocation = ViewportLocation;

                Cursor = CursorHelper.LoadFromResource(Properties.Resources.grabbing);

                needsRefresh = true;
            }

            if (needsRefresh)
            {
                Refresh();
            }
        }