columns3.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 <columns.h>
  22. void do_shuffle(int, int);
  23. /**************************** M_REPOS ********************************/
  24. int m_repos(int j)
  25. {
  26. int n, m, k=cnt, OK, is_set = 0;
  27. int zib = -ifactor, zab = ifactor;
  28. for(n=0;n<k;n++) {
  29. OK = 1;
  30. if(n>j && !is_set) {
  31. zib++;
  32. zab++;
  33. is_set = 1;
  34. }
  35. for(m=zib;m<zab;m++) {
  36. if(n+m<0) continue;
  37. if(n+m>=cnt) break;
  38. if(flteq(fmod(number[j],12.0),fmod(number[n+m],12.0))) {
  39. OK = 0;
  40. break;
  41. }
  42. }
  43. if(OK) {
  44. do_shuffle(n,j);
  45. if(j>n)
  46. return(1); /* list shuffled forward */
  47. return(0); /* list not shuffled forward */
  48. }
  49. }
  50. return(-1);
  51. }
  52. /**************************** F_REPOS ********************************/
  53. int f_repos(int j)
  54. {
  55. int n, m, k=cnt-ifactor, OK, is_set = 0;
  56. double interval;
  57. int zib = -ifactor, zab = ifactor;
  58. for(n=0;n<k;n++) {
  59. OK = 1;
  60. if(n>j && !is_set) {
  61. zib++;
  62. zab++;
  63. is_set = 1;
  64. }
  65. for(m=zib;m<zab;m++) {
  66. if(n+m<0) continue;
  67. if(n+m>=cnt) break;
  68. interval = log(number[j]/number[n+m])/LOG_2_TO_BASE_E;
  69. interval = fmod(fabs(interval),1.0);
  70. if(interval<ONEMAX || interval>ONEMIN) {
  71. OK = 0;
  72. break;
  73. }
  74. }
  75. if(OK) {
  76. do_shuffle(n,j);
  77. if(j>n)
  78. return(1); /* list shuffled forward */
  79. return(0); /* list not shuffled forward */
  80. }
  81. }
  82. return(-1);
  83. }
  84. /**************************** DO_SHUFFLE ******************************/
  85. void do_shuffle(int n,int j)
  86. {
  87. int m;
  88. double keep = number[j];
  89. if(j > n) {
  90. for(m=j;m>n;m--)
  91. number[m] = number[m-1];
  92. } else {
  93. for(m=j;m<n;m++)
  94. number[m] = number[m+1];
  95. }
  96. number[n] = keep;
  97. }
  98. /************************* CHECK_FOR_CONDITIONAL ************************/
  99. void check_for_conditional(int *argc,char *argv[])
  100. {
  101. int n;
  102. char less_than, greater_than;
  103. int condit_set = 0;
  104. if(sloom) {
  105. less_than = '@';
  106. greater_than = '+';
  107. } else {
  108. less_than = '{';
  109. greater_than = '}';
  110. }
  111. for(n=1;n<*argc;n++) {
  112. if((condit = *argv[n])==less_than || condit==greater_than) {
  113. if(condit==less_than)
  114. condit = '<';
  115. else
  116. condit = '>';
  117. argv[n]++;
  118. if(sscanf(argv[n],"%lf",&thresh)!=1) {
  119. sprintf(errstr,"Cannot read conditional value.\n");
  120. do_error();
  121. }
  122. while(n<(*argc)-1) {
  123. *(argv+n) = *(argv+n+1);
  124. n++;
  125. }
  126. (*argc)--;
  127. condit_set = 1;
  128. }
  129. }
  130. if(!condit_set)
  131. condit = 0;
  132. }