Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: new class Juego_button & Bugfix: sound repeating when hovering on buttons #35

Merged
merged 3 commits into from
Mar 23, 2023

Conversation

marsian83
Copy link
Contributor

How to reproduce the bug?

  1. open the activity
  2. hover on any of the menu buttons
  3. move the cursor around
  4. notice the sound is played whenever there is mouse motion

Cause

The issue was caused due to there not being any checks in place to see if the sound has already been played or not. the implementation was done by checking for a pygame event of type MOUSEMOTION and whenever the mouse moved and the mouse coordinates lied within a button, it played the sound.

Fix

I have added a variable menu_sound_played which is initially set to False and is set to True whenever a sound is played within a hover event. it is set to False again whenever the cursor moves out of a button, sounds are only played when the value is False. This way, the sounds do not repeat whenever moving the cursor

whenever hovering on a button the menu.ogg sound kept playing repeatedly. fixed it by adding a variable menu_sound_played to check if the sound has already been played for that hover event or not
@quozl
Copy link

quozl commented Feb 26, 2023

The solution seems complex, and stops sounds under some circumstances. Please look through the commit history to see when the problem began, and tell us which commit is the cause?

@marsian83
Copy link
Contributor Author

Hi @quozl, I have checked out previous versions of the activity and this was the oldest commit I was able to run as it's the port to Gtk3.

Running it makes it evident that the issue existed even then and the implementation for playing the sound was done in this manner to begin with, a MOUSEMOTION event is detected and a sound is played if the mouse is within the button's co-ordinates. This can be seen here in the v1 initial commit.

As you specified, the sound doesn't play in some scenarios, this happens when we move too quickly between buttons. This is due to the buttons being too close and MOUSEMOTION not being able to detect the movement in between the buttons and the cursor moving over to the next button too quickly.

if it would be desirable, I can accommodate this by moving these buttons so that the gap between them is increased.

moreover, I have noticed the coordinates of the buttons are hard coded everywhere and even the checks are repeated multiple times so, that could also be improved by turning the buttons into their own separate classes and having methods to check hovers and running callbacks. would this be desirable?

@quozl
Copy link

quozl commented Feb 27, 2023

Thanks for checking. I went back to the first commit and looked at juego.py, which does not depend on GTK, and found the same; the menu sound is ordered to play on mouse motion event, and there is no check for if the sound is already playing.

I think you are observing a feature of the newer pygame SDL Mixer, which may allow more channels now than a previous version of pygame. Latest version allows eight channels. This is a limit on number of simultaneous sounds. I don't remember it being so generous.

It would be better to detect entry into the area rather than detect motion within it.

Yes, there are too many special numeric constants. You may be interested in https://github.com/orgs/sugarlabs/projects?type=classic which lists the display resolution project in more detail, with background on the overall problem that affects many of the pygame and GTK activities.

@marsian83 marsian83 changed the title fixed buttons sound playing continuously on hover Refactor: new class Juego_button & Bugfix: sound repeating when hovering on buttons Mar 15, 2023
@marsian83
Copy link
Contributor Author

Hi @quozl I have created a new class to avoid hard coding the values for checking hovers and mouse clicks
This class also fixes the issue of multiple sounds playing on hover as each button has it's own hovered property we don't get any cases where, if the mouse moves too quickly we don't get any sound as well.

@quozl
Copy link

quozl commented Mar 23, 2023

Thanks. Looks good.

@quozl quozl merged commit ea7e78f into sugarlabs:master Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants