/* SYX2EES.c - A program to convert sysex dumps from the KMX/Chroma Cult */ /* Midi format into the format for the EES interface. */ /* */ /* Version 0.1 - written 16-DEC-03 by David Clarke */ /* (ac151@freenet.carleton.ca) */ /* */ /* Please feel free to compile, change or do whatever you want with this */ /* utility; however, if you make any significant improvements I'd */ /* appreciate you e-mailing me a copy. Thanks! */ /* */ /* Syntax: */ /* SYX2EES FILENAME.SYX */ /* */ /* The program will output 1 file called FILENAME.EES */ /* For a properly formatted KMX file, the resulting sysex file will be */ /* 3454 bytes. */ /* */ /* Comments: */ /* (See comments in EES2SYX for general file format. This */ /* program does the reverse conversion - going from nibble-ized*/ /* 8-bit format, to packed 7-bit format. */ /**************************************************************************/ #include #include #include #include static char out[] = ".ees"; /* output file suffix */ char *f1name; /* full input file name */ char f2name[50]; /* full output file name */ FILE *f1, *f2; int main(int argc , char *argv[]) { int aa, x, ProgCount, z; unsigned char outbyte, byte[8], byte1, byte2; ProgCount = 0; /* Current Program Number */ if (argc == 1) { printf("Syntax: SYX2EES {filename.syx} where filename is a 50 program KMX sysex file\n"); return(-1); } f1name = argv[1]; strncpy(f2name, f1name, strlen(f1name)-4); strcat(f2name, out); if ((f1 = fopen(f1name, "rb")) == NULL) { printf("can't open %s\n", f1name); return(-1); } if ((f2 = fopen(f2name, "wb")) == NULL) { printf("can't open %s\n", f2name); return(-1); } for (x = 1; x <= 7; x++) /* Strip off Sysex header info from file */ { byte1 = fgetc(f1); } /* Output EES Sysex Header Info */ fputc(0xF0, f2); /* Start of Sysex */ fputc(0x63, f2); /* EES Manuf. ID */ fputc(0x43, f2); while (!feof(f1) && (ProgCount < 50)) /* Convert all 50 programs */ { /* Strip of KMX Patch Number */ byte1 = fgetc(f1); ProgCount++; /* Increment current Patch Number */ fputc(ProgCount, f2); /* Output Patch Number */ z = 1; /* keep track of which partial byte we're at */ for (x = 1; x <= 59; x++) /* Do for all 59 bytes of KMX data payload*/ { byte1 = fgetc(f1); byte2 = fgetc(f1); byte[z++] = (byte1 << 4) + byte2; /* If we've read qty. 7, 8-bit nibbles, combine into qty. 8, 7 bit*/ /* bytes. */ if (x % 7 == 0) { outbyte = 0x00; for (aa = 1; aa<=7; aa++) { fputc( ((byte[aa] >> 1) & 0x7F) , f2); outbyte = ((byte[aa] & 0x1) << (7 - aa)) + outbyte; } fputc((outbyte & 0x7F), f2); /* Output Partials Nibble */ z = 1; } /* If x = 59, we're at the end of the data - and need convert qty. 3*/ /* 8-bit bytes into qty. 4, 7 bit bytes. */ if (x == 59) { outbyte = 0x00; for (aa = 1; aa<=3; aa++) { fputc( (byte[aa] >> 1) & 0x7F , f2); outbyte = ((byte[aa] & 0x1) << (7 - aa)) + outbyte; } fputc((outbyte & 0x7F ), f2); /* Output Partials Nibble */ } } } fputc(0xF7, f2); /* Output an End of Sysex */ fclose(f1); /* Close Input File */ fclose(f2); /* Close Output File */ return(0); }