⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xm-parse.c

📁 Genetic Programing of music
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <xm_lib.h>intmain(int argc, char *argv[]) {  int i;  char *filename=NULL;  FILE *xmFile=NULL;  int patterns;  int instruments;  long headerEnd=0;  long instrumentStart;  long fileEnd;  FILE *outPutFile=NULL;  int splitFile=0;         /* flag for whether to split file */  int parsePattern=0;      /* flag for whether to treat file as pattern only*/  int printNoteData=0;     /* flag for printing note data in patterns */  char *transBuff=NULL;  int channels;    /* parse command line arguments */  for (i=1; i<argc; i++) {        if (strcmp (argv[i], "-v") == 0) {      outPutFile=stdout;         } else if (strcmp (argv[i], "-s") == 0) {      splitFile=1;         } else if (strcmp (argv[i], "-n") == 0) {      printNoteData=1;         } else if (strcmp (argv[i], "-p") == 0) {      parsePattern=1;      patterns=atoi(argv[++i]);      channels=atoi(argv[++i]);    } else if (strcmp (argv[i], "-c") == 0) {      /* sscanf(argv[++i],"%lg",&cSquared); */    } else if (strcmp (argv[i], "-h") == 0) {      fprintf(stderr, "\nSyntax: %s [-h] [-v] [-s] [-p <#pats>] "	      "<xm-file>\n\n"	      "\tDisplays information on the given XM file, and allows it to "	      "be split\n\tinto header, patterns and instruments\n\n"	      "\t-h  = display this help message\n"	      "\t-v  = verbose description of XM file\n"	      "\t-n  = print note data for patterns\n"	      "\t-s  = split into header, pattern and instrument sections,"	      "with names\n\t\theader.bin, patterns.bin, and instruments.bin"	      "\n"	      "\t-p  = parse file as patterns with #pats patternsi and #chan"  		" channels\n\n",	      argv[0]);      exit(1);    } else {      filename = argv[i];    }  }  /* check sanity */  if(parsePattern && splitFile)    fprintf(stderr,"Can't split a pattern!\n");    /* set appropriate output file */  if(outPutFile==NULL)    outPutFile=fopen("/dev/null","w+");    /*   * Open XM File   */  if(filename != NULL)    xmFile = fopen(filename,"r");    if (xmFile==NULL) {        fprintf(stderr,"Couln't open %s\n",filename);    exit(1);  }  /* print start info */  fprintf(outPutFile, "\nXM File Information\n===================\n\n");  if(!parsePattern) {    /* print the header info */    if(fprintXMHeaderInfo(xmFile,outPutFile, &patterns, &instruments,			  &channels)) {            fprintf(stderr, "Not a valid XM file!\n");      exit(1);          }        /* Note the end of the header */    headerEnd=ftell(xmFile);      }    /* Print the pattern information */  for(i=0;i<patterns;i++) {    fprintf(outPutFile, "Pattern %d Information:\n", i);    fprintXMPatternInfo(xmFile, outPutFile, channels, printNoteData);  }  if(!parsePattern) {    /* Note the start of Instruments */    instrumentStart=ftell(xmFile);        /* Print the instrument information */    for(i=0;i<instruments;i++) {            fprintf(outPutFile, "Instrument %d Information:\n", i);            fprintXMInstrumentInfo(xmFile, outPutFile);          }        /* Note the end of File */    fseek(xmFile,0,SEEK_END);    fileEnd=ftell(xmFile);        /* Print out file info */    fprintf(outPutFile, "File header ends at %#lx\n", headerEnd);    fprintf(outPutFile, "File instruments begin at %#lx\n", instrumentStart);    fprintf(outPutFile, "File ends at %#lx\n\n", fileEnd);        fclose(outPutFile);        /* Save the file in sections if requeste */    if(splitFile) {            /* allocate buffer for header and copy header to new file */      transBuff=(char *)realloc(transBuff,headerEnd*sizeof(char));      outPutFile=fopen("header.bin","w+");      fseek(xmFile,0,SEEK_SET);      fread(transBuff,sizeof(char),headerEnd,xmFile);      fwrite(transBuff,sizeof(char),headerEnd,outPutFile);      fclose(outPutFile);            /* allocate buffer for patterns and copy patterns to new file */      transBuff=(char *)realloc(transBuff,				(instrumentStart-headerEnd)*sizeof(char));      outPutFile=fopen("patterns.bin","w+");      fseek(xmFile,headerEnd,SEEK_SET);      fread(transBuff,sizeof(char),(instrumentStart-headerEnd),xmFile);      fwrite(transBuff,sizeof(char),(instrumentStart-headerEnd),outPutFile);      fclose(outPutFile);            /* allocate buffer for instruments and copy instruments to new file */      transBuff=(char *)realloc(transBuff,				(fileEnd-instrumentStart)*sizeof(char));      outPutFile=fopen("instruments.bin","w+");      fseek(xmFile,instrumentStart,SEEK_SET);      fread(transBuff,sizeof(char),(fileEnd-instrumentStart),xmFile);      fwrite(transBuff,sizeof(char),(fileEnd-instrumentStart),outPutFile);      fclose(outPutFile);          }      }    return 0;  } /* end of main */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -