main.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
  3. * http://www.trevorwishart.co.uk
  4. * http://www.composersdesktop.com
  5. *
  6. This file is part of the CDP System.
  7. The CDP System is free software; you can redistribute it
  8. and/or modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The CDP System is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the CDP System; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA
  19. *
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <structures.h>
  24. #include <tkglobals.h>
  25. #include <house.h>
  26. #include <filetype.h>
  27. #include <processno.h>
  28. #include <modeno.h>
  29. #include <formants.h>
  30. #include <cdpmain.h>
  31. #include <special.h>
  32. #include <logic.h>
  33. #include <globcon.h>
  34. #include <cdpmain.h>
  35. #include <sfsys.h>
  36. #include <ctype.h>
  37. #include <string.h>
  38. char errstr[2400];
  39. /*extern*/ int sloom = 0;
  40. /*extern*/ int sloombatch = 0;
  41. /*extern*/ int anal_infiles = 0;
  42. /*extern*/ int is_converted_to_stereo = -1;
  43. const char* cdp_version = "7.1.1";
  44. /**************************************** MAIN *********************************************/
  45. int main(int argc,char *argv[])
  46. {
  47. int exit_status;
  48. dataptr dz = NULL;
  49. // char *special_data_string = NULL;
  50. char **cmdline;
  51. int cmdlinecnt;
  52. aplptr ap;
  53. int *valid = NULL;
  54. int is_launched = FALSE;
  55. int validcnt;
  56. if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
  57. fprintf(stdout,"%s\n",cdp_version);
  58. fflush(stdout);
  59. return 0;
  60. }
  61. /* CHECK FOR SOUNDLOOM */
  62. if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
  63. sloom = 0;
  64. sloombatch = 1;
  65. }
  66. if(!sloom) {
  67. if((exit_status = allocate_and_initialise_validity_flags(&valid,&validcnt))<0) {
  68. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  69. return(FAILED);
  70. }
  71. }
  72. if(sflinit("cdp")){
  73. sfperror("cdp: initialisation\n");
  74. return(FAILED);
  75. }
  76. /* SET UP THE PRINCIPLE DATASTRUCTURE */
  77. if((exit_status = establish_datastructure(&dz))<0) {
  78. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  79. return(FAILED);
  80. }
  81. if(!sloom) {
  82. /* INITIAL CHECK OF CMDLINE DATA */
  83. if((exit_status = make_initial_cmdline_check(&argc,&argv))<0) {
  84. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  85. return(FAILED);
  86. }
  87. cmdline = argv; /* GET PRE_DATA, ALLOCATE THE APPLICATION, CHECK FOR EXTRA INFILES */
  88. cmdlinecnt = argc;
  89. if((exit_status = get_process_and_mode_from_cmdline(&cmdlinecnt,&cmdline,dz))<0) {
  90. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  91. return(FAILED);
  92. }
  93. if((exit_status = setup_particular_application(dz))<0) {
  94. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  95. return(FAILED);
  96. }
  97. if((exit_status = count_and_allocate_for_infiles(cmdlinecnt,cmdline,dz))<0) {
  98. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  99. return(FAILED);
  100. }
  101. } else {
  102. if((exit_status = parse_tk_data(argc,argv,&cmdline,&cmdlinecnt,dz))<0) { /* includes setup_particular_application() */
  103. exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);/* and cmdlinelength check = sees extra-infiles */
  104. return(exit_status);
  105. }
  106. }
  107. ap = dz->application;
  108. /*********************************************************************************************************************
  109. cmdline[0] 2 vals ACTIVE
  110. TK (infile) (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  111. CMDLINE (infile) (more-infiles) (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  112. 1 val
  113. *********************************************************************************************************************/
  114. if(dz->process!=HOUSE_DEL) {
  115. if((exit_status = parse_infile_and_hone_type(cmdline[0],valid,dz))<0) {
  116. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  117. return(FAILED);
  118. }
  119. }
  120. if((exit_status = setup_param_ranges_and_defaults(dz))<0) {
  121. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  122. return(FAILED);
  123. }
  124. /* OPEN FIRST INFILE AND STORE DATA, AND INFORMATION, APPROPRIATELY */
  125. if(dz->process!=HOUSE_DEL) {
  126. /*RWD 9:2001 there was only one & below */
  127. if(dz->process!=HOUSE_BUNDLE && dz->input_data_type!=NO_FILE_AT_ALL) {
  128. if((exit_status = open_first_infile(cmdline[0],dz))<0) {
  129. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  130. return(FAILED);
  131. }
  132. }
  133. if(!sloom) {
  134. if((dz->process==HOUSE_SORT || (dz->process==HOUSE_COPY && dz->mode==COPYSF && dz->infile->filetype==WORDLIST))) {
  135. if(dz->process==HOUSE_SORT)
  136. dz->all_words--;
  137. if (setup_file_outname_where_ness(cmdline[0],dz)<0) {
  138. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  139. return(FAILED); /* stores name of inlistfile at END of list of names of sndfiles */
  140. }
  141. }
  142. }
  143. cmdlinecnt--;
  144. cmdline++;
  145. }
  146. /*********************************************************************************************************************
  147. cmdline[0] 2 vals ACTIVE
  148. TK (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  149. CMDLINE (more-infiles) (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  150. 1 val
  151. *********************************************************************************************************************/
  152. if((exit_status = handle_extra_infiles(&cmdline,&cmdlinecnt,dz))<0) {
  153. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  154. return(FAILED);
  155. }
  156. /*********************************************************************************************************************
  157. cmdline[0] 2 ACTIVE
  158. TK (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  159. CMDLINE (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  160. 1
  161. *********************************************************************************************************************/
  162. if((exit_status = handle_outfile(&cmdlinecnt,&cmdline,is_launched,dz))<0) {
  163. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  164. return(FAILED);
  165. }
  166. /****************************************************************************************
  167. cmdline[0] ACTIVE
  168. TK (flag val) (formantsqksrch) (special) params options variant-params flags
  169. CMDLINE (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  170. *****************************************************************************************/
  171. if((exit_status = handle_formants(&cmdlinecnt,&cmdline,dz))<0) {
  172. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  173. return(FAILED);
  174. }
  175. if((exit_status = handle_formant_quiksearch(&cmdlinecnt,&cmdline,dz))<0) {
  176. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  177. return(FAILED);
  178. }
  179. if((exit_status = handle_special_data(&cmdlinecnt,&cmdline,dz))<0) {
  180. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  181. return(FAILED);
  182. }
  183. /****************************************************************************************
  184. cmdline[0]
  185. TK active_params options variant-params flags
  186. CMDLINE active_params POSSIBLY POSSIBLY POSSIBLY
  187. *****************************************************************************************/
  188. if((exit_status = read_parameters_and_flags(&cmdline,&cmdlinecnt,dz))<0) {
  189. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  190. return(FAILED);
  191. }
  192. if((exit_status = check_param_validity_and_consistency(dz))<0) {
  193. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  194. return(FAILED);
  195. }
  196. is_launched = TRUE;
  197. /*RWD OCT 2001: NB: we need to validate rq srate before allocating buffers! */
  198. if((exit_status = allocate_large_buffers(dz))<0){
  199. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  200. return(FAILED);
  201. }
  202. if((exit_status = param_preprocess(dz))<0){
  203. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  204. return(FAILED);
  205. }
  206. if((exit_status = groucho_process_file(dz))<0) {
  207. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  208. return(FAILED);
  209. }
  210. if((exit_status = complete_output(dz))<0) {
  211. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  212. return(FAILED);
  213. }
  214. exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz);
  215. free(dz);
  216. return(SUCCEEDED);
  217. }