columns.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. /* header for columns */
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26. #include <math.h>
  27. #include <sfsys.h>
  28. #include <osbind.h>
  29. #if defined unix || defined __GNUC__
  30. #define round(x) lround((x))
  31. #endif
  32. #ifndef HUGE
  33. #define HUGE 3.40282347e+38F
  34. #endif
  35. #define PROG "COLUMNS"
  36. #define BIGARRAY 200
  37. #define ODD(x) ((x)&1)
  38. #define ENDOFSTR '\0'
  39. #define FLTERR 0.000002
  40. #define ONEMAX 0.001 /* Upper limit on log(x)==1 */
  41. #define ONEMIN 0.999 /* Lower limit on log(x)==1 */
  42. #define TWELVE 12.0
  43. #define VERY_TINY (0.0000000000000000000000000000001)
  44. #define C_HZ (8.175799)
  45. #define LOG_2_TO_BASE_E (.69314718)
  46. #define HARMONIC_TUNING_TOLERANCE (.01) /* semitones */
  47. #define ONE_OVER_LN2 (1.442695)
  48. #define INVERT 1
  49. #define MULT 0
  50. #define ADD 1
  51. #define SUBTRACT 2
  52. #define ENVMAX 3
  53. #define MIDIMINFRQ (8.175799)
  54. #define MIDIMAXFRQ (12543.853951)
  55. #define MIDIMIN (0)
  56. #define MIDIMAX (127)
  57. #define MAXSAMP (32767.0)
  58. #define F_MAXSAMP (1.0)
  59. #define MAXOCTTRANS (12.0)
  60. extern int cnt, firstcnt, arraysize, infilecnt, outfilecnt;
  61. extern double *number, *permm, *permmm, factor, scatter, *pos;
  62. extern double thresh;
  63. extern FILE **fp;
  64. extern char temp[20000], flag, *filename, *thisfilename, string[200];
  65. extern int ro, ifactor, len, condit;
  66. extern char **strings;
  67. extern char *stringstore;
  68. extern int stringscnt;
  69. extern int stringstoresize, stringstart;
  70. int strgetfloat(char **,double *), strgetstr(char **,char *);
  71. int flteq(double,double);
  72. void logo(void), qiksort(void), eliminate(int), usage(void);
  73. double hztomidi(double), miditohz(double);
  74. char *exmalloc(int), *exrealloc(char *,int);
  75. void rndperm(double *), insert(double *,int, int), prefix(double *,int);
  76. void multrndperm(double *), rndperm2(double *), shuffle(int,int);
  77. void do_infile(char *), do_pitchtext_infile(char *), do_text_read(char *);
  78. void do_outfile(char *), do_other_infiles(char *[]);
  79. void bellperm1(void), bellperm2(void), bellperm3(void);
  80. void swap(double *,double *);
  81. double texttomidi(char *);
  82. char *get_pitchclass(char *,int *,int);
  83. int timevents(double,double,double,double);
  84. int m_repos(int), f_repos(int);
  85. void check_for_conditional(int *,char *[]);
  86. void do_stringline_infile_irreg(char *argv,int n);
  87. void remove_frq_pitchclass_duplicates(void);
  88. void count_items(char *);
  89. void accel_time_seq(void);
  90. void accel_durations(void);
  91. void separate_columns_to_files(void);
  92. void partition_values_to_files(void);
  93. void join_files_as_columns(char *);
  94. void join_many_files_as_columns(char *,int);
  95. void concatenate_files(char *);
  96. void concatenate_files_cyclically(char *);
  97. void vals_end_to_end_in_2_cols(void);
  98. void quantise(void);
  99. void eliminate_equivalents(void);
  100. void eliminate_even_items(void);
  101. void eliminate_greater_than(void);
  102. void eliminate_less_than(void);
  103. void eliminate_duplicates(void);
  104. void print_numbers(void);
  105. void reduce_to_bound(void);
  106. void increase_to_bound(void);
  107. void greatest(void);
  108. void least(void);
  109. void mark_greater_than(void);
  110. void mark_less_than(void);
  111. void minor_to_major(void);
  112. void add(void);
  113. void take_power(void);
  114. void temper_midi_data(void);
  115. void temper_hz_data(void);
  116. void time_from_crotchet_count(void);
  117. void time_from_beat_lengths(void);
  118. void total(void);
  119. void text_to_hz(void);
  120. void product(void);
  121. void hz_to_midi(void);
  122. void find_mean(void);
  123. void midi_to_hz(void);
  124. void major_to_minor(void);
  125. void remove_midi_pitchclass_duplicates(void);
  126. void reverse_list(void);
  127. void rotate_motif(void);
  128. void ratios(void);
  129. void qiksort(void);
  130. void reciprocals(int positive_vals_only);
  131. void randomise_order(int *perm);
  132. void add_randval_plus_or_minus(void);
  133. void add_randval(void);
  134. void multiply_by_randval(void);
  135. void randchunks(void);
  136. void generate_random_values(void);
  137. void random_0s_and_1s(void);
  138. void random_0s_and_1s_restrained(void); /*TW march 2004 */
  139. void random_scatter(void);
  140. void random_elimination(void);
  141. void equal_divisions(void);
  142. void log_equal_divisions(void);
  143. void quadratic_curve_steps(void);
  144. void plain_bob(void);
  145. void get_intervals(void);
  146. void repeat_intervals(void);
  147. void make_equal_intevals_btwn_given_vals(void);
  148. void create_intervals(void);
  149. void change_value_of_intervals(void);
  150. void change_value_of_intervals(void);
  151. void get_intermediate_values(void);
  152. void insert_intermediate_values(void);
  153. void motivically_invert_midi(void);
  154. void motivically_invert_hz(void);
  155. void stack(int with_last); /*TW March 2004 */
  156. void get_one_skip_n(void);
  157. void get_n_skip_one(void);
  158. void sum_nwise(void);
  159. void sum_minus_overlaps(void);
  160. void sum_absolute_differences(void);
  161. void duplicate_values(void);
  162. void duplicate_list(void);
  163. void multiply(int rounded);
  164. void format_vals(void);
  165. void rotate_partition_values_to_files(void);
  166. void generate_harmonics(void);
  167. void group_harmonics(void);
  168. void get_harmonic_roots(void);
  169. void rank_vals(void);
  170. void rank_frqs(void);
  171. void approx_vals(void);
  172. void pitchtotext(int midi);
  173. void miditotext(void);
  174. void floor_vals(void);
  175. void limit_vals(void);
  176. void help(void),helpm(void),helpM(void),helpr(void);
  177. void helpl(void),helpg(void);
  178. void interval_limit(void);
  179. void time_density(void), divide_list(void), group(void);
  180. void duplicate_octfrq(void);
  181. void duplicate_octaves(void);
  182. void interval_to_ratio(int semitones,int tstretch);
  183. void do_slope(void);
  184. void do_string_infile(char *);
  185. void alphabetic_sort(void);
  186. void db_to_level(int sampleval);
  187. void level_to_db(int sampleval);
  188. void do_DB_infile(char *);
  189. void columnate(void);
  190. void samp_to_time(void);
  191. void time_to_samp(void);
  192. void column_format_vals(void);
  193. void delete_small_intervals(void);
  194. void mark_event_groups(void);
  195. void span(void);
  196. void spanpair(void);
  197. void alt0101(void);
  198. void alt0011(void);
  199. void alt01100(void);
  200. void delete_vals(void);
  201. void insert_val(void);
  202. void replace_val(void);
  203. void ascending_order(void);
  204. void alt0r0r(void);
  205. void altr0r0(void);
  206. void alt00rr(void);
  207. void altrr00(void);
  208. void alt0rr00r(void);
  209. void altr00rr0(void);
  210. void alt00RR(void);
  211. void altRR00(void);
  212. void alt0RR00R(void);
  213. void altR00RR0(void);
  214. void create_intervals_from_base(void);
  215. void create_ratios_from_base(void);
  216. void create_equal_vals(void);
  217. void quantised_scatter(int *perm,int permlen);
  218. void replace_equal(void);
  219. void replace_less(void);
  220. void replace_greater(void);
  221. void grid(int isoutside);
  222. void randdel_not_adjacent(void);
  223. void replace_with_rand(int i);
  224. void randquanta_in_gaps(void);
  225. void reverse_time_intervals(void);
  226. void invert_normd_env(void);
  227. void invert_over_range(void);
  228. void invert_around_pivot(void);
  229. void join_files_as_rows(void);
  230. void join_many_files_as_rows(void);
  231. void env_superimpos(int inverse,int typ);
  232. void env_del_inv(void);
  233. void env_plateau(void);
  234. void time_from_beat_position(int has_offset);
  235. void insert_after_val(void);
  236. void min_interval(int ismax);
  237. void mark_multiples(void);
  238. void insert_in_order(void);
  239. void insert_at_start(void);
  240. void insert_at_end(void);
  241. void format_strs(void);
  242. void column_format_strs(void);
  243. void random_integers(void);
  244. void random_integers_evenly_spread(void);
  245. void time_from_bar_beat_metre_tempo(int has_offset);
  246. void brk_add(void);
  247. void brk_subtract(void);
  248. void span_rise(void);
  249. void span_fall(void);
  250. void span_all(void);
  251. void span_xall(void);
  252. void cyclic_select(char c);
  253. void generate_randomised_vals(void);
  254. void ratio_to_interval(int semitones,int tstretch);
  255. void pitch_to_delay(int midi);
  256. void delay_to_pitch(int midi);
  257. void reverse_order_of_brkvals(void);
  258. void thresh_cut(void);
  259. void band_cut(void);
  260. int do_stringline_infile(char *argv,int i);
  261. int do_other_stringline_infile(char *argv);
  262. void do_other_stringline_infiles(char *argv[],char c);
  263. void do_inline_cnt(int n,char *argv);
  264. void scale_above(void);
  265. void scale_below(void);
  266. void scale_from(void);
  267. void env_append(void);
  268. void abutt(void);
  269. void quantise_time(void);
  270. void quantise_val(void);
  271. void expand_table_dur_by_factor(void);
  272. void expand_table_dur_to_time(void);
  273. void expand_table_vals_by_factor(void);
  274. void cut_table_at_time(void);
  275. void limit_table_val_range(void);
  276. void expand_table_to_dur(void);
  277. void extend_table_to_dur(void);
  278. void do_error(void);
  279. void do_valout(double val);
  280. void do_stringout(char *str);
  281. void do_valout_as_message(double val);
  282. void do_valout_flush(double val);
  283. void do_valpair_out(double val0,double val1);
  284. void note_to_midi(int is_transpos);
  285. void substitute(void);
  286. void substitute_all(void); /*TW March 2004 */
  287. void mean_of_reversed_pairs(void);
  288. void duplicate_values_stepped(void);
  289. void kill_text(int after);
  290. void append_text(int where);
  291. void targeted_pan(void);
  292. void targeted_stretch(void);
  293. void do_squeezed_pan(void);
  294. void kill_path(void);
  295. void kill_extension(void);
  296. void kill_path_and_extension(void);
  297. void convert_space_pan_to_tex(void);
  298. void convert_space_tex_to_pan(void);
  299. extern char errstr[];
  300. extern int colcnt, *cntr;
  301. extern int *file_cnt;
  302. extern int sloom;
  303. extern int sloombatch;
  304. extern int hasoutfile;
  305. extern char outfilename[];
  306. void compress_sequence(int multi); /* Wc */
  307. void transpose_sequence(int multi); /* Wt */
  308. void p_invertset_sequence(int multi); /* WI */
  309. void p_expandset_sequence(int multi); /* WE */
  310. void p_invert_sequence(int multi); /* Wi */
  311. void t_reverse_sequence(int multi); /* Wr */
  312. void p_reverse_sequence(int multi); /* WP */
  313. void a_reverse_sequence(int multi); /* WA */
  314. void pa_reverse_sequence(int multi); /* WR */
  315. void tp_reverse_sequence(int multi); /* WT */
  316. void ta_reverse_sequence(int multi); /* Wa */
  317. void tpa_reverse_sequence(int multi); /* WZ */
  318. void loop_sequence(int); /* Wl */
  319. void abut_sequences(int); /* Wb */
  320. void uptempo_sequence(int); /* Wm */
  321. void accel_sequence(int); /* WM */
  322. void create_equal_steps(void); /* iQ */
  323. void mean_tempo(void); /* te */
  324. void time_to_crotchets(int beatvals); /* tB,tC */
  325. void rotate_list(int reversed); /* rR, rX */
  326. void splice_pos(void); /* SM */
  327. void time_warp(void); /* ew */
  328. void brkval_warp(void); /* eX */
  329. void brktime_warp(void); /* eW */
  330. void duplicate_list_at_step(void); /* dL */
  331. void list_warp(void); /* eL */
  332. void seqtime_warp(void); /* eQ */
  333. void tw_pseudo_exp(void); /* ze */
  334. void reverse_time_intervals2(void); /* tR */
  335. void interp_n_vals(void); /* IV */
  336. void convert_to_edits(void); /* sE */
  337. void cosin_spline(void); /* cs */
  338. void distance_from_grid(void); /* dg */
  339. void sinusoid(void); /* ss */
  340. void warped_times(int isdiff); /* wt, wo */
  341. void random_pairs(void); /* rG */
  342. void random_pairs_restrained(void); /* rJ */
  343. void cumuladd(void); /* ga */
  344. void randomise_Ntimes(int *perm); /* Rx */
  345. void tw_psuedopan(void); /* pp */
  346. //double drand48(void);
  347. //void initrand48(void);
  348. void rand_ints_with_fixed_ends(void); /* ri */
  349. void rand_zigs(void); /* zz */
  350. void eliminate_dupltext(void); /* eb */
  351. void sinjoin(char val); /* sc, sv, sx */
  352. void brktime_owarp(void); /* eY */
  353. void just_intonation_Hz(void); /* Zh */
  354. void just_intonation_midi(void); /* ZM */
  355. void create_just_intonation_Hz(void); /* ZH */
  356. void create_just_intonation_midi(void); /* Zm */
  357. void insert_intermediate_valp(void); /* ip */
  358. void random_warp(void); /* Zs */