Ejemplo n.º 1
0
void MusicDriver_Allegro::Stop()
{
    if (_midi != NULL) destroy_midi(_midi);
    _midi = NULL;

    if (--_allegro_instance_count == 0) allegro_exit();
}
Ejemplo n.º 2
0
/**
 * Runs the jukebox code. This contains its own game loop and can only be run
 * by adding the /j flag at startup.
 *
 * We'll display the song name, the current time and total time. When a song
 * is finished, we'll wait a second and then continue with the next.
 * Pressing ESC will quit the jukebox.
 */
int start_jukebox() {
    // Set up everything needed to run the jukebox.
    initialize_jukebox();
    initialize_starfield();

    MIDI *curr_music;
    int status;

    while (TRUE) {
        CURR_TRACK = ALL_MUSIC[track_n];

        // Prepare the screen.
        clear_to_color(buffer, palette_color[0]);

        // Load the next midi file.
        curr_music = load_midi(CURR_TRACK->file);
        length = get_midi_length(curr_music);
        // After calling get_midi_length(), midi_pos will contain the negative
        // number of beats, and midi_time the length of the midi in seconds.
        beats = -midi_pos;

        // Begin playback.
        play_midi(curr_music, FALSE);

        // Run the main loop; status is JUKEBOX_NEXT_SONG, JUKEBOX_PREV_SONG,
        // or JUKEBOX_EXIT if escape has been pressed.
        status = jukebox_loop();

        // Prepare for the next midi file.
        destroy_midi(curr_music);

        if (status == JUKEBOX_NEXT_SONG) {
            // Advance; loop back to zero if we're at the end.
            if (++track_n >= ALL_MUSIC_AMOUNT) {
                track_n = 0;
            }
        }
        else if (status == JUKEBOX_PREV_SONG) {
            // Go back one track.
            if (--track_n < 0) {
                track_n = ALL_MUSIC_AMOUNT - 1;
            }
        }
        else if (status == JUKEBOX_EXIT) {
            // Escape pressed; exit the jukebox.
            break;
        }
        else {
            // Unknown status.
            break;
        }
    }

    shutdown();
    return 0;
}
Ejemplo n.º 3
0
bool som::carregar(string arquivo)
{
	if(!egl_init) 
		return false;
	
	string ext = arquivo.substr(arquivo.size()-4,arquivo.size()-1);
	std::transform(ext.begin(), ext.end(), ext.begin(),static_cast < int(*)(int) > (tolower));

	if (ext == ".wav") {
		tipo = T_WAV;

		if(smp)
		{
			destroy_sample(smp);
			voice = -1;
		}
		smp = load_wav(arquivo.c_str());
		if(!smp) 
		{
			egl_erro("Erro carregando arquivo: " + arquivo);
			egl_debug = true;
			return false;
		}
	} else {
		tipo = T_MID;
		if(mid)
		{
			destroy_midi(mid);
			voice = -1;
		}
		mid = load_midi(arquivo.c_str());
		if(!mid) 
		{
			egl_erro("Erro carregando arquivo: " + arquivo);
			egl_debug = true;
			return false;
		}
	}
	return true;
}
Ejemplo n.º 4
0
void MusicDriver_Allegro::PlaySong(const char *filename)
{
    if (_midi != NULL) destroy_midi(_midi);
    _midi = load_midi(filename);
    play_midi(_midi, false);
}
Ejemplo n.º 5
0
Sound::Sound::~Sound ()
{
  stop ();
  if (midi)
    destroy_midi (midi);
}
Ejemplo n.º 6
0
 void destroy()
 {
   stop_midi();
   destroy_midi(tune);
   tune = NULL;
 }
