libgamemusic
libgamemusic

libgamemusic provides a standard interface to access different music file formats.

Structure

The main interface to the library is the getManager() function, which returns an instance of the Manager class. The Manager is used to query supported music formats, and for each supported file format it returns an instance of the FormatType class.

The FormatType class can be used to examine files and check what file format they are in, and if they are in the correct format, to open them. Successfully opening a music file produces an instance of the Music class. The MusicType class can also be used to create new music files from scratch, which will again return a Music instance.

Reading and writing files through the Music class is done with lists of "events", such as note-on and note-off. These events are transparently converted to and from the underlying file format by the Music class.

Examples

The libgamemusic distribution comes with example code in the form of the gamemus utility, which provides a simple command-line interface to the full functionality of the library.

For a small "hello world" example, try this:

#include <iostream>
using namespace camoto;
using namespace camoto::gamemusic;
int main(void)
{
// Get hold of the Manager class
ManagerPtr manager = getManager();
// Use the manager to look up a particular music format
MusicTypePtr musicType = manager->getMusicTypeByCode("cmf-creativelabs");
// Open a music file on disk
file->open("funky.cmf");
// We cheat here - we should check and load any supplementary files, but
// for the sake of keeping this example simple we know this format doesn't
// need any supps.
// Use the format handler to read in the file we opened.
MusicPtr song = musicType->read(file, supps);
// Find out how many instruments (patches) the song has.
std::cout << "There are " << song->patches->size()
<< " instruments in this song.\n";
// Look through the tags to see if there's a title present.
Metadata::TypeMap::iterator i = song->metadata.find(Metadata::Title);
if (i == song->metadata.end()) {
std::cout << "This song has no title.\n";
} else {
std::cout << "This song is called: " << i->second << "\n";
}
// No cleanup required because all the Ptr variables are shared pointers,
// which get destroyed automatically when they go out of scope (and nobody
// else is using them!)
return 0;
}

When run, this program produces output similar to the following:

There are 13 instruments in this song.
This song is called: Jill of the Jungle - Funky

More information

Additional information is available from the Camoto homepage http://www.shikadi.net/camoto.