From b126700f01b206b4fc6fb97223b0c1ab8fc97913 Mon Sep 17 00:00:00 2001 From: phosphene47 Date: Wed, 27 Nov 2019 22:47:00 +1100 Subject: [PATCH 1/5] Debounce hover sounds --- .../UserInterface/HoverClickSounds.cs | 15 +++++++++++++- .../Graphics/UserInterface/HoverSounds.cs | 20 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs index 4f678b7218..b1a58b5d57 100644 --- a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs @@ -1,12 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Extensions; using osu.Framework.Input.Events; +using osu.Framework.Threading; using osuTK.Input; namespace osu.Game.Graphics.UserInterface @@ -34,10 +36,21 @@ namespace osu.Game.Graphics.UserInterface this.buttons = buttons ?? new[] { MouseButton.Left }; } + private ScheduledDelegate playDelegate; + protected override bool OnClick(ClickEvent e) { + playDelegate?.Cancel(); + if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition)) - sampleClick?.Play(); + { + var debounceMs = (int)DebounceTime.TotalMilliseconds; + + if (debounceMs == 0) + sampleClick?.Play(); + else + playDelegate = Scheduler.AddDelayed(() => sampleClick?.Play(), debounceMs); + } return base.OnClick(e); } diff --git a/osu.Game/Graphics/UserInterface/HoverSounds.cs b/osu.Game/Graphics/UserInterface/HoverSounds.cs index f1ac8ced6e..f4258f2b6d 100644 --- a/osu.Game/Graphics/UserInterface/HoverSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverSounds.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.ComponentModel; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -9,6 +10,7 @@ using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; +using osu.Framework.Threading; namespace osu.Game.Graphics.UserInterface { @@ -20,6 +22,12 @@ namespace osu.Game.Graphics.UserInterface { private SampleChannel sampleHover; + /// + /// Length of debounce for sound playback. + /// Set this to to disable debouncing. + /// + public TimeSpan DebounceTime { get; set; } = TimeSpan.FromMilliseconds(50); + protected readonly HoverSampleSet SampleSet; public HoverSounds(HoverSampleSet sampleSet = HoverSampleSet.Normal) @@ -28,9 +36,19 @@ namespace osu.Game.Graphics.UserInterface RelativeSizeAxes = Axes.Both; } + private ScheduledDelegate playDelegate; + protected override bool OnHover(HoverEvent e) { - sampleHover?.Play(); + playDelegate?.Cancel(); + + var debounceMs = (int)DebounceTime.TotalMilliseconds; + + if (debounceMs == 0) + sampleHover?.Play(); + else + playDelegate = Scheduler.AddDelayed(() => sampleHover?.Play(), debounceMs); + return base.OnHover(e); } From 037d927e4518ee16925ff08e4eb037f6b8b2d6dc Mon Sep 17 00:00:00 2001 From: phosphene47 Date: Wed, 27 Nov 2019 22:51:27 +1100 Subject: [PATCH 2/5] TimeSpans can be negative! --- osu.Game/Graphics/UserInterface/HoverClickSounds.cs | 2 +- osu.Game/Graphics/UserInterface/HoverSounds.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs index b1a58b5d57..fcb8f8d6bd 100644 --- a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs @@ -46,7 +46,7 @@ namespace osu.Game.Graphics.UserInterface { var debounceMs = (int)DebounceTime.TotalMilliseconds; - if (debounceMs == 0) + if (debounceMs <= 0) sampleClick?.Play(); else playDelegate = Scheduler.AddDelayed(() => sampleClick?.Play(), debounceMs); diff --git a/osu.Game/Graphics/UserInterface/HoverSounds.cs b/osu.Game/Graphics/UserInterface/HoverSounds.cs index f4258f2b6d..2223ac21db 100644 --- a/osu.Game/Graphics/UserInterface/HoverSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverSounds.cs @@ -44,7 +44,7 @@ namespace osu.Game.Graphics.UserInterface var debounceMs = (int)DebounceTime.TotalMilliseconds; - if (debounceMs == 0) + if (debounceMs <= 0) sampleHover?.Play(); else playDelegate = Scheduler.AddDelayed(() => sampleHover?.Play(), debounceMs); From d4afea0b5e5197d81999ee7edbf774a5946e0319 Mon Sep 17 00:00:00 2001 From: phosphene47 Date: Wed, 27 Nov 2019 23:06:07 +1100 Subject: [PATCH 3/5] Use double instead of TimeSpan --- osu.Game/Graphics/UserInterface/HoverClickSounds.cs | 7 ++----- osu.Game/Graphics/UserInterface/HoverSounds.cs | 12 ++++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs index fcb8f8d6bd..a8e074d2ef 100644 --- a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -44,12 +43,10 @@ namespace osu.Game.Graphics.UserInterface if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition)) { - var debounceMs = (int)DebounceTime.TotalMilliseconds; - - if (debounceMs <= 0) + if (DebounceTime <= 0) sampleClick?.Play(); else - playDelegate = Scheduler.AddDelayed(() => sampleClick?.Play(), debounceMs); + playDelegate = Scheduler.AddDelayed(() => sampleClick?.Play(), DebounceTime); } return base.OnClick(e); diff --git a/osu.Game/Graphics/UserInterface/HoverSounds.cs b/osu.Game/Graphics/UserInterface/HoverSounds.cs index 2223ac21db..c98d50efff 100644 --- a/osu.Game/Graphics/UserInterface/HoverSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverSounds.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.ComponentModel; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -23,10 +22,9 @@ namespace osu.Game.Graphics.UserInterface private SampleChannel sampleHover; /// - /// Length of debounce for sound playback. - /// Set this to to disable debouncing. + /// Length of debounce for sound playback, in milliseconds. Default is 50ms. /// - public TimeSpan DebounceTime { get; set; } = TimeSpan.FromMilliseconds(50); + public double DebounceTime { get; set; } = 50; protected readonly HoverSampleSet SampleSet; @@ -42,12 +40,10 @@ namespace osu.Game.Graphics.UserInterface { playDelegate?.Cancel(); - var debounceMs = (int)DebounceTime.TotalMilliseconds; - - if (debounceMs <= 0) + if (DebounceTime <= 0) sampleHover?.Play(); else - playDelegate = Scheduler.AddDelayed(() => sampleHover?.Play(), debounceMs); + playDelegate = Scheduler.AddDelayed(() => sampleHover?.Play(), DebounceTime); return base.OnHover(e); } From 786fb9ede350164c1e9e79c760e5a472d3441b25 Mon Sep 17 00:00:00 2001 From: phosphene47 Date: Thu, 28 Nov 2019 00:44:01 +1100 Subject: [PATCH 4/5] Split click and hover and disable click debounce --- osu.Game/Graphics/UserInterface/HoverClickSounds.cs | 9 +++++++-- osu.Game/Graphics/UserInterface/HoverSounds.cs | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs index a8e074d2ef..61cacee45f 100644 --- a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs @@ -21,6 +21,11 @@ namespace osu.Game.Graphics.UserInterface private SampleChannel sampleClick; private readonly MouseButton[] buttons; + /// + /// Length of debounce for click sound playback, in milliseconds. Default is 0ms. + /// + public double ClickDebounceTime { get; set; } + /// /// a container which plays sounds on hover and click for any specified s. /// @@ -43,10 +48,10 @@ namespace osu.Game.Graphics.UserInterface if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition)) { - if (DebounceTime <= 0) + if (ClickDebounceTime <= 0) sampleClick?.Play(); else - playDelegate = Scheduler.AddDelayed(() => sampleClick?.Play(), DebounceTime); + playDelegate = Scheduler.AddDelayed(() => sampleClick?.Play(), ClickDebounceTime); } return base.OnClick(e); diff --git a/osu.Game/Graphics/UserInterface/HoverSounds.cs b/osu.Game/Graphics/UserInterface/HoverSounds.cs index c98d50efff..fcd8940348 100644 --- a/osu.Game/Graphics/UserInterface/HoverSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverSounds.cs @@ -22,9 +22,9 @@ namespace osu.Game.Graphics.UserInterface private SampleChannel sampleHover; /// - /// Length of debounce for sound playback, in milliseconds. Default is 50ms. + /// Length of debounce for hover sound playback, in milliseconds. Default is 50ms. /// - public double DebounceTime { get; set; } = 50; + public double HoverDebounceTime { get; set; } = 50; protected readonly HoverSampleSet SampleSet; @@ -40,10 +40,10 @@ namespace osu.Game.Graphics.UserInterface { playDelegate?.Cancel(); - if (DebounceTime <= 0) + if (HoverDebounceTime <= 0) sampleHover?.Play(); else - playDelegate = Scheduler.AddDelayed(() => sampleHover?.Play(), DebounceTime); + playDelegate = Scheduler.AddDelayed(() => sampleHover?.Play(), HoverDebounceTime); return base.OnHover(e); } From 92ab8026a006bd9e7977bd659dcb3e9b1a41d63e Mon Sep 17 00:00:00 2001 From: Min Date: Thu, 28 Nov 2019 16:03:59 +1100 Subject: [PATCH 5/5] Completely remove click sound debounce --- .../UserInterface/HoverClickSounds.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs index 61cacee45f..803facae04 100644 --- a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Linq; @@ -7,7 +7,6 @@ using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Extensions; using osu.Framework.Input.Events; -using osu.Framework.Threading; using osuTK.Input; namespace osu.Game.Graphics.UserInterface @@ -21,11 +20,6 @@ namespace osu.Game.Graphics.UserInterface private SampleChannel sampleClick; private readonly MouseButton[] buttons; - /// - /// Length of debounce for click sound playback, in milliseconds. Default is 0ms. - /// - public double ClickDebounceTime { get; set; } - /// /// a container which plays sounds on hover and click for any specified s. /// @@ -40,19 +34,10 @@ namespace osu.Game.Graphics.UserInterface this.buttons = buttons ?? new[] { MouseButton.Left }; } - private ScheduledDelegate playDelegate; - protected override bool OnClick(ClickEvent e) { - playDelegate?.Cancel(); - if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition)) - { - if (ClickDebounceTime <= 0) - sampleClick?.Play(); - else - playDelegate = Scheduler.AddDelayed(() => sampleClick?.Play(), ClickDebounceTime); - } + sampleClick?.Play(); return base.OnClick(e); }