Play Multiple sounds in parallel

 

Hi

I wrote a very simple indicator that should play a sound when a new bar is opened, this indicator is meant to be used on renko charts. Now, I want to have two renko charts and one instance of this indicator on each (two renko charts because two box sized), at the same time, I have another expert that only plays sound when a trade is closed.


Problem is, many many times, these sounds fall on top of eachother, for example, a new renko box is created and exactly few milliseconds later or sooner, a trade will be closed, in these situations, I only here one of the sounds (the one that happens last).


Is there a way to make MT5 play all the sounds without cutting one of them?

 
Alireza Khodakarami:

Hi

I wrote a very simple indicator that should play a sound when a new bar is opened, this indicator is meant to be used on renko charts. Now, I want to have two renko charts and one instance of this indicator on each (two renko charts because two box sized), at the same time, I have another expert that only plays sound when a trade is closed.


Problem is, many many times, these sounds fall on top of eachother, for example, a new renko box is created and exactly few milliseconds later or sooner, a trade will be closed, in these situations, I only here one of the sounds (the one that happens last).


Is there a way to make MT5 play all the sounds without cutting one of them?

build your own queue and place a delay between each one long enough for the sound to complete

 
Paul Anscombe:

build your own queue and place a delay between each one long enough for the sound to complete

I'm already trying the Sleep command, problem is, I will have multiple instances of the same indicator on multiple charts and sometimes, they will try to play sounds with milliseconds difference. I'm using winmm dll right now, playing the sounds with ASYNC mode, it helps a little bit but still some of the sounds gets masked when the market moves fast (for example the sound of closing of a position will get masked because of the sound of new bar indicator on another chart!)

question is, without trying our own hand on custom dll for threading the play sound, is there a way to play the sound on a separate thread each time?

 
Alireza Khodakarami:

I'm already trying the Sleep command, problem is, I will have multiple instances of the same indicator on multiple charts and sometimes, they will try to play sounds with milliseconds difference. I'm using winmm dll right now, playing the sounds with ASYNC mode, it helps a little bit but still some of the sounds gets masked when the market moves fast (for example the sound of closing of a position will get masked because of the sound of new bar indicator on another chart!)

question is, without trying our own hand on custom dll for threading the play sound, is there a way to play the sound on a separate thread each time?

no

 
Alireza Khodakarami: they will try to play sounds with milliseconds difference. … is there a way to play the sound on a separate thread each time?
Put a mutex around each play.
          Prevent EA from opening trades at the same time across two or more pairs? (Steve) - MQL4 programming forum 2016.06.21
 
William Roeder:
Put a mutex around each play.
          Prevent EA from opening trades at the same time across two or more pairs? (Steve) - MQL4 programming forum 2016.06.21

Did I get it right? Is this the equivalent of locking an object in C# and then calling thread actions?

Like this?


Mutex.Lock()

PlaySoundW(..)

Mutex.Release()


???

Also, your file is using 4 different custom header files that you never provided? I would appreciate if you help with a complete solution. thanks

By the way, there are two conditions like this :

if(!IsTradeContextBusy() && GlobalVariableSetOnCondition(mName, 0, 1))


both of them are checking IsTradeContextBusy, do I really need it? because all i'm doing is playing a sound and I don't think this condition would do anything there for me


One more thing, I don't think using a Mutex is the solution I am looking for, the mutex will eventually stop other instances from playing any sound until the first instance is done. What I am looking for, is the ability to play all sounds at the same time without one covering the other one (silencing the other one)

 
Alireza Khodakarami: What I am looking for, is the ability to play all sounds at the same time without one covering the other one (silencing the other one)

If they are not “covering the other one,” then they are not playing “at the same time. ” “A Mutex is the solution I am looking for.”

 
William Roeder:

If they are not “covering the other one,” then they are not playing “at the same time. ” “A Mutex is the solution I am looking for.”

I didn't have the header files you used in your file, just found another mutex in the code section or forums (don't remember), but, I DON'T want them to COVER each other not the other way around

Reason: