Board index FlightGear Development Nasal

Spoken GCA

Nasal is the scripting language of FlightGear.

Re: Spoken GCA

Postby rleibner » Wed Mar 07, 2018 8:49 pm

I've added a generic listen_mouse_events() function to the skinnable class.
And uploaded new versions of the PAR and Oscilloscope addons who uses that feature.

Still have to document that on the wiki.

On the other hand, I wanted to add some audible feedback when a button is pressed (it didn't work) :cry:
Par.nas at lines 77-81 reads:
Code: Select all
var sound = {
path : addon.basePath,
file : addon.resourcePath("click.wav") ,
volume : 1};
fgcommand("play-audio-sample", props.Node.new(sound) );
but I hear nothing (should sound when the instrument is instantiated -only as a test-).
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 230
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: 2180.4.0
OS: Ubuntu 18.04

Re: Spoken GCA

Postby Hooray » Wed Mar 07, 2018 9:05 pm

my impression here is that you may be running into other places (subsystems) that don't have any addon support - under the hood, these subsystems should be using a common lookup routine that would have to be aware of the new addon system - but most (all) subsystems were obviously developed years ago, so that they may be using other means to look up the directory, which may be incompatible with addon path handling.
It would be best to identify such bugs and report them here so that we can take a look - I believe that rominet has already fixed a few of those (e.g. bindings and UI dialogs).
There's probably other places loading textures, 3D models or audio files that are still unaware of addon path handling

In the meantime you could try to raise your --log-level=bulk and see what the log file says when you try to execute the offending fgcommand
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11192
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby Hooray » Wed Mar 07, 2018 9:25 pm

Code: Select all
cd $FG_SRC && grep -nr "play-audio" *


Okay, the fgcommand is registered here: https://sourceforge.net/p/flightgear/fl ... er.cxx#l87

The underlying C++ code is this: https://sourceforge.net/p/flightgear/fl ... r.cxx#l205

You can see the path lookup code here: https://sourceforge.net/p/flightgear/fl ... r.cxx#l205

This ends up calling: https://sourceforge.net/p/flightgear/fl ... r.cxx#l223
Code: Select all
SGSoundSample *msg = new SGSoundSample(file.c_str(), path);


Thus, we need to look up the constructor of SGSoundSample() to see if it is using an addon-aware API or not.

Which gets us to this place in simgear: https://sourceforge.net/p/flightgear/si ... e.cxx#l112
Code: Select all
// constructor
SGSoundSample::SGSoundSample(const char *file, const SGPath& currentDir) :
    _is_file(true),
    _changed(true),
    _valid_source(false),
    _source(SGSoundMgr::NO_SOURCE),
    _data(NULL),
    _valid_buffer(false),
    _buffer(SGSoundMgr::NO_BUFFER)
{
    SGPath p = simgear::ResourceManager::instance()->findPath(file, currentDir);
    _refname = p.utf8Str();
}


They key line is this: SGPath p = simgear::ResourceManager::instance()->findPath(file, currentDir); (which does look good to me, so I would try the same code out of the addon directory to see if the problem is elsewhere)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11192
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby rleibner » Thu Mar 08, 2018 4:25 pm

Hooray wrote in Wed Mar 07, 2018 9:05 pm:my impression here is that you may be running into other places (subsystems) that don't have any addon support

I agree. I feel that I would like to take a break from the standalone-instruments.
I do not know anything about subsystems, but I gess I can learn.
Can you point me somewhere to take my first steps there ?
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 230
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: 2180.4.0
OS: Ubuntu 18.04

Re: Spoken GCA

Postby rominet » Thu Mar 08, 2018 5:39 pm

Hi,

Did you manage to play any sound, regardless of the location, with the 'play-audio-sample' FGCommand? It doesn't seem to work for me, even for sounds in FGData:
Code: Select all
var sound = {
  path : "/path/to/fgdata/Sounds",
  file : "gear-hrn.wav",
  volume : 1.0
};

fgcommand("play-audio-sample", props.Node.new(sound));

Besides, the only two aircraft in FGAddon using 'play-audio-sample' don't give any clue, because their code assumes the aircraft dirs are located under $FG_ROOT, which is not the case anymore since several years (therefore they are broken, so you can't use them to narrow the problem by dichotomy between a working and non-working setup) .
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby rleibner » Thu Mar 08, 2018 6:13 pm

rominet wrote in Thu Mar 08, 2018 5:39 pm:Did you manage to play any sound, regardless of the location, with the 'play-audio-sample' FGCommand?
No, I din't.
I tried $FG-ROOT and $FG-HOME without success. :cry:

My fs.log reads:
Code: Select all
sound:3:/home/rodolfo/fgfs/next/flightgear/src/Sound/VoiceSynthesizer.cxx:56:FLITE synthesis thread exiting
sound:3:/home/rodolfo/fgfs/next/flightgear/src/Sound/VoiceSynthesizer.cxx:109:FLITE synthesis thread joined OK
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 230
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: 2180.4.0
OS: Ubuntu 18.04

Re: Spoken GCA

Postby rominet » Fri Mar 09, 2018 12:41 am

Good news: 'play-audio-sample' is not broken. :)

But in order to get sound from this FGCommand, you first need to do something like this:
Code: Select all
props.globals.getNode("/sim/sound/chatter/enabled").setValue(1);

