[AD] play.c patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


This is a patch for the "play" program in the tests/ dir. Changes include reverting the bg to black (who in their right mind turned it white? I'd like to keep my eyesight, thanks :P). As well, it no longer bombs out if one of the files isn't loadable. It also no longer uses the palette_color array to get the colors, but instead uses makecol and stores them in local vars.

- Kitty Cat
Index: tests/play.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tests/play.c,v
retrieving revision 1.10
diff -u -r1.10 play.c
--- tests/play.c	15 Dec 2003 15:37:01 -0000	1.10
+++ tests/play.c	17 Jul 2004 05:45:18 -0000
@@ -140,6 +140,7 @@
    int doodle_note = -1;
    unsigned char midi_msg[3];
    int doodle_pitch[12] = { 60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79 };
+   int white, black, red, green;
    int i;
 
    if (allegro_init() != 0)
@@ -172,9 +173,14 @@
 	 return 1;
       }
    }
-
    set_palette(default_palette);
-   clear_to_color(screen, makecol(255, 255, 255));
+
+   white = makecol(255, 255, 255);
+   black = makecol(  0,   0,   0);
+   red   = makecol(192,   0,   0);
+   green = makecol(  0, 192,   0);
+
+   clear_to_color(screen, black);
 
    if (install_sound(digicard, midicard, NULL) != 0) {
       set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
@@ -182,16 +188,16 @@
       return 1;
    }
 
-   textprintf_centre_ex(screen, font, SCREEN_W/2, 12, palette_color[4], makecol(255, 255, 255), "Sound code test program for Allegro " ALLEGRO_VERSION_STR ", " ALLEGRO_PLATFORM_STR);
-   textprintf_centre_ex(screen, font, SCREEN_W/2, 24, palette_color[4], makecol(255, 255, 255), "By Shawn Hargreaves, " ALLEGRO_DATE_STR);
+   textprintf_centre_ex(screen, font, SCREEN_W/2, 12, red, -1, "Sound code test program for Allegro " ALLEGRO_VERSION_STR ", " ALLEGRO_PLATFORM_STR);
+   textprintf_centre_ex(screen, font, SCREEN_W/2, 24, red, -1, "By Shawn Hargreaves, " ALLEGRO_DATE_STR);
 
-   textprintf_ex(screen, font, 0, 84,  palette_color[2], makecol(255, 255, 255), "Digital sound driver: %s", digi_driver->name);
-   textprintf_ex(screen, font, 0, 96,  palette_color[2], makecol(255, 255, 255), "Description: %s", digi_driver->desc);
-   textprintf_ex(screen, font, 0, 108, palette_color[2], makecol(255, 255, 255), "Voices: %d", digi_driver->voices);
-
-   textprintf_ex(screen, font, 0, 132, palette_color[2], makecol(255, 255, 255), "Midi music driver: %s", midi_driver->name);
-   textprintf_ex(screen, font, 0, 144, palette_color[2], makecol(255, 255, 255), "Description: %s", midi_driver->desc);
-   textprintf_ex(screen, font, 0, 156, palette_color[2], makecol(255, 255, 255), "Voices: %d", midi_driver->voices);
+   textprintf_ex(screen, font, 0, 84,  green, -1, "Digital sound driver: %s", digi_driver->name);
+   textprintf_ex(screen, font, 0, 96,  green, -1, "Description: %s", digi_driver->desc);
+   textprintf_ex(screen, font, 0, 108, green, -1, "Voices: %d", digi_driver->voices);
+
+   textprintf_ex(screen, font, 0, 132, green, -1, "Midi music driver: %s", midi_driver->name);
+   textprintf_ex(screen, font, 0, 144, green, -1, "Description: %s", midi_driver->desc);
+   textprintf_ex(screen, font, 0, 156, green, -1, "Voices: %d", midi_driver->voices);
 
    while ((i < argc) && (item_count < 9)) {
       if ((stricmp(get_extension(argv[i]), "voc") == 0) || (stricmp(get_extension(argv[i]), "wav") == 0)) {
@@ -203,27 +209,28 @@
 	 is_midi[item_count] = 1;
       }
       else {
-	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
-	 allegro_message("Unknown file type '%s'\n", argv[i]);
-	 goto get_out;
+	 textprintf_ex(screen, font, 32, 192+item_count*12, white, -1, "Unknown file type '%s'", argv[i]);
+	 item[item_count] = NULL;
+	 item_count++;
+	 i++;
+	 continue;
       }
 
       if (!item[item_count]) {
-	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
-	 allegro_message("Error reading %s\n", argv[i]);
-	 goto get_out;
+	 textprintf_ex(screen, font, 32, 192+item_count*12, white, -1, "Error reading %s", argv[i]);
+      }
+      else {
+	 textprintf_ex(screen, font, 32, 192+item_count*12, white, -1, "%d: %s", item_count+1, argv[i]);
       }
-
-      textprintf_ex(screen, font, 32, 192+item_count*12, palette_color[255], makecol(255, 255, 255), "%d: %s", item_count+1, argv[i]);
 
       item_count++;
       i++;
    }
 
