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

Add ability to have a system-wide configuration file for Windows #1143

Closed
daniel-1964 opened this issue Aug 18, 2022 · 6 comments
Closed

Add ability to have a system-wide configuration file for Windows #1143

daniel-1964 opened this issue Aug 18, 2022 · 6 comments
Milestone

Comments

@daniel-1964
Copy link

daniel-1964 commented Aug 18, 2022

I want a system-wide configuration file for fluidsynth on Windows

Linux has one on /etc but Windows does not have /etc or similar.
My proposal is to place the system-wide configuration file togheter with the fluidsynth executable.
I know that only administrator can modify this file, but with a junction you can put it elsewhere.

My solution

If you accept win32 api code in this part of program, the solution is very simple (see patch below).

diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c                                                        
index 1d4baaed..b7c9b60f 100644                                                                                         
--- a/src/bindings/fluid_cmd.c                                                                                          
+++ b/src/bindings/fluid_cmd.c                                                                                          
@@ -692,7 +692,22 @@ fluid_get_userconf(char *buf, int len)                                                             
 char *                                                                                                                 
 fluid_get_sysconf(char *buf, int len)                                                                                  
 {                                                                                                                      
-#if defined(WIN32) || defined(MACOS9)                                                                                  
+#if defined(WIN32)                                                                                                     
+    char exePath[MAX_PATH];                                                                                            
+    char *lpFileName;                                                                                                  
+    int requiredLen;                                                                                                   
+    GetModuleFileName(NULL, exePath, MAX_PATH);                                                                        
+    requiredLen = GetFullPathName(exePath, len, buf, &lpFileName);                                                     
+    if(requiredLen >= len)                                                                                             
+    {                                                                                                                  
+        return NULL;                                                                                                   
+    }                                                                                                                  
+    else                                                                                                               
+    {                                                                                                                  
+        strcpy(lpFileName, "fluidsynth.cfg");                                                                          
+        return buf;                                                                                                    
+    }                                                                                                                  
+#elif defined(MACOS9)                                                                                                  
     return NULL;                                                                                                       
 #else                                                                                                                  
     FLUID_SNPRINTF(buf, len, "/etc/fluidsynth.conf");                                                                  

HTH

@derselbst
Copy link
Member

The idea of a system-wide config is that no matter where you are on the system and no matter who you are, you get the same config file.

Your proposal is neither a system-wide, nor a user-wide config, as the location of the config depends on the location of the invoking process. This is not acceptable, sry.

@daniel-1964
Copy link
Author

daniel-1964 commented Aug 18, 2022 via email

@derselbst
Copy link
Member

This also apply for the "c:\soundfonts\default.sf"" hardcoded in fluidsynth.

You probably mean C:\ProgramData\soundfonts\default.sf2, do you? This value can be overridden when building fluidsynth.

I would prefer to go with the %PROGRAMDATA%\fluidsynth solution you proposed, just by simply using getenv() (no need for too much win32 clutter). For Windows Vista and older, fluid_get_sysconf() should just return NULL as before.

If the default.sf2 strikes you so much, I would be open to relocate this into %PROGRAMDATA%\fluidsynth by default.

@daniel-1964
Copy link
Author

Yes, I prefer having default.sf2 into c:\ProgramData\fluidsynth. But it is not so important if we have already a system-wide configuration file.

Finaly the solution invoked yesterday reaches my goal:

  • In the fluid_get_sysconf function use:
    char *program_data = getenv("ProgramData"); if(program_data == NULL) { return NULL; } else { FLUID_SNPRINTF(buf, len, "%s\\fluidsynth\\fluidsynth.cfg", program_data); return buf; }
    to set the system-wide configuration file.

  • In build use the option:
    -DDEFAULT_SOUNDFOT='C:\\ProgramData\\Fluidsynth\\default.sf2"

I have tested and it works perfectly for my need: all users of my Windows machine can use a configured fluidsynth without having to define a user configuration file.
I let in your own the default value for the DEFAULT_SOUNDFONT build option. It can break the configuration for old systems but is better in newer system because it is more compliant with the latest Windows philosophy.

@derselbst
Copy link
Member

Ok, thanks. I'll probably adapt your solution later, when I find some time.

derselbst added a commit that referenced this issue Aug 21, 2022
@derselbst derselbst added this to the 2.2 milestone Aug 26, 2022
@derselbst
Copy link
Member

Implemented in 5c38efb and will be part of 2.2.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants