texture1.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 <structures.h>
  25. #include <tkglobals.h>
  26. #include <globcon.h>
  27. #include <processno.h>
  28. #include <modeno.h>
  29. #include <arrays.h>
  30. #include <texture.h>
  31. #include <cdpmain.h>
  32. #include <sfsys.h>
  33. /********************* GETTING DATA VALUES VIA RAND PERMUTATIONS *************/
  34. static int delete_all_other_motifs(motifptr thismotif,dataptr dz);
  35. static int delete_motifs_before(motifptr thismotif,dataptr dz);
  36. static int delete_motifs_beyond(motifptr thismotif);
  37. /***************************** TEXTURE 1 ********************************
  38. * (1) Generating random permutations of sets of values, and delivering
  39. * the next value from one of these.
  40. * (2) Scattering values within a range.
  41. */
  42. /*************************** MAKE_TEXTURE *********************************/
  43. int make_texture(dataptr dz)
  44. {
  45. int exit_status;
  46. unsigned int texflag = dz->tex->txflag;
  47. display_virtual_time(0,dz);
  48. if(texflag & ISHARM) {
  49. if(texflag & IS_CLUMPED) {
  50. if((exit_status = do_clumped_hftexture(dz))<0)
  51. return(exit_status);
  52. } else {
  53. if((exit_status = do_simple_hftexture(dz))<0)
  54. return(exit_status);
  55. }
  56. } else {
  57. if((exit_status = do_texture(dz))<0)
  58. return(exit_status);
  59. }
  60. if((exit_status = delete_all_other_motifs(dz->tex->timeset,dz))<0)
  61. return(exit_status);
  62. return(FINISHED);
  63. }
  64. /****************************** GETVALUE **********************************
  65. *
  66. * Get value of a parameter, either from table, or fixed value.
  67. */
  68. int getvalue(int paramhi,int paramlo,double thistime,int z,double *val,dataptr dz)
  69. {
  70. int exit_status;
  71. double range;
  72. int is_swap = 0;
  73. if(dz->is_int[paramhi] || dz->is_int[paramlo]) {
  74. sprintf(errstr,"getvalue() called on integer parameter %d or %d\n",paramhi,paramlo);
  75. return(PROGRAM_ERROR);
  76. }
  77. if(dz->brk[paramhi]) {
  78. if((exit_status = read_value_from_brktable(thistime,paramhi,dz))<0)
  79. return(exit_status);
  80. }
  81. if(dz->brk[paramlo]) {
  82. if((exit_status = read_value_from_brktable(thistime,paramlo,dz))<0)
  83. return(exit_status);
  84. }
  85. if((range = dz->param[paramhi] - dz->param[paramlo])<0.0) {
  86. swap(&dz->param[paramhi],&dz->param[paramlo]);
  87. range = -range;
  88. is_swap = 1;
  89. }
  90. if(flteq(range,0.0)) {
  91. *val = dz->param[paramhi];
  92. if(is_swap)
  93. swap(&dz->param[paramhi],&dz->param[paramlo]);
  94. return(FINISHED);
  95. }
  96. if((exit_status = pscatx(range,dz->param[paramlo],z,val,dz))<0)
  97. return(exit_status);
  98. if(is_swap)
  99. swap(&dz->param[paramhi],&dz->param[paramlo]);
  100. return(FINISHED);
  101. }
  102. /****************************** IGETVALUE **********************************
  103. *
  104. * Get integer value of a parameter, either from table, or fixed value.
  105. */
  106. int igetvalue(int paramhi,int paramlo,double thistime,int z,int *ival,dataptr dz)
  107. {
  108. int exit_status;
  109. int irange;
  110. int a, is_swap = 0;
  111. if(!dz->is_int[paramhi] || !dz->is_int[paramlo]) {
  112. sprintf(errstr,"igetvalue() called on non-integer parameter %d or %d\n",paramhi,paramlo);
  113. return(PROGRAM_ERROR);
  114. }
  115. if(dz->brk[paramhi]) {
  116. if((exit_status = read_value_from_brktable(thistime,paramhi,dz))<0)
  117. return(exit_status);
  118. }
  119. if(dz->brk[paramlo]) {
  120. if((exit_status = read_value_from_brktable(thistime,paramlo,dz))<0)
  121. return(exit_status);
  122. }
  123. if((irange = dz->iparam[paramhi] - dz->iparam[paramlo])<0) {
  124. iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
  125. irange = -irange;
  126. is_swap = 1;
  127. }
  128. if(irange==0) {
  129. *ival = (int)dz->iparam[paramlo];
  130. if(is_swap)
  131. iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
  132. return(FINISHED);
  133. /* OCT 1997 replace ****
  134. } else if((exit_status = doperm(irange,z,&a,dz))<0)
  135. */
  136. /* BY */
  137. } else if((exit_status = doperm(irange+1,z,&a,dz))<0)
  138. /* because the range of an integer variable between(say) 3 & 7 is INCLUSIVELY 5, not 7-3) */
  139. return(exit_status);
  140. a = (int)(a + dz->iparam[paramlo]);
  141. *ival = a;
  142. if(is_swap)
  143. iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
  144. return(FINISHED);
  145. }
  146. /*************************** DELETE_ALL_OTHER_MOTIFS **********************************
  147. *
  148. * Deletes all other motifs in motif list.
  149. */
  150. int delete_all_other_motifs(motifptr thismotif,dataptr dz)
  151. {
  152. int exit_status;
  153. motifptr here = thismotif->next;
  154. if((exit_status = delete_motifs_before(thismotif,dz))<0)
  155. return(exit_status);
  156. if(here!=(motifptr)0) {
  157. if((exit_status = delete_motifs_beyond(here))<0)
  158. return(exit_status);
  159. }
  160. dz->tex->motifhead = thismotif;
  161. return(exit_status);
  162. }
  163. /********************** DELETE_MOTIFS_BEYOND ******************************
  164. *
  165. * Deletes motif-space from this space onwards.
  166. */
  167. int delete_motifs_beyond(motifptr thismotif)
  168. {
  169. motifptr start = thismotif;
  170. while(thismotif->next!=(motifptr)0)
  171. thismotif = thismotif->next;
  172. while(thismotif!=start) {
  173. thismotif = thismotif->last;
  174. free(thismotif->next);
  175. }
  176. thismotif->next = (motifptr)0;
  177. return(FINISHED);
  178. }
  179. /*********************** DELETE_MOTIFS_BEFORE ***************************
  180. *
  181. * Kill all motifs BEFORE this one in the motif list.
  182. */
  183. int delete_motifs_before(motifptr thismotif,dataptr dz)
  184. {
  185. motifptr here = dz->tex->motifhead;
  186. while(here!=thismotif) {
  187. if((here = here->next)==(motifptr)0) {
  188. sprintf(errstr,"Problem in delete_motifs_before()\n");
  189. return(PROGRAM_ERROR);
  190. }
  191. delete_notes_here_and_beyond(here->last->firstnote);
  192. free(here->last);
  193. here->last = (motifptr)0;
  194. }
  195. dz->tex->motifhead = thismotif;
  196. return(FINISHED);
  197. }