pulb / mailnag

An extensible mail notification daemon
GNU General Public License v2.0
253 stars 32 forks source link

More control over sound notification #178

Open TimP69 opened 5 years ago

TimP69 commented 5 years ago

mailnag-config lets you enable/disable a Sound Notification. By default the sound file located at /usr/share/mailnag/mailnag.ogg is played. It would be nice if the Sound Notification plugin could be modified within mailnag-config to select a different sound file.

As mentioned elsewhere, you can change which sound file is played by editing ~/.config/mailnag/mailnag.cfg (under Ubuntu 18.04) and tweaking the following section:

[soundplugin]
soundfile = /full/path/to/sound.file

One thing I noticed — when substituting my own sound files — was that the volume ended up being quite loud. It would appear that the ID3 audio normalisation tags were being ignored.

Knowing nothing about Python or GStreamer, I ultimately worked out that you could gain volume control by inserting a single set_property line towards the bottom of /usr/lib/python2.7/dist-packages/Mailnag/plugins/soundplugin.py:

ply = Gst.ElementFactory.make("playbin", "player")
ply.set_property("uri", "file://" + os.path.abspath(filename))
ply.set_property("volume", 0.2)
pt = _GstPlayThread(ply)
pt.start()

A volume of 0.0 is mute, 1.0 is max.

Now, due to the way that Python works, you need to perform a couple of extra steps to get it to regenerate a compiled bytecode file, but I wrote up a whole blog post with the details — so check that out if you need to.

Being able to select alternative sound files and set their volume levels by modifying the Sound Notification plugin within mailnag-config would be ideal. Failing that, perhaps adding a "volume = 1.0" entry under [soundplugin] in ~/.config/mailnag/mailnag.cfg — and being able to control volume that way — would be possible?

pulb commented 5 years ago

Hi, thanks for your intererst in Mailnag and your very comprehensive blog post about python binary files. You can avoid all this pain though, by simply copying your plugin (e.g. my-sound-plugin.py) file into ~/.config/mailnag/plugins. This way, the associated *.pyc file can be generated automatically (this dir has write access) and your modifcations won't be overwritten by a Mailnag software update.

Unortunately I have currently no time to work on Mailnag, but if you want to enhance the official plugin with widgets for a custom soundfile and a volume slider, I'd be very intersted in it :)