hlolli / csound-mode

Emacs major mode for coding in Csound
41 stars 14 forks source link

Conditionally set play flags for wsl2/wslg on win11 #19

Open tj64 opened 2 years ago

tj64 commented 2 years ago

Hi, with current versions of WSL2 (Windows Subsystem for Linux) graphics and audio are possible, the latter due to a running Pulse Server on WSLg, linked to the users linux distro via env var $PULSE_SERVER.

I added some code that

Cheers Thorsten

PS sorry for the accidental formatting noise in the PR. And something similar needs to be done for csound-repl, but I'm not yet there, maybe another PR soon

hlolli commented 2 years ago

Looks legit issue and legit solution.

I'll review tomorrow (and look into the midi-sco issue as well)

But we need to take into accout that

  1. defvar is user variable, so we can't punish the user for defining csound options within csound-mode. Example: the user defines "-m0", and the check string-empty-p sees that csound-play-flags are defined (as opposed to undefined) and doesn't apply the rtaudio options, and the user loses audio for defining message level options.
  2. .csound6rc (.coundrc or soon to be .csound7rc) are defined by the user, the user defined rtaudio there, but it unable to understand why their dotfiles don't work on rtaudio options. So we need to make sure where order of precedence lies here. We need to respect user's intentions, but if csound-mode in emacs has precedence over .csound6rc I'm not so convinced about.
tj64 commented 2 years ago

I had this in my doom emacs config.el, but first I had to figure out the problem with csound-mode on wsl2 (and how audio works in wsl2 now). The idea of this PR is to set defaults on wsl2 so everything works out-of-the box without each user having to analyse the situation again.

I understand the conflict between avoiding error messages for starters and not messing up csound configs of seasoned users.

Not sure if a new variable like "csound-wsl-flags" would help. Maybe just add another check for a .csoundrc (must be empty or non-existing)?

hlolli commented 2 years ago

We could rethink the configuration variable, and set csound options on individual argument basis. So that rtaudio vars would be their own emacs var, within that, we could set them to defaults depending on the system configuration.

tj64 commented 2 years ago

Sounds good to me. Maybe we could have a defvar (not defcustom) like csound-os-wslg-p, and set that once with this code or something similar:

` (and 
   (string-match "linux" (format "%s" system-type)) 
   (string-match "WSL2" operating-system-release)
   (not (string-empty-p (getenv "PULSE_SERVER") ) ) )`

Then have defcustoms like csound-rtaudio-flag, csound-server-flag (maybe more, but thats all I need for WSL2). And we set them conditional on csound-os-wslg-p as default.

But then they need to be used for csound-play and csound-repl--start-server.

How to proceed now? Reject/Delete the current PR, then either you implement this, or I try to create a new cleaner PR?