zxcalc / zxlive

A graphical tool for the ZX calculus
Apache License 2.0
45 stars 15 forks source link

Add sound effects #251

Open y-richie-y opened 3 weeks ago

y-richie-y commented 3 weeks ago

Sound effects are activated with the shortcut Ctrl+B.

RazinShaikh commented 3 weeks ago

Epic 😎 Can you add an option to turn the sound effects on or off in the menu or preferences? Another slight problem I noticed is that when I have the sound effects on, the UI gets stuck for ~0.5 seconds to play the sound effect. Can you please fix that?

y-richie-y commented 3 weeks ago

Added the sound effects in preferences. On my computer the lag only happens the first time any sound is played, not sure what to do about that.

RazinShaikh commented 3 weeks ago

The lag happens every time for me unfortunately.

y-richie-y commented 3 weeks ago

Does anyone have any ideas on how to fix this? I can't replicate it on my machine

RazinShaikh commented 3 weeks ago

After the recent commit, I am not able to open preferences. I get the following error:

Traceback (most recent call last):
  File "C:\Users\Razin Shaikh\OneDrive\Documents\code\zxlive\zxlive\mainwindow.py", line 129, in <lambda>
    self.preferences_action = self._new_action("&Preferences...", lambda: open_settings_dialog(self), None, "Open the preferences dialog")
  File "C:\Users\Razin Shaikh\OneDrive\Documents\code\zxlive\zxlive\settings_dialog.py", line 264, in open_settings_dialog
    dialog = SettingsDialog(parent)
  File "C:\Users\Razin Shaikh\OneDrive\Documents\code\zxlive\zxlive\settings_dialog.py", line 67, in __init__
    self.add_setting(form_general, "sound-effects", "Sound Effects", "checkbox")
  File "C:\Users\Razin Shaikh\OneDrive\Documents\code\zxlive\zxlive\settings_dialog.py", line 225, in add_setting
    widget.setChecked(val)
TypeError: 'PySide6.QtWidgets.QAbstractButton.setChecked' called with wrong argument types:       
  PySide6.QtWidgets.QAbstractButton.setChecked(str)
Supported signatures:
  PySide6.QtWidgets.QAbstractButton.setChecked(bool)
y-richie-y commented 3 weeks ago

I don't get this error but I have (hopefully) a fix

jvdwetering commented 2 weeks ago

In Qt, you can add files to a resource file, and then they will be loaded at start time. This might prevent the lagging when playing the sound for the first time (but at a potential cost of increasing the start-up time). If you want to try this, you can add the sound files to the zxlive/resources.qrc file. You then have to recompile the file to resources.py: https://www.pythonguis.com/tutorials/packaging-data-files-pyside6-with-qresource-system/

RazinShaikh commented 1 week ago

Perhaps we should just merge this as this is an easter egg feature, disabled by default. Thoughts?

y-richie-y commented 1 week ago

I am for this: I can't replicate the lag on my machine and I also don't know what could fix the lag.

It is disabled by default already

jvdwetering commented 1 week ago

The testing suite gives the error

from PySide6.QtMultimedia import QSoundEffect
E   ImportError: libpulse.so.0: cannot open shared object file: No such file or directory

Should a new library be included in the requirements.txt?