main.c 9.7 KB

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