Sign in to follow this  
jspan_com

C++ Callout Gauge problem

Recommended Posts

Hi All,I am working on a C++ callout (sound) gauge. This gauge does not use mouse clicks, but is only intended to play sounds at specific events. The code used here is modified from another gauge using mouse clicks and that's perhaps the problem? The sound does come up, but plays in an endless loop!Here are extracts from the code://--->// --------------------------------------------------------------------------// icons set to OFF or zero value// --------------------------------------------------------------------------UINT32 gearup = 0;// --------------------------------------------------------------------------// callbacks for the icons// --------------------------------------------------------------------------FLOAT64 FSAPI gear_cb(PELEMENT_ICON);// --------------------------------------------------------------------------// main gauge callback// --------------------------------------------------------------------------void FSAPI callout_cb(PGAUGEHDR, int, UINT32);// --------------------------------------------------------------------------// local variables// --------------------------------------------------------------------------char callout_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER callout_list;extern MOUSERECT callout_mouse_rect[];// --------------------------------------------------------------------------// this variable will hold the actual width of the gauge; //needed in some mouse callbacks// --------------------------------------------------------------------------double width;// --------------------------------------------------------------------------// variables/definitions for the sound buffers:// sound files in FS Sound folder// --------------------------------------------------------------------------MFSSoundFileVars(gear_sound, "SOUNDJSATR_gear.WAV");// --------------------------------------------------------------------------// MODULE IMPORT AND EXPORT DEFINITIONS// --------------------------------------------------------------------------GAUGE_HEADER_FS700(GAUGE_W, callout_gauge_name, &callout_list, callout_mouse_rect, callout_cb, 0, 0, 0 );// --------------------------------------------------------------------------// DRAWING ELEMENTS DEFINITIONS// --------------------------------------------------------------------------MAKE_ICON( gear, CALLOUT, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | IMAGE_HIDDEN, 0, 0, 0, MODULE_VAR_NONE, gear_cb, ICON_SWITCH_TYPE_SET_CUR_ICON, 1, 0, 0)// --------------------------------------------------------------------------// link the drawing elements to the background// --------------------------------------------------------------------------PELEMENT_HEADER callout_plist1[] = { &gear.header, NULL};MAKE_STATIC( callout_background, CALLOUT_BACKGROUND, &callout_plist1, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE |IMAGE_HIDDEN, 0, 0,0)PELEMENT_HEADER callout_list = &callout_background.header;// --------------------------------------------------------------------------// RESET VARS TO ZERO - MODULE Vars// --------------------------------------------------------------------------UINT32 Plane = 0;UINT32 Ground = 0;UINT32 Alt = 0; //Radio AltitudeUINT32 AltCheck = 0;UINT32 Down = 0;UINT32 Gearup = 0;MODULE_VAR landed = {AIRCRAFT_ON_GROUND};MODULE_VAR gearpos = {GEAR_POS_LEFT}; MODULE_VAR PHeight = {RADIO_HEIGHT};MODULE_VAR GHeight = {GROUND_ALTITUDE};// --------------------------------------------------------------------------// DRAWING ELEMENT CALLBACKS// --------------------------------------------------------------------------// icon callbacksFLOAT64 FSAPI gear_cb(PELEMENT_ICON pelement) { FLOAT64 val=pelement->source_var.var_value.n; lookup_var(&gearpos ); lookup_var(&PHeight ); lookup_var(&GHeight ); lookup_var(&landed ); Down = (int)((double)landed.var_value.n); Plane = (int)((double)PHeight.var_value.n); Ground = (int)((double)GHeight.var_value.n); Ground = Ground/256; Gearup = (int)((double)gearpos.var_value.n); Alt = Plane - Ground; Alt = (int)((double)Alt * 3.28083989501312);//Check that aircraft is below 400 feet if (Alt < 400) { AltCheck = 1; }//If aircraft has landed then reset the altitude check if (Down == 1) { AltCheck = 0; }// Play altitude callout if (Gearup == 0 ) { Gearup = 1 ; } else { Gearup = 0 ; } MFSSoundFilePlay(gear_sound, FALSE); return FALSE;}// --------------------------------------------------------------------------// MAIN GAUGE CALLBACK// --------------------------------------------------------------------------void FSAPI callout_cb(PGAUGEHDR pgauge, int service_id, UINT32 extra_data) { switch(service_id) { case PANEL_SERVICE_POST_INSTALL: // sounds need to be registered before they can be played MFSSoundFileRegister(gear_sound); break; case PANEL_SERVICE_PRE_INITIALIZE: // save the actual with of the gauge width = ((PELEMENT_STATIC_IMAGE)pgauge->elements_list[0]) ->image_data.final->dim.x; break; case PANEL_SERVICE_PRE_UPDATE: /* "pre_update_routine()"*/ break; case PANEL_SERVICE_PRE_DRAW: /* "draw_routine()"*/ break; case PANEL_SERVICE_PRE_KILL: // never forget to unregister the sounds MFSSoundUnregister(gear_sound); break; }}// --------------------------------------------------------------------------// MOUSE SPECIFIC DEFINITIONS// --------------------------------------------------------------------------MOUSE_BEGIN(callout_mouse_rect, HELP_NONE, 0, 0)MOUSE_END// --------------------------------------------------------------------------// CLEAN UP// --------------------------------------------------------------------------#undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_W//--->I would indeed appreciate help on this one!Best regardsJan H. Sorensen

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Of course it loops, any image callback function is called 18 times per sec, so your playing sound code is called each time. You have to call your sound the time you need it, not every time. P.S. I would use the gauge callback function to call sounds (e.g. while PANEL_SERVICE_PRE_UPDATE is valid), not in an image callback, you still have to check if the condition is right to play, otherwise it's played in a loop as in your example.Arne Bartels

