Howto:Reload sound configuration without restarting: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(I encountered this problem on the concatenation of paths, "~" it is not enough you need to insert the character "/" then I replaced "~" with the string ~ '/' ~)
No edit summary
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
As a massive timesaver for those working on sound configuration files, the following piece of nasal code can be entered in the [[nasal]] console (found on the Debug [[menu]].)
__NOTOC__


'''Reloading the sound configuration without restarting''' can be a massive time saver for those working on sound configuration files.
{{FGCquote
  | the reinit code is not needed anymore, just reload model from debug menu. It does the same.
  |{{cite web |url={{forum url|p=176705}}
    |title=<nowiki>Re: How do I dynamically change audio files to play?</nowiki>
    |author=<nowiki>Necolatis</nowiki>
    |date=<nowiki>Tue Nov 12</nowiki>
  }}
}}
== Using the Nasal console ==
Note: this method does not seems to work anymore. 
The following line of Nasal code can be entered in the [[Nasal Console|Nasal console]] (found in the Debug [[menu]]).
<syntaxhighlight lang="nasal">
  fgcommand("reinit", props.Node.new({ subsystem: "fx" }))
  fgcommand("reinit", props.Node.new({ subsystem: "fx" }))
</syntaxhighlight>
Every time the line is executed the sound subsystem ("fx") is restarted and the configuration file reloaded, enabling you to test your changes instantly.


Every time that line is executed, the sound subsystem ("fx") is restarted and the config file reloaded, enabling you to test your changes instantly. Just remember to actually save your sound config file each time you want to test so that FG sees the most recent changes.
{{tip|Remember to actually save your sound configuration file each time you want to test it, so that FG can see the most recent changes.}}


Here is a Nasal function which will automatically reload the sound xml file when you make a change...
== Reloading the sound config automatically ==
Here is a Nasal function which will automatically reload the sound configuration file when you make a change:


<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
  var reload_sound = func {
  var reload_sound = func {
   var sf = getprop('/tmp/sound-xml/path');
   var sf = getprop('/tmp/sound-xml/path');
Line 31: Line 53:
  reload_sound();
  reload_sound();
</syntaxhighlight>
</syntaxhighlight>
== Related content ==
* [[Howto:Add sound effects to aircraft]]


[[Category:Howto|Reload sound config without restarting]]
[[Category:Howto|Reload sound config without restarting]]

Revision as of 11:56, 14 November 2019


Reloading the sound configuration without restarting can be a massive time saver for those working on sound configuration files.


Cquote1.png the reinit code is not needed anymore, just reload model from debug menu. It does the same.
— Necolatis (Tue Nov 12). Re: How do I dynamically change audio files to play?.
(powered by Instant-Cquotes)
Cquote2.png

Using the Nasal console

Note: this method does not seems to work anymore.

The following line of Nasal code can be entered in the Nasal console (found in the Debug menu).

 fgcommand("reinit", props.Node.new({ subsystem: "fx" }))

Every time the line is executed the sound subsystem ("fx") is restarted and the configuration file reloaded, enabling you to test your changes instantly.

Tip  Remember to actually save your sound configuration file each time you want to test it, so that FG can see the most recent changes.

Reloading the sound config automatically

Here is a Nasal function which will automatically reload the sound configuration file when you make a change:

 var reload_sound = func {
  var sf = getprop('/tmp/sound-xml/path');
  if(sf == nil)
  {
    sf = getprop('/sim/fg-root') ~ '/' ~ getprop('/sim/sound/path');
    setprop('/tmp/sound-xml/path', sf);
  }
  var st = io.stat(sf);
  var lm = getprop('/tmp/sound-xml/modified');
  if(lm == nil)
  {
    lm = st[9];
    setprop('/tmp/sound-xml/modified', lm);
  }
  elsif(lm < st[9])
  {
    setprop('/tmp/sound-xml/modified', st[9]);
    fgcommand('reinit', props.Node.new({ subsystem: "fx" }));
  }
  settimer(reload_sound, 2);
 }
 reload_sound();

Related content