public IDisposable Subscribe(ReactiveSpace spaceListener) { CompositeDisposable subscriptions = new CompositeDisposable(); subscriptions.Add(spaceListener .LockedHands() .ObserveOn(UI) .Subscribe(o => { HandsCount++; })); subscriptions.Add(spaceListener .LockedHands() .Select(o => o .ObserveOn(UI) .Subscribe(oo => { }, () => { HandsCount--; })) .Subscribe()); subscriptions.Add(SubscribeCore(spaceListener)); subscriptions.Add(Disposable.Create(()=>HandsCount = 0)); return subscriptions; }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { CompositeDisposable subscriptions = new CompositeDisposable(); subscriptions.Add(spaceListener .LockedHands() .ObserveOn(UI) .SelectMany(h => h .Select(hh => new { Group = h, Hand = hh })) .Subscribe(h => { var diff = 1000 + (h.Hand.PalmPosition.y - h.Group.Key.PalmPosition.y); var bin = (int)(diff / MinInterval); if(bin < PreviousBin) { if(OnMoveDown != null) OnMoveDown(); } if(bin > PreviousBin) { if(OnMoveUp != null) OnMoveUp(); } PreviousBin = bin; })); return subscriptions; }
public override IDisposable Subscribe(ReactiveSpace space) { return space .ReactiveListener .Gestures() .Where(g => g.Key.Type == _Type) .SelectMany(g => g.ToList().Select(l => new { Key = g.Key, Gestures = l })) .BufferUntilCalm(TimeSpan.FromMilliseconds(200)) .Where(b => b.Count > 0) .Subscribe(gs => { var g = gs[0]; float speed = g.Gestures.Where(gg => gg.Pointables.Count > 0) .Average(gg => gg.Pointables[0].TipVelocity.Magnitude); //Diviser par le nbr de frame a la place de la duration var stop = g.Gestures.Last(); var orientation = new Vector(GetDelta(g.Gestures, p => p.x), GetDelta(g.Gestures, p => p.y), GetDelta(g.Gestures, p => p.z)); var size = orientation.Magnitude; orientation = Normalize(orientation); var detected = new LeapGestureViewModel(_Type) { Duration = TimeSpan.FromSeconds(stop.DurationSeconds), Orientation = orientation, FingersCount = gs.SelectMany(gg => gg.Gestures).SelectMany(gg => gg.Pointables).Select(i => i.Id).Distinct().Count(), Speed = speed, Size = size }; if(detected.Speed > MinSpeed) OnMatch(detected, 1.0); }); }
private IDisposable Subscribe(ReactiveSpace reactiveSpace) { return null; }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { var deselectWhenUnlocked = spaceListener.IsLocked() .ObserveOn(UI) .Subscribe(isLocked => { if(!isLocked) ClearCurrent(); }); var updatePosition = spaceListener .LockedHands() .ObserveOn(UI) .Select(g => new { Group = g, CenterPosition = g.Key.PalmPosition }) .SelectMany(g => g .Group .Select(p => new { Position = p, GroupContext = g })) .Subscribe((hand) => { var offset = hand.Position.PalmPosition.To2D() - hand.GroupContext.CenterPosition.To2D(); if(-ZoneHeight/2f < offset.y && offset.y < ZoneHeight / 2f && -ZoneHeight/2f < offset.x && offset.x < ZoneHeight / 2f) GoTo(Center); if(-ZoneHeight / 2f < offset.y && offset.y < ZoneHeight / 2f) { if(-ZoneHeight / 2f >= offset.x) { GoTo(Left); } if(offset.x >= ZoneHeight / 2f) { GoTo(Right); } } if(-ZoneHeight / 2f < offset.x && offset.x < ZoneHeight / 2f) { if(-ZoneHeight / 2f >= offset.y) { GoTo(Down); } if(offset.y >= ZoneHeight / 2f) { GoTo(Up); } } }); CompositeDisposable subscriptions = new CompositeDisposable(); subscriptions.Add(deselectWhenUnlocked); subscriptions.Add(updatePosition); subscriptions.Add(Disposable.Create(ClearCurrent)); return subscriptions; }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { return spaceListener .LockedHands() .SelectMany(l => l) .Where(h => Math.Abs(h.PalmVelocity.y) > VelocityThreshold || Math.Abs(h.PalmVelocity.x) > VelocityThreshold) .Sample(MinInterval) .ObserveOn(UI) .Subscribe(h => { if(OnClicked != null) { LastSide = "Center"; OnClicked(); } if(Math.Abs(h.PalmVelocity.y) > VelocityThreshold) { var isDown = h.PalmVelocity.y < 0.0; var upOrDown = isDown ? OnDown : OnUp; var side = isDown ? "Down" : "Up"; if(upOrDown != null) { LastSide = side; upOrDown(); } } else { var isLeft = h.PalmVelocity.x < 0.0; var leftOrRight = isLeft ? OnLeft : OnRight; var side = isLeft ? "Left" : "Right"; if(leftOrRight != null) { LastSide = side; leftOrRight(); } } }); }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { return spaceListener.LockedHands() .ObserveOn(UI) .Select(g => new { Group = g, StartValue = Value, StartHeight = g.Key.PalmPosition.y }) .SelectMany(g => g .Group .Select(p => new { Position = p, GroupContext = g })) .Subscribe((hand) => { double heightRange = 150.0; var maxHeight = hand.GroupContext.StartHeight + heightRange * ((MaxValue - hand.GroupContext.StartValue) / (MaxValue - MinValue)); var minHeight = maxHeight - heightRange; double height = hand.Position.PalmPosition.y; height = Math.Max(minHeight, height); height = Math.Min(maxHeight, height); Value = Helper.Map(height, minHeight, maxHeight, MinValue, MaxValue); }); }
public virtual IDisposable Subscribe(ReactiveSpace space) { return Disposable.Empty; }
protected virtual IDisposable SubscribeCore(ReactiveSpace spaceListener) { return Disposable.Empty; }
private void Subscribe(ReactiveSpace reactiveSpace) { var fps = reactiveSpace.ReactiveListener.Frames() .Timestamp() .Buffer(2) .ObserveOn(main.UI) .Subscribe(o => { var seconds = (o[1].Timestamp - o[0].Timestamp).TotalSeconds; FPS = (int)(1.0 / seconds); }); var fingerCount = reactiveSpace.ReactiveListener.FingersMoves() .ObserveOn(main.UI) .Subscribe(o => { FingerCount++; }); _Subscriptions.Add(fingerCount); fingerCount = reactiveSpace.ReactiveListener .FingersMoves() .Select(c => c.ObserveOn(main.UI).Subscribe(cc => { }, () => { FingerCount--; })) .Subscribe(); _Subscriptions.Add(fingerCount); _Subscriptions.Add(fps); }
private void Subscribe(ReactiveSpace spaceListener) { var minimized = spaceListener .ReactiveListener .FingersMoves() .SelectMany(m => m) .ThrottleWithDefault(TimeSpan.FromSeconds(1)) .ObserveOn(UI) .Subscribe(b => { if(!ShowConfig) { State = MainViewState.Minimized; } }); //var maximize = // spaceListener // .ReactiveListener // .Gestures // .Where(g => g.Key.Type == Gesture.GestureType.TYPECIRCLE) // .SelectMany(g => g.ToList().Select(l => new // { // Key = g.Key, // Values = l // })) // .Buffer(() => spaceListener.ReactiveListener.Gestures.SelectMany(g => g).OnlyTimeout(TimeSpan.FromMilliseconds(500))) // .Where(b => b.Count > 0) // .Take(1) // .Repeat() // .ObserveOn(UI) // .Subscribe(l => // { // var distinct = l.SelectMany(oo => oo.Values.SelectMany(o => o.Pointables)).Select(p => p.Id).Distinct().Count(); // State = MainViewState.Navigating; // }); var maximize = spaceListener .LockedHands() .SelectMany(h => h) .ObserveOn(UI) .Subscribe(h => { if(State == MainViewState.Minimized) State = MainViewState.Navigating; }); var lockedSubs = spaceListener .IsLocked() .ObserveOn(UI) .CombineLatest(Helper.PropertyChanged(this, () => this.State), (l, s) => new { Locked = l, State = s }) .Where(o => o.State != MainViewState.Minimized) .Subscribe(o => { State = o.Locked ? MainViewState.Locked : MainViewState.Navigating; }); _Subscriptions.Add(lockedSubs); _Subscriptions.Add(maximize); _Subscriptions.Add(minimized); }
public MainViewModel(ReactiveSpace spaceListener) { _ProgListener = new ForegroundProgramListener(); _ProgListener.ForegroundProcess .ObserveOn(UI) .Subscribe(pid => { if(pid != _CurrentPid) { using(var p = Process.GetProcessById(pid)) { CurrentProgram = p.ProcessName; var tile = Tiles.FirstOrDefault(t => t.BelongsToFastContext(p.ProcessName)); if(tile != null) CurrentTile = tile; } } }); this.State = MainViewState.Navigating; this._SpaceListener = spaceListener; this._Tiles.CollectionChanged += UpdateFreeTiles; Subscribe(spaceListener); _GestureTemplates.Add(GestureTemplateViewModel.Empty); _GestureTemplates.Add(new LeapGestureTemplateViewModel(Gesture.GestureType.TYPECIRCLE) { Name = "Circle" }); _GestureTemplates.Add(new LeapGestureTemplateViewModel(Gesture.GestureType.TYPEKEYTAP) { Name = "KeyTap" }); _GestureTemplates.Add(new LeapGestureTemplateViewModel(Gesture.GestureType.TYPESCREENTAP) { Name = "ScreenTap" }); _GestureTemplates.Add(new LeapGestureTemplateViewModel(Gesture.GestureType.TYPESWIPE) { Name = "Swipe", MinSpeed = 1500 }); _PresenterTemplates.Add(new PresenterTemplateViewModel("Not used", "", () => PresenterViewModel.Unused)); _PresenterTemplates.Add(new PresenterTemplateViewModel("Switch windows", () => new MovePresenterViewModel() { OnEnter = Interpreter.Simulate("DOWN ALT"), OnMoveUp = Interpreter.Simulate("PRESS TAB"), OnMoveDown = Interpreter.Simulate( "DOWN SHIFT", "PRESS TAB", "UP SHIFT"), OnRelease = Interpreter.Simulate("UP ALT") } )); _PresenterTemplates.Add(new PresenterTemplateViewModel("Switch windows 2", () => new CyclePresenterViewModel() { OnEnter = Interpreter.Simulate("DOWN ALT"), OnClockWise = Interpreter.Simulate("PRESS TAB"), OnCounterClockWise = Interpreter.Simulate( "DOWN SHIFT", "PRESS TAB", "UP SHIFT"), OnRelease = Interpreter.Simulate("UP ALT") } )); _PresenterTemplates.Add(new PresenterTemplateViewModel("Volume", () => VolumePresenterViewModel.Create())); _PresenterTemplates.Add(new PresenterTemplateViewModel("Dock window", () => new ZonePresenterViewModel() { Up = new ZoneTransitionViewModel() { OnEnter = Interpreter.Simulate("PRESS WIN,UP"), OnLeave = Interpreter.Simulate("PRESS WIN,DOWN"), }, Down = new ZoneTransitionViewModel() { OnEnter = Interpreter.Simulate("PRESS WIN,DOWN"), OnLeave = Interpreter.Simulate("") }, Right = new ZoneTransitionViewModel() { OnEnter = Interpreter.Simulate("PRESS WIN,RIGHT"), OnLeave = Interpreter.Simulate("PRESS WIN,LEFT"), }, Left = new ZoneTransitionViewModel() { OnEnter = Interpreter.Simulate("PRESS WIN,LEFT"), OnLeave = Interpreter.Simulate("PRESS WIN,RIGHT"), }, Center = new ZoneTransitionViewModel(), })); _PresenterTemplates.Add(new PresenterTemplateViewModel("Close window", () => new ClickPresenterViewModel() { OnClicked = Interpreter.Simulate("PRESS ALT,F4") })); _Debug = new DebugViewModel(this); Observable.Interval(TimeSpan.FromSeconds(5.0)) .ObserveOn(UI) .Subscribe(t => { new GestSpaceRepository().Save(this); }); new GestSpaceRepository().Load(this); //CurrentTile = Tiles.First(t => !t.IsUnused); }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { return spaceListener .ReactiveListener .FingersMoves() .Concat() .ObserveOn(UI) .Subscribe(c => { var v = c.TipVelocity.To2D(); //v = new Vector(-c.TipVelocity.x, c.TipVelocity.y, 0); var cos = Math.Cos(Helper.DegreeeToRadian(Rotation)); var sin = Math.Sin(Helper.DegreeeToRadian(Rotation)); var tan = new Vector((float)sin, (float)cos, 0); var man = tan.Dot(v); Rotation -= man / 100; }); }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { listener = new ReactiveListener(); var spaceListener = new ReactiveSpace(listener); controller = new Controller(listener); ViewModel = new MainViewModel(spaceListener); var ui = SynchronizationContext.Current; //listener // .FingersMoves // .SelectMany(f => f.ToList().Select(l => // new // { // Key = f.Key, // Fingers = l // })) // .Subscribe(f => // { // Console.WriteLine("finger"); // try // { // //var max = f.Fingers.Select(ff => GetAngle(ff)).Where(a => a != null).Select(a => a.Value).Max(); // var av = f.Fingers.Select(ff => GetAngle(ff)).Where(a => a != null).Select(a => a.Value).Average(); // Console.WriteLine("av : " + ((int)av)); // } // catch // { // Console.WriteLine("Ex"); // } // }); var centers = listener .FingersMoves() .SelectMany(f => f) .Buffer(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(100)) .Where(b => b.Count > 0) .Select(b => KeepPopularFinger(b)) .Select(v => new { Finger = v.First().Id, Position = new Leap.Vector(v.Average(m => m.StabilizedTipPosition.x), v.Average(m => m.StabilizedTipPosition.y), 0.0f), }); var moveCenter = listener .FingersMoves() .SelectMany(f => f) .CombineLatest(centers, ViewModel.SpaceListener.IsLocked(), (p, center, locked) => new { Center = center, Position = p.StabilizedTipPosition.To2D(), Move = p.StabilizedTipPosition.To2D() - center.Position, Locked = locked, Finger = p }) .Where(p => p.Center.Finger == p.Finger.Id) .Where(p => !p.Locked); moveCenter .ObserveOn(ui) .Subscribe(o => { ViewModel.SelectionPosition = new Point(o.Move.x, o.Move.y); }); moveCenter .Where(o => o.Move.Magnitude >= 50.0) .Sample(TimeSpan.FromMilliseconds(1000)) .ObserveOn(ui) .Subscribe(o => { if(ViewModel.Debug.FingerCount <= 2 && ViewModel.State == MainViewState.Navigating) { var angle = Helper.RadianToDegree(Math.Atan2(o.Move.y, o.Move.x)); if(!ViewModel.ShowConfig) ViewModel.SelectTile(angle); } }); Dispatcher.BeginInvoke(new Action(() => { Center(); })); })); }