PDA

View Full Version : play midi file from memory, is it possible?



noeska
03-05-2003, 09:48 PM
For my game i store all game data in an archive i use tmemorystream to access files from it. For the moment i use tmediaplayer for playing midi files but that requires me to write the tmemorystream with the midi data to the disk and play that and delete the file afterwards. Is there a way i can play a midi file directly from a tmemorystream?

DooMeeR
01-06-2003, 05:25 PM
I don't know if it'll help, but i wrote a midi unit which is not done and will never be, but it contains a class that allow you to play midi events. I think there is a midi file loader too, but I used it to build a midi editor and it cannot load other midi files because they have midi events that are unknown to my unit (but it could be easily fixed if you know midi format).

Well. Here is a link to the source of the midi editor: http://www.doomeer.com (direct link: http://www.doomeer.com/progs/midedsrc.zip ). The midi unit is midi.pas. The editor is given as an example ;)

I guess you could find better midi units somewhere else.

noeska
01-06-2003, 06:39 PM
Thanks, i have a look at it!

Mrwb
26-06-2004, 02:28 PM
Has anyone found a way to do this? (Non-VCL)

I've been trying to do this for quite some time now, and the last 10-12 hours I've been reading SDK documentation over and over again while experimenting. I can't get it right though. Im using .res files to store the midi, and load it like this: (which works fine)



SoundRes:=LoadResource(0,FindResource(0,'music','M IDI'));

Anyway, I can't figure out a way to use the memory handle (SoundRes) to play the midi. The code I currently have, loads the file using mciSendCommand(); with SoundRes assigned to the lpstrElementName of the MCI_OPEN_PARMS structure. The code doesn't throw any errors, it simply doesn't work. I have also tried using the MidiOut out stuff instead.

Paulius
26-06-2004, 04:17 PM
Being able to play from a file and not doing it from memory defies logic but if this functionality exists in Win API it is well hidden, an ugly bypass would be to write you're midi to disk and delete it later like in a 64k intro on sulaco

Mrwb
26-06-2004, 05:24 PM
Yeah, that was what I was doing until I thought I'd try to do it directly to avoid the VCL. Guess I can write the file without the VCL as well though.
Either way I have totally given up trying to do it from memory.

It seems as though the possibility is there, since the SDK documentation on the MCI_OPEN_PARMS structure describes the lpstrElementName as following: "Device element (often a path)" the "often a path" possibly indicates that you can use something other than a path, IE a memory handle or something.