shithub: choc

Download patch

ref: 2c2e33f914ed6fdf149cfa41d845dca8d5f98964
parent: c440a62250aa02e1bb649f2822ea71c89848e5f0
author: Simon Howard <[email protected]>
date: Tue Nov 14 19:25:22 EST 2006

Use booleans in place of ints where possible.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 753

--- a/src/mus2mid.c
+++ b/src/mus2mid.c
@@ -101,7 +101,7 @@
 
 // Write timestamp to a MIDI file.
 
-static int midi_writetime(unsigned int time, MEMFILE *midioutput) 
+static boolean midi_writetime(unsigned int time, MEMFILE *midioutput) 
 {
 	unsigned int buffer = time & 0x7F;
 	byte writeval;
@@ -118,7 +118,7 @@
 
 		if (mem_fwrite(&writeval, 1, 1, midioutput) != 1) 
 		{
-			return 1;
+			return true;
 		}
 
 		++tracksize;
@@ -130,7 +130,7 @@
 		else 
 		{
 			queuedtime = 0;
-			return 0;
+			return false;
 		}
 	}
 }
@@ -137,38 +137,38 @@
 
 
 // Write the end of track marker
-static int midi_writeendtrack(MEMFILE *midioutput) 
+static boolean midi_writeendtrack(MEMFILE *midioutput) 
 {
 	byte endtrack[] = {0xFF, 0x2F, 0x00};
 
 	if (midi_writetime(queuedtime, midioutput)) 
 	{
-		return 1;
+		return true;
 	}
 
 	if (mem_fwrite(endtrack, 1, 3, midioutput) != 3) 
 	{
-		return 1;
+		return true;
 	}
 
 	tracksize += 3;
-	return 0;
+	return false;
 }
 
 // Write a key press event
-static int midi_writepresskey(byte channel, byte key, 
-                              byte velocity, MEMFILE *midioutput) 
+static boolean midi_writepresskey(byte channel, byte key, 
+                                  byte velocity, MEMFILE *midioutput) 
 {
 	byte working = midi_presskey | channel;
 
 	if (midi_writetime(queuedtime, midioutput)) 
 	{
-		return 1;
+		return true;
 	}
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	working = key & 0x7F;
@@ -175,7 +175,7 @@
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 	
 	working = velocity & 0x7F;
@@ -182,28 +182,28 @@
 	
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	tracksize += 3;
 
-	return 0;
+	return false;
 }
 
 // Write a key release event
-static int midi_writereleasekey(byte channel, byte key, 
-                                MEMFILE *midioutput) 
+static boolean midi_writereleasekey(byte channel, byte key, 
+                                    MEMFILE *midioutput) 
 {
 	byte working = midi_releasekey | channel;
 
 	if (midi_writetime(queuedtime, midioutput)) 
 	{
-		return 1;
+		return true;
 	}
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	working = key & 0x7F;
@@ -210,7 +210,7 @@
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	working = 0;
@@ -217,28 +217,28 @@
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	tracksize += 3;
 
-	return 0;
+	return false;
 }
 
 // Write a pitch wheel/bend event
-static int midi_writepitchwheel(byte channel, short wheel, 
-                                MEMFILE *midioutput) 
+static boolean midi_writepitchwheel(byte channel, short wheel, 
+                                    MEMFILE *midioutput) 
 {
 	byte working = midi_pitchwheel | channel;
 
 	if (midi_writetime(queuedtime, midioutput)) 
 	{
-		return 1;
+		return true;
 	}
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	working = wheel & 0x7F;
@@ -245,7 +245,7 @@
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	working = (wheel >> 7) & 0x7F;
@@ -252,27 +252,27 @@
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	tracksize += 3;
-	return 0;
+	return false;
 }
 
 // Write a patch change event
-static int midi_writechangepatch(byte channel, byte patch,
-                                 MEMFILE *midioutput) 
+static boolean midi_writechangepatch(byte channel, byte patch,
+                                     MEMFILE *midioutput) 
 {
 	byte working = midi_changepatch | channel;
 	
 	if (midi_writetime(queuedtime, midioutput)) 
 	{
-		return 1;
+		return true;
 	}
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	working = patch & 0x7F;
@@ -279,32 +279,32 @@
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	tracksize += 2;
 
-	return 0;
+	return false;
 }
 
 
 
 // Write a valued controller change event
-static int midi_writechangecontroller_valued(byte channel, 
-                                             byte control, 
-                                             byte value, 
-                                             MEMFILE *midioutput) 
+static boolean midi_writechangecontroller_valued(byte channel, 
+                                                 byte control, 
+                                                 byte value, 
+                                                 MEMFILE *midioutput) 
 {
 	byte working = midi_changecontroller | channel;
 
 	if (midi_writetime(queuedtime, midioutput)) 
 	{
-		return 1;
+		return true;
 	}
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	working = control & 0x7F;
@@ -311,7 +311,7 @@
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 	// Quirk in vanilla DOOM? MUS controller values should be 
 	// 7-bit, not 8-bit.
@@ -328,18 +328,18 @@
 
 	if (mem_fwrite(&working, 1, 1, midioutput) != 1) 
 	{
-		return 1;
+		return true;
 	}
 
 	tracksize += 3;
 
-	return 0;
+	return false;
 }
 
 // Write a valueless controller change event
