MIDI Library *help please*

Started by
8 comments, last by Huangdi 20 years, 4 months ago
Hi guys! This is my first post, glad to be here! Sry my first post is asking for help :/ Anyways, I''m making a computer game with a group of friends. Since we don''t know much about programming, we decided to make it text-based at first, and then convert to 2d graphics, or even to 3d, we''ll see as time goes on... What''s nice about this fairly basic text-based RPG is that all the data for the world, monsters, etc. are stored in .txt files, so you can change them on the fly. Right now, I''m trying to add MIDI sound to the game. However, I don''t know how... I''m programming in Borland C++ 5.02. Is there a MIDI Library that I can include for this purpose? I don''t need a lot of functions, I just want to be able to control what it plays, and whether it repeats or not, like PlaySound(). What I evision is just including the library, and calling the function like PlaySound does. Something simple, I''m just a beginner. Thanks for your help! (BTW, the URL is www.geocities.com/djdcpp/Temple43.zip Newer editions will be Temple44.zip, Temple45.zip, etc. Thanks for checking it out! Suggestions greatly appreciated. The world is not even close to complete; it''s just a test world.)
Advertisement
Windows has some functions for this. lookup mciSendString etc.
If you don''t like them (for I don''t) you can use a library like fmod, fmod is free as long as you don''t make any money with your game.

My Site
Ok, thx.

I downloaded FMOD, but how do I use it to play a MIDI file? Remember, I am a n00b. Can you give me a simple example please (complete code)?

Pretend that I want to create a program to run the MIDI file "Music.MIDI". what would I do?
At the moment, I can''t get sound at my computer, so I can''t test it, but I think this should work:

at the beginning of your program, to init fmod:

FSOUND_Init(44100, 32, 0);

then, if you want to play a song:
FMUSIC_MODULE *song = FMUSIC_LoadSong("c:\\song.mid");
FMUSIC_SetLooping(song,true); // enable looping
FMUSIC_PlaySong(song);

and when you''re ready, stop and free the song:
FSOUND_StopSong(song);
FSOUND_Close();

remember that you have to #include <fmod.h> and that you should link with the fmod library. You can find this library in the fmod\api\lib\ folder. Which one you need depends on your compiler, but that''s obvious.
You also need to put the fmod.dll file in the same folder as your program, or in the windows\system folder

My Site
I included the "fmod.h" and also put the fmodbc.lib into my Library folder, and put the dll into the same folder as my program. It''s having link errors: Unresolved external FSOUND_Init referenced from ... I have never linked stuff before. What am I doing wrong? How do you link stuff for Borland C++? (I feel so stupid... ^_^)
you actually need to LINK the lib to ur program, ive never linked to a lib through the text, since im a bastard with microsofts vc++ so i dont need to put it in the source code, but anyways, i saw earlier something like

#pragma comment( lib, [library].lib)

although i woulda thought that

#include <[library].lib> woulda worked, dont ask me though

(btw, replace [library] wit hthe library name :-D )
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
#including a library certainly won''t work. afaik that #pragma way is also microsoft, but I''m not sure about that. You can try it.

In most ide''s(the editor) there''s an options dialog in which you can set the libraries you want to link with. Look for project options or something. I don''t know borland c++ though, so maybe someone who knows it can help you.


My Site
Thanks for your help guys! #pragma comment worked! ^_^

Sorry for replying so late, my internet service went down...

However, this piece of code doesn''t work... it won''t take strings... If I change it to FMUSIC_LoadSong("C://song.mid") it works...

void Music(tAll &all, string Play, bool Repeat)
{
FMUSIC_StopAllSongs();
FMUSIC_MODULE *song = FMUSIC_LoadSong(Play); //<--bug!
if(Repeat==true)
FMUSIC_SetLooping(song,true); // enable looping
else
FMUSIC_SetLooping(song, false);

FMUSIC_PlaySong(song);

};
Hey,
You''ll need to put:
FMUSIC_MODULE *song = FMUSIC_LoadSong(Play.c_str());

tj963
tj963
Wow, I love this forum! Quick and direct replies!

Can you please explain what you did and why it works? I would like to learn for future reference. BTW, IT WORKED GREAT!

I tried to sign up for Computer Programming AP at our school, but they canceled the class due to class size (too few people). Makes me mad, grr... So now i''m learning by myself. Hopefully I will soon know lots and can repay you guys for your awesome help!

This topic is closed to new replies.

Advertisement