Share this post


Link to post
Share on other sites

To play the sound only once, you need to set a "flag" variable, check for that variable, and then change the status for the "flag" variable.Here is a callback that will play the appropriate sound *once* whenever the rotary test switch is turned to those positions:FLOAT64 FSAPI callback4( PELEMENT_ICON pelement){FLOAT64 rwert=pelement->source_var.var_value.n;rwert = (float)test_rotary ; if ( rwert > 9 ) { test_rotary = 0 ; } if ( rwert < 0 ) { test_rotary = 9 ; } if ( test_rotary == 0 ) { test1 = 1 ; test2 = 1 ; test3 = 1 ; } if ( test_rotary == 1 && test1 == 1 ) { test1 = 0 ; (GaugePlaySound)("soundESDGitt_warn.wav","",0) ; } if ( test_rotary == 2 && test2 == 1 ) { test2 = 0 ; (GaugePlaySound)("soundESDGgearhorn.wav","",0) ; } if ( test_rotary == 7 && test3 == 1 ) { test3 = 0 ; (GaugePlaySound)("soundESDGoverspd.wav","",0) ; } if ( test_rotary == 9 ) { test = 1 ; } return rwert;}The three "flag" variables I've used are test1, test2, and test3. Note that the first thing done is to set the testx variable to 0 (false), then play the sound. Because the testx variable is now 0, the "if" statement ends, and there is no looping.Simple, no? :)

Share this post


Link to post
Share on other sites

Thank you both for the replies, I will test these options. This gauge is setup using the MSFSSound routines by Daniel Steiner, and I have tried to setup the callback functions in PANEL_SERVICE_PRE_UPDATE. Now, the sound is playing when the condition are met, but still looping. But I will investigate this one further.The FLOAT64 FSAPI callback is absolutely interesting! I noticed this line:--->if ( test_rotary == 1 && test1 == 1 ) { test1 = 0 ; (GaugePlaySound)("soundESDGitt_warn.wav","",0) ; }--->The statement (GaugePlaySound) will be tested, but I guess that means that I have to leave the MSFSSound concept?Best regardsJan H. Sorensen

Share this post


Link to post
Share on other sites

The point is, that the calling of the sound function is within the if statement, which one GaugePlaySound, or MFSSoundFilePlay that's up to you.So it's if ( AltCheck && Gearup && test1) { test1 = 0 ; GaugePlaySound("soundESDGitt_warn.wav","",0);}orif ( AltCheck && Gearup && test1 ) { test1 = 0 ; MFSSoundFilePlay(gear_sound, FALSE);}You have to unset test1 (test1=0) somewhere to allow playing the sound again (above 400ft while climbing or so).Arne Bartels

Share this post


Link to post
Share on other sites