-   textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H-48, palette_color[4], makecol(255, 255, 255), "Press a number 1-9 to trigger a sample or midi file");
-   textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H-36, palette_color[4], makecol(255, 255, 255), "v/V changes sfx volume, p/P changes sfx pan, and f/F changes sfx frequency");
-   textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H-24, palette_color[4], makecol(255, 255, 255), "space pauses/resumes MIDI playback, and the arrow keys seek through the tune");
-   textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H-12, palette_color[4], makecol(255, 255, 255), "Use the function keys to doodle a tune");
+   textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H-48, red, -1, "Press a number 1-9 to trigger a sample or midi file");
+   textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H-36, red, -1, "v/V changes sfx volume, p/P changes sfx pan, and f/F changes sfx frequency");
+   textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H-24, red, -1, "space pauses/resumes MIDI playback, and the arrow keys seek through the tune");
+   textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H-12, red, -1, "Use the function keys to doodle a tune");
 
    k = '1';      /* start sound automatically */
 
@@ -305,12 +312,14 @@
 	    }
 	    else if (((k & 0xFF) >= '1') && ((k & 0xFF) < '1'+item_count)) {
 	       k = (k & 0xFF) - '1';
-	       if (is_midi[k]) {
-		  play_midi((MIDI *)item[k], FALSE);
-		  paused = FALSE;
+	       if (item[k]) {
+		  if (is_midi[k]) {
+		     play_midi((MIDI *)item[k], FALSE);
+		     paused = FALSE;
+		  }
+		  else
+		     play_sample((SAMPLE *)item[k], vol, pan, freq, FALSE);
 	       }
-	       else
-		  play_sample((SAMPLE *)item[k], vol, pan, freq, FALSE);
 	    }
 	    else {
 	       k >>= 8;
@@ -340,7 +349,7 @@
       old_midi_pos = midi_pos;
 
       sprintf(buf, "        midi pos: %ld    vol: %d    pan: %d    freq: %d        ", midi_pos, vol, pan, freq);
-      textout_centre_ex(screen, font, buf, SCREEN_W/2, SCREEN_H-120, palette_color[255], makecol(255, 255, 255));
+      textout_centre_ex(screen, font, buf, SCREEN_W/2, SCREEN_H-120, white, black);
 
       do {
       } while ((!keypressed()) && (midi_pos == old_midi_pos));
@@ -354,11 +363,14 @@
 
    get_out:
 
-   for (i=0; i<item_count; i++)
+   for (i=0; i<item_count; i++) {
+      if (!item[i])
+	 continue;
       if (is_midi[i])
 	 destroy_midi((MIDI *)item[i]);
       else
 	 destroy_sample((SAMPLE *)item[i]);
+   }
 
    return 0;
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/