I made a TUI soundboard in Rust! (cls) (github.com)
from NorthWestWind@lemmy.world to rust@programming.dev on 07 Oct 2024 12:23
https://lemmy.world/post/20595864

This is my first ever Rust program.

The motivation of this is to create a soundboard with global hotkey support on Wayland, because Soundux wouldn’t add it :<
That’s why this soundboard is structurally very similar to Soundux.

Here’s a screenshot:

#rust

threaded - newest

Ephera@lemmy.ml on 07 Oct 2024 22:29 next collapse

Neat.

Zykino@programming.dev on 08 Oct 2024 07:01 collapse

I read that global hotkey is not possible in Wayland. Or, at least, not as easily as with XOrg. Did you achived it ? Can you link to where you are doing it in your code please ? I’m curious, especially since its the first time I heard global hotkeys from a terminal program.

I try not to use global hotkeys myself. Do you have another way of controlling the soundboard ? Either from websocket, DBus, launching a command, … I like to use streampi^1^ (open source streamdeck clone) for streaming and it may use any of this interraction methods. (Websocket may require to write a plugin for yëur program.)

^1^ Streampi as stopped developpment for now in its v2 snapshots. Still usable. But the dev want to rewrite in C++/Qt for a v3.

NorthWestWind@lemmy.world on 08 Oct 2024 08:17 next collapse

During my development, I have found 2 different crates that handles global key input. They are inputbot and mki. I looked at some issues in inputbot and learnt that they are using libinput as the backend. I didn’t read about mki though.

This soundboard is using mki, and global hotkey is working in Wayland (at least for Plasma).

NorthWestWind@lemmy.world on 10 Oct 2024 05:12 collapse

Global hotkey is only used for playing the sounds and nothing else, and that is basically just running a command.

This will play all files that has an audio stream (cls is also using this command):
ffmpeg -i <file> -f s16le - | pacat -d <sink> --channels=<1 for mono, 2 for stereo> --rate=<sample rate> --volume=<0-65535, 65535 = 100%>

I guess it is pretty complicated so maybe I’ll add a way to play files.

Zykino@programming.dev on 12 Oct 2024 06:37 collapse

Yeah, I’d rather register cls play <id, name or path> in streampi or other macro box. Especially if cls let me add new sounds and configure things easily. Like I see having multiples “public laughing”, so when starting the sound any can be played. Which provide a bit of variety in the stream. And allow to repeat the sound for a longer effect on the fly without being too repetitive.