+SoundFile* load_music_file(const std::string& filename)
+{
+ lisp::Parser parser(false);
+ const lisp::Lisp* root = parser.parse(filename);
+ const lisp::Lisp* music = root->get_lisp("supertux-music");
+ if(music == NULL)
+ throw std::runtime_error("file is not a supertux-music file.");
+
+ std::string raw_music_file;
+ float loop_begin = 0;
+ float loop_at = -1;
+
+ music->get("file", raw_music_file);
+ music->get("loop-begin", loop_begin);
+ music->get("loop-at", loop_at);
+
+ if(loop_begin < 0) {
+ throw std::runtime_error("can't loop from negative value");
+ }
+
+ std::string basedir = FileSystem::dirname(filename);
+ raw_music_file = FileSystem::normalize(basedir + raw_music_file);
+
+ PHYSFS_file* file = PHYSFS_openRead(raw_music_file.c_str());
+ if(!file) {
+ std::stringstream msg;
+ msg << "Couldn't open '" << raw_music_file << "': " << PHYSFS_getLastError();
+ throw std::runtime_error(msg.str());
+ }
+
+ return new OggSoundFile(file, loop_begin, loop_at);
+}
+