ponytracker/sources/instrument/main.c

54 lines
1.4 KiB
C
Raw Normal View History

#include <SDL/SDL.h>
#include <SDL_mixer.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int continuer = 1;
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *ecran = NULL;
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_Event event;
SDL_WM_SetCaption("SDL_Mixer", NULL);
SDL_Flip(ecran);
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) //Initialisation de l'API Mixer
{
printf("%s", Mix_GetError());
}
Mix_Music *musique; //Creation du pointeur de type Mix_Music
musique = Mix_LoadMUS("A Friend For Life (MIM Remix) 2.wav"); //Chargement de la musique
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_KEYDOWN:
Mix_PlayMusic(musique, -1); //Jouer en boucle tant que la touche est enfoncee
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_KEYUP:
Mix_HaltMusic(); //Arreter la boucle si la touche est relachee
break;
}
break;
}
}
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
}
}
Mix_FreeMusic(musique); //Lib<69>ration de la musique
Mix_CloseAudio(); //Fermeture de l'API
SDL_Quit();
return EXIT_SUCCESS;
}