Minimal working example in an add-on (what follows is addon-main.nas):
Code: Select all
var main = func(addon) {
  var sound = {
    path : addon.basePath ~ "/sounds",
    file : "gear-hrn.wav",
    volume : 1.0
  };

  props.globals.getNode("/sim/sound/chatter/enabled").setValue(1);
  fgcommand("play-audio-sample", props.Node.new(sound));
}

Just put gear-hrn.wav or whatever you want in the 'sounds' subdir of your add-on base dir.

Note that in not-too-old versions of FG (< 1 year or so), the sound fades in at sim start, therefore if your sound sample duration is too short, you probably won't hear anything with the above example. If this is the case, take a longer sound or wait a few seconds before feeding it to 'play-audio-sample'.
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby wkitty42 » Fri Mar 09, 2018 8:32 am

that's weird... you should not have to have the chatter enabled just to hear ambient scenery sounds... i keep the chatter turned off over here because it is slower than the ATC text it is speaking and when the ATC text has finished going by, the chatter is still chattering along trying to catch up... but all craft sounds still work... this sounds like there's at least two different paths for sounds... possibly even two different commands?? play-audio-sample may be for chatter and another one for general scene sounds... i dunno but it strikes me as "off"... ahhhh, but then again, this is the Spoken GCA mod so yes, i guess it would need to follow the same path as the chatter stuff...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 4762
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Spoken GCA

Postby rominet » Fri Mar 09, 2018 9:23 am

I agree that something named in a generic way like 'play-audio-sample' but only working when /sim/sound/chatter/enabled is true sounds odd. This appears to come from flightgear/src/Sound/sample_queue.cxx:
Code: Select all
FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const std::string &refname ) :
    last_enabled( true ),
    last_volume( 0.0 ),
    _enabled( fgGetNode("/sim/sound/chatter/enabled", true) ),
    _volume( fgGetNode("/sim/sound/chatter/volume", true) )
{
    ...
}

Probably historical reasons...
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby Hooray » Fri Mar 09, 2018 2:43 pm

It should be relatively straightforward to take the existing fgcommand and adapt it to make more settings customizable (e.g. the fade-in/fade-out behavior) and register this using a new fgcommand name
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11192
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby rominet » Fri Mar 09, 2018 3:22 pm

AFAIK, the fade in effect is not added by 'play-audio-sample' per se, it is applied to every sound output at simulator startup (during the first few seconds after startup).
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby Hooray » Fri Mar 09, 2018 8:59 pm

I've been looking at fg_commands.cxx to see if there are possibly other fgcommands building SGPaths not using the addon-aware API, and I believe that fgValidatePath() and a few others may need to be checked, e.g. what about resolve_maybe_aircraft_path() ?

There are probably other places accessing the command manager to register subsystem specific fgcommands that may build paths that are unaware of addons, i.e. code accessing "SGCommandMgr"

From an I/O standpoint, addons may need to write stuff to disk, too - so could use a convention like $FG_HOME/Export/addon-id
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11192
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby rominet » Fri Mar 09, 2018 9:58 pm

For fgValidatePath(), I don't see any use because it should be called after path resolution IMO (fgValidatePath() validates paths, it is not a path resolver).

resolve_maybe_aircraft_path() already works with add-ons by using the syntax documented in README.add-ons, cf. section Resources under the add-on directory:
Code: Select all
[addon=ADDON_ID]path/relative/to/the/addon/directory

Such resource paths are precisely what
Code: Select all
addon.resourcePath("path/relative/to/the/addon/directory")

produces, when addon is an addons.Addon instance (i.e., an “add-on ghost”). BTW, this is what allows the Oscilloscope add-on to display its picture, and property-rule configuration files to be loaded from inside an add-on dir (as used in Slawek's experimental addonized version of FGCamera).

For the same reason, the 'loadxml' FGCommand and therefore io.read_properties() also work with add-on resource paths:
Code: Select all
io.read_properties(
  "[addon=org.flightgear.addons.FooBarAddon]some/subdir/test.xml",
  props.getNode("XXXtest", 1));

Edit: in such a case however, I'd rather recommend this:
Code: Select all
io.read_properties(
  addon.basePath ~ "/some/subdir/test.xml",
  props.getNode("XXXtest", 1));

because this way, FG doesn't have to crawl through all of SimGear's ResourceManager instances in order to resolve the path. addon.basePath is readily available, so this method should be faster. This recommendation would apply to every place where you have addon.basePath accessible (i.e., potentially all Nasal add-on code) and you are calling an API[1] that accepts absolute paths.

Regarding files to be written, I mostly agree, but maybe rather $FG_HOME/Export/addons/ADDON_ID in order to keep add-ons together, and separate from other stuff directly in $FG_HOME/Export.

[1] Nasal function, FGCommand...
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby Hooray » Sat Mar 10, 2018 11:51 am

I agree, having something like addon.storagePath would definitely make sense (or possibly a func/method, to make it clear that this is not lvalue).
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11192
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby rominet » Sat Mar 10, 2018 1:31 pm

Sorry, but addon.basePath is this. It is a read-only attribute (= data member) of addons.Addon as documented in README.add-ons, in the section titled Nasal API. It was designed as an attribute as opposed to a method in order to
  • be consistent with James' policy for the API of waypoint ghosts (as discussed on the list a few months ago);
  • emphasize that the value can't change for a given addons.Addon instance (it does not need to be recomputed every time you ask for it).
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

PreviousNext

Return to Nasal

Who is online

Users browsing this forum: No registered users and 2 guests