-static int midi_writechangecontroller_valueless(byte channel, 
-                                                byte control, 
-                                                MEMFILE *midioutput) 
+static boolean midi_writechangecontroller_valueless(byte channel, 
+                                                    byte control, 
+                                                    MEMFILE *midioutput) 
 {
 	return midi_writechangecontroller_valued(channel, control, 0, 
 			 			 midioutput);
@@ -374,7 +374,7 @@
 //
 // Returns 0 on success or 1 on failure.
 
-int mus2mid(MEMFILE *musinput, MEMFILE *midioutput) 
+boolean mus2mid(MEMFILE *musinput, MEMFILE *midioutput) 
 {
 	// Header for the MUS file
 	musheader musfileheader;         
@@ -405,7 +405,7 @@
 
 	if (!read_musheader(musinput, &musfileheader))
 	{
-		return 1;
+		return true;
 	}
 
 #ifdef CHECK_MUS_HEADER
@@ -415,7 +415,7 @@
 	 || musfileheader.id[2] != 'S' 
 	 || musfileheader.id[3] != 0x1A) 
 	{
-		return 1;
+		return true;
 	}
 #endif
 
@@ -422,7 +422,7 @@
 	// Seek to where the data is held
 	if (mem_fseek(musinput, (long)musfileheader.scorestart, SEEK_SET) != 0) 
 	{
-		return 1;
+		return true;
 	}
 
 	// So, we can assume the MUS file is faintly legit. Let's start 
@@ -441,7 +441,7 @@
 
 			if (mem_fread(&eventdescriptor, 1, 1, musinput) != 1) 
 			{
-				return 1;
+				return true;
 			}
 
 			channel = eventdescriptor & 0x0F;
@@ -465,12 +465,12 @@
 				case mus_releasekey:
 					if (mem_fread(&key, 1, 1, musinput) != 1) 
 					{
-						return 1;
+						return true;
 					}
 
 					if (midi_writereleasekey(channel, key, midioutput)) 
 					{
-						return 1;
+						return true;
 					}
 
 					break;
@@ -478,7 +478,7 @@
 				case mus_presskey:
 					if (mem_fread(&key, 1, 1, musinput) != 1) 
 					{
-						return 1;
+						return true;
 					}
 
 					if (key & 0x80) 
@@ -485,7 +485,7 @@
 					{
 						if (mem_fread(&channelvelocities[channel], 1, 1, musinput) != 1) 
 						{
-							return 1;
+							return true;
 						}
 
 						channelvelocities[channel] &= 0x7F;
@@ -493,7 +493,7 @@
 
 					if (midi_writepresskey(channel, key, channelvelocities[channel], midioutput)) 
 					{
-						return 1;
+						return true;
 					}
 
 					break;
@@ -505,7 +505,7 @@
 					}
 					if (midi_writepitchwheel(channel, (short)(key * 64), midioutput)) 
 					{
-						return 1;
+						return true;
 					}
 
 					break;
@@ -513,16 +513,16 @@
 				case mus_systemevent:
 					if (mem_fread(&controllernumber, 1, 1, musinput) != 1) 
 					{
-						return 1;
+						return true;
 					}
 					if (controllernumber < 10 || controllernumber > 14) 
 					{
-						return 1;
+						return true;
 					}
 
 					if (midi_writechangecontroller_valueless(channel, mus2midi_translation[controllernumber], midioutput)) 
 					{
-						return 1;
+						return true;
 					}
 
 					break;
@@ -530,12 +530,12 @@
 				case mus_changecontroller:
 					if (mem_fread(&controllernumber, 1, 1, musinput) != 1) 
 					{
-						return 1;
+						return true;
 					}
 
 					if (mem_fread(&controllervalue, 1, 1, musinput) != 1) 
 					{
-						return 1;
+						return true;
 					}
 
 					if (controllernumber == 0) 
@@ -542,7 +542,7 @@
 					{
 						if (midi_writechangepatch(channel, controllervalue, midioutput)) 
 						{
-							return 1;
+							return true;
 						}
 					} 
 					else 
@@ -549,12 +549,12 @@
 					{
 						if (controllernumber < 1 || controllernumber > 9) 
 						{
-							return 1;
+							return true;
 						}
 
 						if (midi_writechangecontroller_valued(channel, mus2midi_translation[controllernumber], controllervalue, midioutput)) 
 						{
-							return 1;  
+							return true;
 						}
 					}
 
@@ -565,7 +565,7 @@
 					break;
 
 				default:
-					return 1;
+					return true;
 					break;
 			}
 
@@ -582,7 +582,7 @@
 			{
 				if (mem_fread(&working, 1, 1, musinput) != 1) 
 				{
-					return 1;
+					return true;
 				}
 
 				timedelay = timedelay * 128 + (working & 0x7F);
@@ -598,13 +598,13 @@
 	// End of track
 	if (midi_writeendtrack(midioutput)) 
 	{
-		return 1;
+		return true;
 	}
 
 	// Write the track size into the stream
 	if (mem_fseek(midioutput, 18, SEEK_SET)) 
 	{
-		return 1;
+		return true;
 	}
 
         tracksizebuffer[0] = (tracksize >> 24) & 0xff;
@@ -614,9 +614,9 @@
 
 	if (mem_fwrite(tracksizebuffer, 1, 4, midioutput) != 4) 
 	{
-		return 1;
+		return true;
 	}
 
-	return 0;
+	return false;
 }
 
--- a/src/mus2mid.h
+++ b/src/mus2mid.h
@@ -27,9 +27,10 @@
 #ifndef MUS2MID_H
 #define MUS2MID_H
 
+#include "doomtype.h"
 #include "memio.h"
 
-int mus2mid(MEMFILE *musinput, MEMFILE *midioutput);
+boolean mus2mid(MEMFILE *musinput, MEMFILE *midioutput);
 
 #endif /* #ifndef MUS2MID_H */