예제 #1
0
파일: i_music.c 프로젝트: mdgunn/doomretro
void *I_RegisterSong(void *data, int len)
{
    if (!music_initialized)
        return false;
    else
    {
        Mix_Music       *music = NULL;

        if (!memcmp(data, "MUS", 3))
        {
            ConvertMus(data, len, tempmusicfilename);
            music = Mix_LoadMUS(tempmusicfilename);
            remove(tempmusicfilename);
        }
        else
        {
            SDL_RWops   *rwops = SDL_RWFromMem(data, len);

            if (rwops)
                music = Mix_LoadMUS_RW(rwops, SDL_FALSE);
        }

        return music;
    }
}
예제 #2
0
static void *I_SDL_RegisterSong(void *data, int len)
{
    char *filename;
    Mix_Music *music;

    if (!music_initialized)
    {
        return NULL;
    }

    // MUS files begin with "MUS"
    // Reject anything which doesnt have this signature

    filename = M_TempFile("doom"); // [crispy] generic filename

    // [crispy] Reverse Choco's logic from "if (MIDI)" to "if (not MUS)"
    // MUS is the only format that requires conversion,
    // let SDL_Mixer figure out the others
/*
    if (IsMid(data, len) && len < MAXMIDLENGTH)
*/
    if (len < 4 || memcmp(data, "MUS\x1a", 4)) // [crispy] MUS_HEADER_MAGIC
    {
        M_WriteFile(filename, data, len);
    }
    else
    {
	// Assume a MUS file and try to convert

        ConvertMus(data, len, filename);
    }

    // Load the MIDI. In an ideal world we'd be using Mix_LoadMUS_RW()
    // by now, but Mix_SetMusicCMD() only works with Mix_LoadMUS(), so
    // we have to generate a temporary file.

#if defined(_WIN32)
    // [AM] If we do not have an external music command defined, play
    //      music with the MIDI server.
    if (midi_server_initialized)
    {
        music = NULL;
        if (!I_MidiPipe_RegisterSong(filename))
        {
            fprintf(stderr, "Error loading midi: %s\n",
                "Could not communicate with midiproc.");
        }
    }
    else
#endif
    {
        music = Mix_LoadMUS(filename);
        if (music == NULL)
        {
            // Failed to load
            fprintf(stderr, "Error loading midi: %s\n", Mix_GetError());
        }

        // Remove the temporary MIDI file; however, when using an external
        // MIDI program we can't delete the file. Otherwise, the program
        // won't find the file to play. This means we leave a mess on
        // disk :(

        if (strlen(snd_musiccmd) == 0)
        {
            remove(filename);
        }
    }

    free(filename);

    return music;
}