home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu 2008 / 2008-06-02_hobbes.nmsu.edu.zip / new / scummc-0.2.0-os2.zip / ScummC / src / midi.c < prev    next >
Encoding:
C/C++ Source or Header  |  2008-02-03  |  2.3 KB  |  95 lines

  1. /* ScummC
  2.  * Copyright (C) 2006  Alban Bedel
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17.  *
  18.  */
  19.  
  20. /** @file midi.c
  21.  *  @brief A MIDI file hacking tool.
  22.  */
  23.  
  24.  
  25. #include "config.h"
  26.  
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <inttypes.h>
  31. #include <errno.h>
  32.  
  33.  
  34. #include <sys/types.h>
  35. #include <sys/stat.h>
  36. #include <fcntl.h>
  37. #include "scc_fd.h"
  38. #include "scc_util.h"
  39.  
  40. #include "scc_param.h"
  41. #include "scc_smf.h"
  42.  
  43. #include "midi_help.h"
  44.  
  45. static int strip_track = -1;
  46. static int set_type = -1;
  47. static int dump = 0;
  48. static int* merge = NULL;
  49.  
  50. static scc_param_t scc_parse_params[] = {
  51.   { "strip-track", SCC_PARAM_INT, 0, 255, &strip_track },
  52.   { "set-type", SCC_PARAM_INT, 0, 2, &set_type },
  53.   { "merge-track", SCC_PARAM_INT_LIST, 0, 255, &merge },
  54.   { "dump", SCC_PARAM_FLAG, 0, 1, &dump },
  55.   { "help", SCC_PARAM_HELP, 0, 0, &midi_help },
  56.   { NULL, 0, 0, 0, NULL }
  57. };
  58.  
  59. int main(int argc,char** argv) {
  60.   scc_cl_arg_t* files;
  61.   scc_smf_t* smf;
  62.   
  63.   files = scc_param_parse_argv(scc_parse_params,argc-1,&argv[1]);
  64.  
  65.   if(!files) scc_print_help(&midi_help,1);
  66.  
  67.   smf = scc_smf_parse_file(files->val);
  68.   if(!smf) return 1;
  69.   
  70.   if(dump) {
  71.     scc_smf_dump(smf);
  72.     return 0;
  73.   }
  74.  
  75.   if(merge && merge[0] > 1) {
  76.     int t;
  77.     for(t = 2 ; t < merge[0]+1 ; t++)
  78.       scc_smf_merge_track(smf,merge[1],merge[t]);
  79.   }
  80.   
  81.   if(strip_track >= 0) {
  82.     if(strip_track >= smf->num_track) {
  83.       scc_log(LOG_ERR,"Track %d doesn't exist, there are only %d tracks.\n",
  84.               strip_track,smf->num_track);
  85.       return 1;
  86.     }
  87.     scc_smf_remove_track(smf,strip_track);
  88.   }
  89.  
  90.   if(set_type >= 0)
  91.     smf->type = set_type;
  92.  
  93.   return !scc_smf_write_file(smf,files->next->val);
  94. }
  95.