Sound and Macro question

#1
My task is to have a controller articulate a plane's atc _id.
Using Doug's sound setup, I can pass a literal value to a macro that plays a sound, like so:

Code:
<Macro Name="playsound">1 (>L:mysounds_@, number></Macro>
...
@play(helloworld)   //plays mysounds_helloworld.wav
@play(1)                 //plays mysounds_1.wav  ("one")
@play(Z)                 //plays mysounds_Z.wav ("zulu")
This, as you know, works just fine. Now what I want to get is to make the macro capture a value from an Lvar, like so

Code:
1 (>L:myvar, number)
@play((L:myvar, number))   // to play play mysounds_1.wav; but doesn't work
I could of course make it conditional like ...

Code:
(L:myvar, number) 1 == if{ @play(1) }
(L:myvar, number) 2 == if{ @play(2) }
...
(L:myvar, number) 65 == if{ @play(A) }
...
(L:myvar, number) 90 == if{ @play(Z) }
... but at what a horrible waste of space and time. Any ideas for a more efficient solution?
 
Last edited:

taguilo

Resource contributor
#2
This example is a bit tricky but helps to reduce source code.

Code:
<Macro Name="Play">l0 @1 == if{ 1 (>L:mysounds_@2, number) }</Macro>
...
(L:myvar, number) sp0
@Play(1,sound1) @Play(2,sound2) @Play(3,sound3) @Play(65,A) @Play(90,Z) ....etc
Tom
 
#3
Thanks Tom, but I'm not sure I get it. Maybe too complicated for me...

Say atc_id is N1024A
Say I want my controller to pronounce the last digit, ie "A" or "Alpha".
I isolate the last digit and put 65 to L:myvar (because ord(A) is 65).
So far so good. But from there how do I get my code to execute "@play(65,sound65)" ?
The first parameter is variable, but sound65 is not. How to get the 65 (or any other value!) into the "soundXX" of the macro call?
 
Last edited:

taguilo

Resource contributor
#4
Ah ok, you need to play SOUND65, and you use ascii codes for alphabet chars, then even simpler:

Code:
Macro Name="Play">l0 @1 == if{ 1 (>L:SOUND@1, number) }</Macro>
(L:myvar, number) sp0
@Play(65)
Code is internally translated to

Code:
(L:myvar, number) sp0
l0 65 == if{ 1 (>L:SOUND65, number) }
You'll have to repeat @Play() macro for every alphabetic character related to a sound.
ie

Code:
@Play(65)     <!-- Alpha -->
@Play(66)     <!--  Bravo --> 
@Play(67)     <!--  Charlie) -->
@Play(68)     <!--  Delta) -->
etc

Tom

.
 
#5
Well, apart from the sp0/l0 bit this is basically what I had in my initial post. The crux is the condition "l0 xx == if{ 1 (>L:SOUNDxx, number) }" because it has to be tested for the whole range 48..57 and 65 ..90, i.e. the ten digits and the 24 letters. Can be done, maybe must be done, but it's precisely what I wanted to avoid ...
 
#6
I don't know enough about application of Doug's sound gauge to be helpful, I fear, but is this simply an issue about dynamically (on the fly) creating a variable name that has an arbitrary number - like the ascii code of a string character - appended to the var name?

If so, then XMLVARS can be used to create such a var name:

'Sound' Ord(A) scat (>C:XMLVARS:StoreVarName, string), where Ord(A) is your script that isolates the desired string character and returns its ascii number. In your example, it would create the XMLVAR name 'Sound65'

Does this help? Hope so.

Bob
 
#7
Thanks Bob, looks promising.

I don't know enough about application of Doug's sound gauge to be helpful, I fear, but is this simply an issue about dynamically (on the fly) creating a variable name that has an arbitrary number - like the ascii code of a string character - appended to the var name?
Exactly.

If so, then XMLVARS can be used to create such a var name:

'Sound' Ord(A) scat (>C:XMLVARS:StoreVarName, string), where Ord(A) is your script that isolates the desired string character and returns its ascii number. In your example, it would create the XMLVAR name 'Sound65'
OK. Since L:myvar already has the ord number, I guess one would write this as

Code:
'Sound' (L:myvar, number) chr scat (>C:XMLVARS:StoreVarName, string)
But, on reflection, as a matter of fact, Doug's gauge already creates the variables named sounds48 thru sounds90, via an .ini file, ready to be used. Anyway I'll see what gives. Haven't used XMLVARS so far. Must read up...
 
#9
OK. Since L:myvar already has the ord number, I guess one would write this as

Code:
'Sound' (L:myvar, number) chr scat (>C:XMLVARS:StoreVarName, string)

Pretty close. If you've already applied the ord operator, drop the chr:

Code:
'Sound' (L:myvar, number) scat (>C:XMLVARS:StoreVarName, string)

I understand this application of XMLVARS might not end up being helpful with Doug's sound gauge, but otherwise, the importance and usefulness of dynamic variable names and dynamic variable name arrays is hard to overstate. There are several tools in Tom Aguilo's XMLTOOLS that I use regularly; XMLVARS is at the top of my list.

Bob
 
Last edited:

taguilo

Resource contributor
#11
Well, apart from the sp0/l0 bit this is basically what I had in my initial post. The crux is the condition "l0 xx == if{ 1 (>L:SOUNDxx, number) }" because it has to be tested for the whole range 48..57 and 65 ..90, i.e. the ten digits and the 24 letters. Can be done, maybe must be done, but it's precisely what I wanted to avoid ...
Despite Bob's good intentions to provide something to test, there is no other simple way to do that than the example I provided.

Unfortunately LVar names must be written literaly for the parser to recognize them. You cannot use variable values appended to part of an LVar's partial name to conform a complete name.
Anyway, if you need to repeat , for example @Play(n) 100 times, I see no big problem to that. Just copy/paste/update each macro call in a different line to improve readability. Cost in FPS will be nil, not visually observable.

Tom
 
Top