Archived

This topic is now archived and is closed to further replies.

MIDI Library *help please*

This topic is 5129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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... ^_^)

Share this post


Link to post
Share on other sites
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 )

Share this post


Link to post
Share on other sites
#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

Share this post


Link to post
Share on other sites
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);

};

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites