Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm gonna write me a synth.
(well, tweak existing synth code for my own nefarious purposes)

I already have a midi sequencer app. (that edits notes and such)

And I'd like the synth to be a seperate .exe since it's a different sort of beast and would be nice to have runnin on another core, etc.

So now i gotta come up with the best way to send midi bytes
(and load c:\THISpiano.patch messages, etc, etc)
from the sequencer .exe to the synth .exe

I guess memory mapped files are the windows way, eh?
Sequencer app opens mem mapped file and writes to shared mem.
Synth app opens same mem mapped file and reads from shared mem.

Anybody got any other hi performance techniques for inter process talkin on windows - especially by a native c++ app?

thanks mucho!

...Steve


Actually, while I'm at it here, if I DO use mem mapped files,
is there a way for me to WAIT and not spin in a busy loop looking
constantly for any change in shared mem?

It'll be in a busy loop ANYway when there are ANY notes on.
But when things are silent (notes/voices are all off)
it could be nicer to the cpu.
Posted
Updated 29-Sep-10 6:22am
v2

You could use TCP/IP sockets. that's probably the best way in terms of performance...
 
Share this answer
 
v2
Comments
stephen.hazel 29-Sep-10 12:54pm    
well, the sequencer and synth are guaranteed to be on the same box.
so i'd =think= there'd be a more direct way than sockets, eh?
hmmm...
Well, I haven't done any of this in some time, but did you consider using this
http://msdn.microsoft.com/en-us/library/ms649009(v=VS.85).aspx[^]?
 
Share this answer
 
Comments
stephen.hazel 29-Sep-10 12:57pm    
I think this uses mem mapped files per Jeff Richter's book.
But it does send a message and I need some way for this
to be message based. I wonder if there's some way to wait on a mem mapped file change.
I know there's a way to wait on regular os file changes..
well, time to go hit ole msdn again :/
hey me,

you could add the synth code on a seperate thread.
that'd let it run on a seperate core AND be message based.
(thread's msgloop)

BUT you'ld have to compile your big ole
sequencer+synth .exe with all the
float startup/support code in clib.

And you really don't want to have to have that included
in your midi sequencer if you don't have to.

So keep your midi sequencer float free in a sep .exe
and the synth (which HAS to have floats) in a sep .exe

so, ok, yeah, stick with the 2 .exes i guess, me...

...me
 
Share this answer
 
ok, me, i think i got it.

midi sequencer boots up, opens memmapped file that both sequencer.exe and synth.exe know of and sticks it's thread id (seq_thrd) at offset 0.

When sequencer loads song, if song needs synth.exe, boots it up.
(Maybe song uses a hardware synth instead of synth.exe or whatever)

synth.exe opens same memmapped file, puts it's thread id (syn_thrd) at offset 4, gets seq_thrd from offset 0
and does a PostThreadMessage(seq_thrd) of "I'm ready to go - use me" to sequencer.exe

As sequencer.exe needs synth to do stuff, it uses rest of memmapped file as a queue and does a PostThreadMessage(syn_thrd, queuePos)

synth.exe is waiting in it's msgloop, wakes up, and reads that pos, uses it, and does a PostThreadMessage(seq_thrd, queuePos) to tell seq it can reuse that pos
(1st ulong of message in queue will have length, etc)


Now to test and see if this way of doin stuff WERKS.
I'm not yet sure that PostThreadMessage() will work across processes.
But I'm hoping it does.


If anybody sees any holes in this plan, please let me know sooner rather than later :)
 
Share this answer
 
Comments
stephen.hazel 29-Sep-10 18:08pm    
Wow Steve, that works pretty darn good!
I can't imagine a better way to share memory across processes than windows shared memory.
And I can't imagine any faster way to message than PostThreadMessage (it does work across processes, BTW).


So I think I'm set, Steve - thanks again for your help!

(ok, sorry for annoyin' everyone, but when things WORK, it's a good day!!)
stephen.hazel 29-Sep-10 18:11pm    
How come I can't #Quote#accept#Quote# my own answer ??
Hmmmmmmm..........
Ok, this is what pipes were made for, or you could use a shared memory mapped file, or if you could use a DLL with a shared memory block, or you could just use the windows messaging system.
Just about any of the above will work. i have personally used a DLL with a shared memory block and that worked really well, also i have used windows messages and those also work well, and i have done a little messing around with memory mapped files but not with/for shared memory, but i have not used pipes that doesn't mean that they aren't good.
 
Share this answer
 
Comments
stephen.hazel 30-Sep-10 0:39am    
shared memory = memory mapped file - an actual file (uses sys paging file).
I've got a test program and storing the threadids in a memory mapped file (minus file:) and PostThreadMessage()ing works great. and is about as fast as you can possibly get.

and i'm pretty sure than any equivalent solution will use these things underneath (like pipes, dll shared mem block, etc)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900