Ejemplo n.º 7
0
int main()
{
    int field[25][50];
    int python[1000][2];
    int fd[2];
    int k,i,j,n=1,counter=0, over,t2;
    char directory[] = "Music/x.mid";

    allegro_init();
    install_keyboard();
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 272, 0, 0);
    install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL);

    BITMAP *buffer = create_bitmap(600,272);
    MIDI *music;
    while(n>0)
    {
        dir = r;
        length = 4;
        score = 0;
        t = 100;
        sp = 1;
        over = 0;
        look = 'r';
        t2 = 1;
        python[0][0] = 15;
        python[0][1] = 10;
        python[1][0] = 15;
        python[1][1] = 9;
        python[2][0] = 15;
        python[2][1] = 8;
        python[3][0] = 15;
        python[3][1] = 7;

        srand(time(NULL));
        directory[6] = intchar(rand()%9 + 1);

        music = load_midi(directory);
        play_midi(music,0);

        clear_to_color(screen,0x000000);
        opening();
        menu_mode(field);
        init(field);

        position(field,python);  // position the snake
        food(field,fd);
        guardi = python[length-1][0];
        guardj = python[length-1][1];
        display(field,python,fd,t2);

        while(over!=1)
        {
            if(t2<10) {
                t2++;
            }
            guardi = python[length-1][0];
            guardj = python[length-1][1];
            save = dir;
            python[length][0] = i;
            python[length][1] = j;
            rest(10);
            if(keypressed()) {
                dir = readkey();
            }
            else if ((dir & 0xff) == 'w') dir =u;
            else if ((dir & 0xff) == 's') dir =d;
            else if ((dir & 0xff) == 'a') dir =l;
            else if ((dir & 0xff) == 'd') dir =r;

            if((dir==u)||(dir==d)||(dir==l)||(dir==r)) {
                over = analysis(field,python,fd);
                rest(t-10);
            }
            else if(dir==esc) {
                over=1;
                n=0;
            }
            else {
                dir = save;
                over = analysis(field,python,fd);
                rest(t-10);
            };
            display(field,python,fd,t2);



        }
        portal1[0] = 50;
        portal1[1] = 50;
        portal2[0] = 50;
        portal2[1] = 50;
        clear_to_color(screen,0xFFFFFF);
        textout_ex(screen,font,"Score: ",225,160,0x02094A,0xF7FF0B);
        outnumber(265,160,score);
        saverec(field,python,fd);
        destroy_midi(music);
        rest(100);
        if(readkey()==esc) {
            n=0;
        }

    }

    destroy_bitmap(buffer);
    return 0;
}
Ejemplo n.º 8
0
som::~som()
{
	if(smp) destroy_sample(smp);
	if(mid) destroy_midi(mid);
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
   MIDI *the_music;
   int length, pos;
   int beats, beat;
   int x, y, tw, th;
   int background_color;
   int text_color;
   int paused = 0;
   int done = 0;

   if (allegro_init() != 0)
      return 1;

   if (argc != 2) {
      allegro_message("Usage: 'exmidi filename.mid'\n");
      return 1;
   }

   install_keyboard(); 
   install_timer();

   /* install a MIDI sound driver */
   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
      allegro_message("Error initialising sound system\n%s\n", allegro_error);
      return 1;
   }

   /* read in the MIDI file */
   the_music = load_midi(argv[1]);
   if (!the_music) {
      allegro_message("Error reading MIDI file '%s'\n", argv[1]);
      return 1;
   }
   length = get_midi_length(the_music);
   beats = -midi_pos; /* get_midi_length updates midi_pos to the negative
                         number of beats (quarter notes) in the midi. */

   if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
	 return 1;
      }
   }
   
   /* try to continue in the background */
   if (set_display_switch_mode(SWITCH_BACKGROUND))
      set_display_switch_mode(SWITCH_BACKAMNESIA);

   set_palette(desktop_palette);
   background_color = makecol(255, 255, 255);
   text_color = makecol(0, 0, 0);
   clear_to_color(screen, background_color);
   th = text_height(font);
   x = SCREEN_W / 2;

   textprintf_centre_ex(screen, font, x, SCREEN_H / 3, text_color, -1,
			"Driver: %s", midi_driver->name);
   textprintf_centre_ex(screen, font, x, SCREEN_H / 2, text_color, -1,
			"Playing %s", get_filename(argv[1]));

   /* start up the MIDI file */
   play_midi(the_music, TRUE);

   y = 2 * SCREEN_H / 3;
   tw = text_length(font, "0000:00 / 0000:00");
   /* wait for a key press */
   while (!done) {
       /* P key pauses/resumes, any other key exits. */
      while (keypressed()) {
	 int k = readkey() & 255;
	 if (k == 'p') {
	    paused = !paused;
	    if (paused) {
	       midi_pause();
	       textprintf_centre_ex(screen, font, x, y + th * 3,
		  text_color, -1, "P A U S E D");
	    }
	    else {
	       midi_resume();
	       rectfill(screen, x - tw / 2, y + th * 3, x + tw / 2,
		  y + th * 4, background_color);
	    }
	 }
	 else
	    done = 1;
      }
      pos = midi_time;
      beat = midi_pos;
      rectfill(screen, x - tw / 2, y, x + tw / 2, y + th * 2, background_color);
      textprintf_centre_ex(screen, font, x, y, text_color, -1,
	 "%d:%02d / %d:%02d", pos / 60, pos % 60, length / 60, length % 60);
      textprintf_centre_ex(screen, font, x, y + th, text_color, -1,
	 "beat %d / %d", beat, beats);
      /* We have nothing else to do. */
      rest(100);
   }

   /* destroy the MIDI file */
   destroy_midi(the_music);

   return 0;
}