Hi Arne and Bill.Thanks again for your help! Well, for me it's not so simple! Unfortunately the sound loop is still there. Here's what I have done so far:Global UINT's and Vars (in the main c file)://--->UINT32 Plane = 0;UINT32 Ground = 0;UINT32 Alt = 0;UINT32 AltCheck = 0;UINT32 Down = 0;UINT32 Gearup = 0;UINT32 gearwarn = 0;UINT32 gearflag = 0;MODULE_VAR landed = {AIRCRAFT_ON_GROUND};MODULE_VAR gearpos = {GEAR_POS_LEFT}; //0 = up, 16K = dn MODULE_VAR PHeight = {PLANE_ALTITUDE};MODULE_VAR GHeight = {GROUND_ALTITUDE};/-->The gear warning callback in the Callout.c:FLOAT64 FSAPI gear_cb(PELEMENT_ICON pelement) { FLOAT64 gearwarn=pelement->source_var.var_value.n;lookup_var(&gearpos );lookup_var(&PHeight );lookup_var(&GHeight );lookup_var(&landed );Down = (int)((double)landed.var_value.n);Plane = (int)((double)PHeight.var_value.n);Ground = (int)((double)GHeight.var_value.n);Ground = Ground/256;Gearup = (int)((double)gearpos.var_value.n);Alt = Plane - Ground;Alt = (int)((double)Alt * 3.28083989501312);if (Alt < 500) AltCheck = 1 ; //Check that aircraft is below 500 feetif (Down = 1) AltCheck = 0; //If aircraft has landed then reset the altitude checkgearwarn = (float)Gearup ; if ( gearwarn > 1 ) { Gearup = 0 ; } if ( gearwarn < 0 ) { Gearup = 1 ; } if ( Gearup == 0 ) { gearflag = 1 ; }if ( Gearup == 1 && gearflag == 1 ) { gearflag = 0 ; }if ( Gearup == 0 && Alt < 500 && gearflag)gearflag = 0 ;GaugePlaySound("soundJSATRJSATR_gear.wav","",0);return Gearup; }//--->The TGaugePlaySound is set up with the sound declaration and in the Main Gauge Callback and should work. There are no error or warning messages during compilation or build.Best regardsJan H. Sorensen

Share this post


Link to post
Share on other sites

Of course it still loops, you haven't changed anything when the sound function is called. Still not within an if statement, still played 18 times per sec. You really read my post?Arn Bartels

Share this post


Link to post
Share on other sites

if ( Gearup == 0 && Alt :)

Share this post


Link to post
Share on other sites

Hi Bill,Thank you for the tip, I will check that out ASAP. I have BTW reworked the code by using the Token Var {RADIO_HEIGHT}. I will draw a new Flow Diagram and try to figure out all the pointers, there are still quite a few :). It's easy to get a broken link here and there! I will come back to you later with the result of this.Another thing which might make things more complicated: This FS2002 gauge has still subgauges using FSSound.dll. I will therefore rework all sub's to use the TGaugePlaySound concept. Otherwise I am using Visual C ++ 6.0 STD (SP5) and the FS2K2Gauges.h (243 KB) with the timestamp 11JULY 2002 13:02.Best regardsJan H. Sorensenhttp://www.jspanels.com/images/logo_small.gifHomepage: http://www.jspanels.com

Share this post


Link to post
Share on other sites

Is this code for FS2004? Is there something similar for FS2002?

Share this post


Link to post
Share on other sites

ATT: ryanloganThe code used here is compiled and built using the FS2002 SDK. The gauge can also be used in FS2004. The code was earlier setup with the MSFSSound routines by Daniel Steiner, refer to the "FS2000 and CFS Gauge Creation" document by Dai Griffiths. I have also tested this code with FS2004 Gauges.h and it seem to work, but not tested extensively.When converting the code to use the "TGaugePlaySound" concept I could remove the links to fssound_msvc.lib and dsound.lib in Visual C ++ 6.0 Object/Library (modules). By doing this you will be able to compile & build gauges with sound(s) which not are dependant of FSSound.h and FSSound.dll (which has to be resident in FS2XXmodules).Best regardsJan H. Sorensenhttp://www.jspanels.com/images/logo_small.gifHomepage: http://www.jspanels.com

Share this post


Link to post
Share on other sites

I know this is an old post, but could someone help me here?BTW Why doesn't HTML work? It says HTML use enabled. (UBB doesn't work either.)

Share this post


Link to post
Share on other sites

ATT: Kd527In Dai Griffiths' latest Gauge Tutorial (rev. 17) - sd2gau17.zip you can find complete source code for Panel Switches with sound.Regarding the forum problems, check out "Help for the AVSIM Forums" above, it might be problems related to cookie or security settings in your Internet Browser.Best regardsJan H. Sorensenhttp://www.jspanels.com/images/logo_small.gifHomepage: http://www.jspanels.com

Share this post


Link to post
Share on other sites

Sorry about not replying promptly. Where can I get "sd2gau17.zip"?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this