pc-ops.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. (define-module (gac pc-ops)
  2. #:use-module (gac sg1)
  3. #:use-module (srfi srfi-1)
  4. #:export (transpositions
  5. transpose-all
  6. inversions
  7. reverse-all
  8. get-sc
  9. append-sc
  10. cons-sc
  11. choose-sc
  12. sc1+))
  13. (define
  14. (transpositions l)
  15. (define
  16. (rot o)
  17. (map
  18. (lambda (e)
  19. (remainder (+ o e) 12)) l))
  20. (map rot (iota 12)))
  21. set-classes
  22. '(0 1 2 3 4 5 6 7 8 9 10 11)
  23. '("c" "cs" "d" "ds" "e" "f" "fs" "g" "gs" "a" "as" "b")
  24. '((0 . "c") (1 . "cs") ...)
  25. (define %trichords '((0 1 2) (0 1 3) (0 2 3) (0 1 4)
  26. (0 3 4) (0 1 5) (0 4 5) (0 1 6)
  27. (0 5 6) (0 2 4) (0 2 5) (0 3 5)
  28. (0 2 6) (0 4 6) (0 2 7) (0 3 6)
  29. (0 3 7) (0 4 7) (0 4 8)))
  30. (transpose-all %trichords)
  31. (((0 1 2)
  32. "<c cs d>1" lilypond token
  33. $ lilypond chords.ly > evince chords.pdf
  34. writer > chords.ly
  35. reader = parser
  36. gac "guile assisted composition" "rare tropical fruit"
  37. Modules:
  38. sg1 "data" set classes
  39. pc-ops transposition inversion transpose-all multiplication alpha (1->1 mapping)
  40. ga "genetic algorithms"
  41. lily "writes"
  42. abc "writer"
  43. guido "writer"
  44. abcjs "writer"
  45. package it for guix
  46. guix install guile-gac
  47. (1 2 3)
  48. (2 3 4)
  49. (3 4 5)
  50. (4 5 6)
  51. (5 6 7)
  52. (6 7 8)
  53. (7 8 9)
  54. (8 9 10)
  55. (9 10 11)
  56. (10 11 0)
  57. (11 0 1))
  58. ((0 1 3)
  59. (1 2 4)
  60. (2 3 5)
  61. (3 4 6)
  62. (4 5 7)
  63. (5 6 8)
  64. (6 7 9)
  65. (7 8 10)
  66. (8 9 11)
  67. (9 10 0)
  68. (10 11 1)
  69. (11 0 2))
  70. ((0 2 3)
  71. (1 3 4)
  72. (2 4 5)
  73. (3 5 6)
  74. (4 6 7)
  75. (5 7 8)
  76. (6 8 9)
  77. (7 9 10)
  78. (8 10 11)
  79. (9 11 0)
  80. (10 0 1)
  81. (11 1 2))
  82. ((0 1 4)
  83. (1 2 5)
  84. (2 3 6)
  85. (3 4 7)
  86. (4 5 8)
  87. (5 6 9)
  88. (6 7 10)
  89. (7 8 11)
  90. (8 9 0)
  91. (9 10 1)
  92. (10 11 2)
  93. (11 0 3))
  94. ((0 3 4)
  95. (1 4 5)
  96. (2 5 6)
  97. (3 6 7)
  98. (4 7 8)
  99. (5 8 9)
  100. (6 9 10)
  101. (7 10 11)
  102. (8 11 0)
  103. (9 0 1)
  104. (10 1 2)
  105. (11 2 3))
  106. ((0 1 5)
  107. (1 2 6)
  108. (2 3 7)
  109. (3 4 8)
  110. (4 5 9)
  111. (5 6 10)
  112. (6 7 11)
  113. (7 8 0)
  114. (8 9 1)
  115. (9 10 2)
  116. (10 11 3)
  117. (11 0 4))
  118. ((0 4 5)
  119. (1 5 6)
  120. (2 6 7)
  121. (3 7 8)
  122. (4 8 9)
  123. (5 9 10)
  124. (6 10 11)
  125. (7 11 0)
  126. (8 0 1)
  127. (9 1 2)
  128. (10 2 3)
  129. (11 3 4))
  130. ((0 1 6)
  131. (1 2 7)
  132. (2 3 8)
  133. (3 4 9)
  134. (4 5 10)
  135. (5 6 11)
  136. (6 7 0)
  137. (7 8 1)
  138. (8 9 2)
  139. (9 10 3)
  140. (10 11 4)
  141. (11 0 5))
  142. ((0 5 6)
  143. (1 6 7)
  144. (2 7 8)
  145. (3 8 9)
  146. (4 9 10)
  147. (5 10 11)
  148. (6 11 0)
  149. (7 0 1)
  150. (8 1 2)
  151. (9 2 3)
  152. (10 3 4)
  153. (11 4 5))
  154. ((0 2 4)
  155. (1 3 5)
  156. (2 4 6)
  157. (3 5 7)
  158. (4 6 8)
  159. (5 7 9)
  160. (6 8 10)
  161. (7 9 11)
  162. (8 10 0)
  163. (9 11 1)
  164. (10 0 2)
  165. (11 1 3))
  166. ((0 2 5)
  167. (1 3 6)
  168. (2 4 7)
  169. (3 5 8)
  170. (4 6 9)
  171. (5 7 10)
  172. (6 8 11)
  173. (7 9 0)
  174. (8 10 1)
  175. (9 11 2)
  176. (10 0 3)
  177. (11 1 4))
  178. ((0 3 5)
  179. (1 4 6)
  180. (2 5 7)
  181. (3 6 8)
  182. (4 7 9)
  183. (5 8 10)
  184. (6 9 11)
  185. (7 10 0)
  186. (8 11 1)
  187. (9 0 2)
  188. (10 1 3)
  189. (11 2 4))
  190. ((0 2 6)
  191. (1 3 7)
  192. (2 4 8)
  193. (3 5 9)
  194. (4 6 10)
  195. (5 7 11)
  196. (6 8 0)
  197. (7 9 1)
  198. (8 10 2)
  199. (9 11 3)
  200. (10 0 4)
  201. (11 1 5))
  202. ((0 4 6)
  203. (1 5 7)
  204. (2 6 8)
  205. (3 7 9)
  206. (4 8 10)
  207. (5 9 11)
  208. (6 10 0)
  209. (7 11 1)
  210. (8 0 2)
  211. (9 1 3)
  212. (10 2 4)
  213. (11 3 5))
  214. ((0 2 7)
  215. (1 3 8)
  216. (2 4 9)
  217. (3 5 10)
  218. (4 6 11)
  219. (5 7 0)
  220. (6 8 1)
  221. (7 9 2)
  222. (8 10 3)
  223. (9 11 4)
  224. (10 0 5)
  225. (11 1 6))
  226. ((0 3 6)
  227. (1 4 7)
  228. (2 5 8)
  229. (3 6 9)
  230. (4 7 10)
  231. (5 8 11)
  232. (6 9 0)
  233. (7 10 1)
  234. (8 11 2)
  235. (9 0 3)
  236. (10 1 4)
  237. (11 2 5))
  238. ((0 3 7)
  239. (1 4 8)
  240. (2 5 9)
  241. (3 6 10)
  242. (4 7 11)
  243. (5 8 0)
  244. (6 9 1)
  245. (7 10 2)
  246. (8 11 3)
  247. (9 0 4)
  248. (10 1 5)
  249. (11 2 6))
  250. ((0 4 7)
  251. (1 5 8)
  252. (2 6 9)
  253. (3 7 10)
  254. (4 8 11)
  255. (5 9 0)
  256. (6 10 1)
  257. (7 11 2)
  258. (8 0 3)
  259. (9 1 4)
  260. (10 2 5)
  261. (11 3 6))
  262. ((0 4 8)
  263. (1 5 9)
  264. (2 6 10)
  265. (3 7 11)
  266. (4 8 0)
  267. (5 9 1)
  268. (6 10 2)
  269. (7 11 3)
  270. (8 0 4)
  271. (9 1 5)
  272. (10 2 6)
  273. (11 3 7)))
  274. (define (transpose-all chords)
  275. (map transpositions chords))
  276. (transpose-all %trichords)
  277. (define inversions
  278. '((0 . 0)
  279. (1 . 11)
  280. (2 . 10)
  281. (3 . 9)
  282. (4 . 8)
  283. (5 . 7)
  284. (6 . 6)))
  285. '(0 1 2) => '(0 11 10) => '(1 0 11)
  286. (map (compose inversions transpose-by-zero))
  287. ;; todo add alpha mappings from morris' composition with pitch classes
  288. (define
  289. (reverse-all lst)
  290. (map
  291. (lambda (x) (reverse x))
  292. lst))
  293. (define (get-sc setclass position)
  294. (list-ref setclass position))
  295. (define (append-sc sc1 sc2)
  296. (append sc1 sc2))
  297. (define (cons-sc sc1 sc2)
  298. (cons sc1 sc2))
  299. (define (choose-sc setclass)
  300. (list-ref setclass (random (length setclass))))
  301. ;; this can be used with get-sc e.g. (sc1+ (get-sc %trichords 1))
  302. (define (sc1+ setclass)
  303. (map (lambda (x) (1+ x)))
  304. setclass)