Advertisement Jump to content
Sign in to follow this  

Making a file format?!

This topic is 4884 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

I am making this piano program in c++ using the beep() function, and i am trying to figure out a way to record it, and to save it in a midi file format or making my own format. My question is how would you record what are you typing into the program. If anybody can help me i would appreciate it

Share this post

Link to post
Share on other sites
1) You need to understand the midi file format. Only the documentation on the file can help you there. If however, the song is to only be played back in your own software - the its quite possible to make your own file format.

2) For the basic recording of the tune, each note played would have to be recorded each time it played. I suppose you could have a simple structure for a note...

struct TYP_NOTE
int time; // stores the time that the note was played
int type; // with a vast number of different notes, it helps to state which kind it was...
}; now we have a Note to play with. And afterthat you would require a timeline...

int startTime; // Although most songs start from 0, you can specify where in the song to start...
int currentTime; // The current play position
int endTime; // When the song finishes...
bool state; // Playing, stopped, Pause etc

...and now you have a timeline to attach the notes onto. Obviously, one can see the need for a linked list to manage the notes( I'll leave that up to you ), but the real issue here is putting those notes into a file.

A file usually comes with two sections; A file header, and the data.

The file header is usually a structure containing basic information of the file...

int numberOfNotes;
int sizeOfSingleNote;
char[256] nameOfAuthor;
}; first you write your header to the file. Once thats in there, you can write each note to the file as well. This is done by basically reading each one from the linked list and storing them into the file one-by-one( in the order that they are played in of course! ).

So in the end, it comes down to linked lists and basic file I/O.

Best of luck.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!