main.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. /* floatsam version: no changes */
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <structures.h>
  26. #include <tkglobals.h>
  27. #include <texture.h>
  28. #include <filetype.h>
  29. #include <processno.h>
  30. #include <modeno.h>
  31. #include <formants.h>
  32. #include <cdpmain.h>
  33. #include <special.h>
  34. #include <logic.h>
  35. #include <globcon.h>
  36. #include <cdpmain.h>
  37. #include <sfsys.h>
  38. #include <ctype.h>
  39. char errstr[6000];
  40. /*extern*/ int sloom = 0;
  41. /*extern*/ int sloombatch = 0;
  42. /*extern*/ int anal_infiles = 0;
  43. /*extern*/ int is_converted_to_stereo = -1;
  44. const char* cdp_version = "8.0.1";
  45. /**************************************** MAIN *********************************************/
  46. int main(int argc,char *argv[])
  47. {
  48. int exit_status;
  49. dataptr dz = NULL;
  50. /* char *special_data_string = NULL;*/
  51. char **cmdline;
  52. int cmdlinecnt;
  53. // aplptr ap;
  54. int *valid = NULL;
  55. int is_launched = FALSE;
  56. int validcnt;
  57. if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
  58. fprintf(stdout,"%s\n",cdp_version);
  59. fflush(stdout);
  60. return 0;
  61. }
  62. /* CHECK FOR SOUNDLOOM */
  63. //TW UPDATE
  64. if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
  65. sloom = 0;
  66. sloombatch = 1;
  67. }
  68. if(!sloom) {
  69. if((exit_status = allocate_and_initialise_validity_flags(&valid,&validcnt))<0) {
  70. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  71. return(FAILED);
  72. }
  73. }
  74. if(sflinit("cdp")){
  75. sfperror("cdp: initialisation\n");
  76. return(FAILED);
  77. }
  78. /* SET UP THE PRINCIPLE DATASTRUCTURE */
  79. if((exit_status = establish_datastructure(&dz))<0) {
  80. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  81. return(FAILED);
  82. }
  83. if(!sloom) {
  84. /* INITIAL CHECK OF CMDLINE DATA */
  85. if((exit_status = make_initial_cmdline_check(&argc,&argv))<0) {
  86. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  87. return(FAILED);
  88. }
  89. cmdline = argv; /* GET PRE_DATA, ALLOCATE THE APPLICATION, CHECK FOR EXTRA INFILES */
  90. cmdlinecnt = argc;
  91. if((exit_status = get_process_and_mode_from_cmdline(&cmdlinecnt,&cmdline,dz))<0) {
  92. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  93. return(FAILED);
  94. }
  95. if((exit_status = setup_particular_application(dz))<0) {
  96. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  97. return(FAILED);
  98. }
  99. if((exit_status = count_and_allocate_for_infiles(cmdlinecnt,cmdline,dz))<0) {
  100. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  101. return(FAILED);
  102. }
  103. } else {
  104. if((exit_status = parse_tk_data(argc,argv,&cmdline,&cmdlinecnt,dz))<0) { /* includes setup_particular_application() */
  105. exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);/* and cmdlinelength check = sees extra-infiles */
  106. return(exit_status);
  107. }
  108. }
  109. // ap = dz->application;
  110. /*********************************************************************************************************************
  111. cmdline[0] 2 vals ACTIVE
  112. TK (infile) (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  113. CMDLINE (infile) (more-infiles) (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  114. 1 val
  115. *********************************************************************************************************************/
  116. if((exit_status = parse_infile_and_hone_type(cmdline[0],valid,dz))<0) {
  117. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  118. return(FAILED);
  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->input_data_type!=NO_FILE_AT_ALL) {
  126. if((exit_status = open_first_infile(cmdline[0],dz))<0) {
  127. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  128. return(FAILED);
  129. }
  130. //TW UPDATE
  131. cmdlinecnt--;
  132. cmdline++;
  133. }
  134. /*********************************************************************************************************************
  135. cmdline[0] 2 vals ACTIVE
  136. TK (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  137. CMDLINE (more-infiles) (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  138. 1 val
  139. *********************************************************************************************************************/
  140. if((exit_status = handle_extra_infiles(&cmdline,&cmdlinecnt,dz))<0) {
  141. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  142. return(FAILED);
  143. }
  144. /*********************************************************************************************************************
  145. cmdline[0] 2 ACTIVE
  146. TK (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  147. CMDLINE (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  148. 1
  149. *********************************************************************************************************************/
  150. if((exit_status = handle_outfile(&cmdlinecnt,&cmdline,is_launched,dz))<0) {
  151. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  152. return(FAILED);
  153. }
  154. /****************************************************************************************
  155. cmdline[0] ACTIVE
  156. TK (flag val) (formantsqksrch) (special) params options variant-params flags
  157. CMDLINE (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  158. *****************************************************************************************/
  159. if((exit_status = handle_formants(&cmdlinecnt,&cmdline,dz))<0) {
  160. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  161. return(FAILED);
  162. }
  163. if((exit_status = handle_formant_quiksearch(&cmdlinecnt,&cmdline,dz))<0) {
  164. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  165. return(FAILED);
  166. }
  167. if((exit_status = handle_special_data(&cmdlinecnt,&cmdline,dz))<0) {
  168. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  169. return(FAILED);
  170. }
  171. /****************************************************************************************
  172. cmdline[0]
  173. TK active_params options variant-params flags
  174. CMDLINE active_params POSSIBLY POSSIBLY POSSIBLY
  175. *****************************************************************************************/
  176. if((exit_status = read_parameters_and_flags(&cmdline,&cmdlinecnt,dz))<0) {
  177. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  178. return(FAILED);
  179. }
  180. if((exit_status = check_param_validity_and_consistency(dz))<0) {
  181. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  182. return(FAILED);
  183. }
  184. is_launched = TRUE;
  185. if((exit_status = allocate_large_buffers(dz))<0){
  186. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  187. return(FAILED);
  188. }
  189. if((exit_status = param_preprocess(dz))<0){
  190. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  191. return(FAILED);
  192. }
  193. if((exit_status = groucho_process_file(dz))<0) {
  194. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  195. return(FAILED);
  196. }
  197. if((exit_status = complete_output(dz))<0) {
  198. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  199. return(FAILED);
  200. }
  201. exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz);
  202. free(dz);
  203. return(SUCCEEDED);
  204. }