Build, search, and play chords.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. import {
  2. describe,
  3. it,
  4. expect,
  5. beforeEach,
  6. } from 'vitest';
  7. import {
  8. ChordBase,
  9. ChordComponent,
  10. ChordExtensionType,
  11. ChordModificationType,
  12. // constructChord,
  13. analyzeIntervals, getChordName,
  14. } from '../src';
  15. // describe('constructChord', () => {
  16. // it('works', () => {
  17. // const chord = constructChord({ pitchClass: 0 });
  18. // expect(chord).toEqual([0, 4, 7]);
  19. // });
  20. // });
  21. describe('analyzeChord', () => {
  22. describe('building', () => {
  23. let chord: number[];
  24. beforeEach(() => {
  25. chord = [];
  26. });
  27. describe('root', () => {
  28. beforeEach(() => {
  29. chord.push(0);
  30. });
  31. describe('major third', () => {
  32. beforeEach(() => {
  33. chord.push(4);
  34. });
  35. describe('perfect fifth', () => {
  36. beforeEach(() => {
  37. chord.push(7);
  38. });
  39. it('determines major chord', () => {
  40. expect(analyzeIntervals(chord)).toEqual({
  41. base: ChordBase.MAJOR,
  42. });
  43. });
  44. describe('major sixth', () => {
  45. beforeEach(() => {
  46. chord.push(9);
  47. });
  48. it('describes major sixth chord', () => {
  49. expect(analyzeIntervals(chord)).toEqual({
  50. base: ChordBase.MAJOR,
  51. extensions: [{
  52. type: ChordExtensionType.MAJOR,
  53. component: ChordComponent.SIXTH,
  54. }],
  55. });
  56. });
  57. });
  58. describe('minor seventh', () => {
  59. beforeEach(() => {
  60. chord.push(10);
  61. });
  62. it('describes dominant seventh chord', () => {
  63. expect(analyzeIntervals(chord)).toEqual({
  64. base: ChordBase.MAJOR,
  65. extensions: [{
  66. type: ChordExtensionType.DOMINANT,
  67. component: ChordComponent.SEVENTH,
  68. }],
  69. });
  70. });
  71. });
  72. describe('major seventh', () => {
  73. beforeEach(() => {
  74. chord.push(11);
  75. });
  76. it('describes major seventh chord', () => {
  77. expect(analyzeIntervals(chord)).toEqual({
  78. base: ChordBase.MAJOR,
  79. extensions: [{
  80. type: ChordExtensionType.MAJOR,
  81. component: ChordComponent.SEVENTH,
  82. }],
  83. });
  84. });
  85. });
  86. });
  87. describe('diminished fifth', () => {
  88. beforeEach(() => {
  89. chord.push(6);
  90. });
  91. describe('minor seventh', () => {
  92. beforeEach(() => {
  93. chord.push(10);
  94. });
  95. it('describes dominant seventh lowered fifth chord', () => {
  96. expect(analyzeIntervals(chord)).toEqual({
  97. base: ChordBase.MAJOR,
  98. modifications: [{
  99. type: ChordModificationType.LOWERED,
  100. component: ChordComponent.FIFTH,
  101. }],
  102. extensions: [{
  103. type: ChordExtensionType.DOMINANT,
  104. component: ChordComponent.SEVENTH,
  105. }],
  106. });
  107. });
  108. });
  109. describe('major seventh', () => {
  110. beforeEach(() => {
  111. chord.push(11);
  112. });
  113. it('describes major seventh lowered fifth chord', () => {
  114. expect(analyzeIntervals(chord)).toEqual({
  115. base: ChordBase.MAJOR,
  116. modifications: [{
  117. type: ChordModificationType.LOWERED,
  118. component: ChordComponent.FIFTH,
  119. }],
  120. extensions: [{
  121. type: ChordExtensionType.MAJOR,
  122. component: ChordComponent.SEVENTH,
  123. }],
  124. });
  125. });
  126. });
  127. });
  128. describe('augmented fifth', () => {
  129. beforeEach(() => {
  130. chord.push(8);
  131. });
  132. it('determines augmented chord', () => {
  133. expect(analyzeIntervals(chord)).toEqual({
  134. base: ChordBase.AUGMENTED,
  135. });
  136. });
  137. describe('minor seventh', () => {
  138. beforeEach(() => {
  139. chord.push(10);
  140. });
  141. it('describes augmented dominant seventh chord', () => {
  142. expect(analyzeIntervals(chord)).toEqual({
  143. base: ChordBase.AUGMENTED,
  144. extensions: [{
  145. type: ChordExtensionType.DOMINANT,
  146. component: ChordComponent.SEVENTH,
  147. }],
  148. });
  149. });
  150. });
  151. describe('major seventh', () => {
  152. beforeEach(() => {
  153. chord.push(11);
  154. });
  155. it('describes augmented major seventh chord', () => {
  156. expect(analyzeIntervals(chord)).toEqual({
  157. base: ChordBase.AUGMENTED,
  158. extensions: [{
  159. type: ChordExtensionType.MAJOR,
  160. component: ChordComponent.SEVENTH,
  161. }],
  162. });
  163. });
  164. });
  165. });
  166. });
  167. describe('minor third', () => {
  168. beforeEach(() => {
  169. chord.push(3);
  170. });
  171. describe('perfect fifth', () => {
  172. beforeEach(() => {
  173. chord.push(7);
  174. });
  175. it('determines minor chord', () => {
  176. expect(analyzeIntervals(chord)).toEqual({
  177. base: ChordBase.MINOR,
  178. });
  179. });
  180. describe('major sixth', () => {
  181. beforeEach(() => {
  182. chord.push(9);
  183. });
  184. it('describes minor sixth chord', () => {
  185. expect(analyzeIntervals(chord)).toEqual({
  186. base: ChordBase.MINOR,
  187. extensions: [{
  188. type: ChordExtensionType.MAJOR,
  189. component: ChordComponent.SIXTH,
  190. }],
  191. });
  192. });
  193. });
  194. describe('minor seventh', () => {
  195. beforeEach(() => {
  196. chord.push(10);
  197. });
  198. it('describes minor seventh chord', () => {
  199. expect(analyzeIntervals(chord)).toEqual({
  200. base: ChordBase.MINOR,
  201. extensions: [{
  202. type: ChordExtensionType.DOMINANT,
  203. component: ChordComponent.SEVENTH,
  204. }],
  205. });
  206. });
  207. });
  208. describe('major seventh', () => {
  209. beforeEach(() => {
  210. chord.push(11);
  211. });
  212. it('describes minor major seventh chord', () => {
  213. expect(analyzeIntervals(chord)).toEqual({
  214. base: ChordBase.MINOR,
  215. extensions: [{
  216. type: ChordExtensionType.MAJOR,
  217. component: ChordComponent.SEVENTH,
  218. }],
  219. });
  220. });
  221. });
  222. });
  223. describe('diminished fifth', () => {
  224. beforeEach(() => {
  225. chord.push(6);
  226. });
  227. it('determines diminished chord', () => {
  228. expect(analyzeIntervals(chord)).toEqual({
  229. base: ChordBase.DIMINISHED,
  230. });
  231. });
  232. describe('diminished seventh', () => {
  233. beforeEach(() => {
  234. chord.push(9);
  235. });
  236. it('describes diminished seventh chord', () => {
  237. expect(analyzeIntervals(chord)).toEqual({
  238. base: ChordBase.DIMINISHED,
  239. extensions: [{
  240. type: ChordExtensionType.DIMINISHED,
  241. component: ChordComponent.SEVENTH,
  242. }],
  243. });
  244. });
  245. });
  246. describe('minor seventh', () => {
  247. beforeEach(() => {
  248. chord.push(10);
  249. });
  250. it('describes diminished dominant seventh (half-diminished) chord', () => {
  251. expect(analyzeIntervals(chord)).toEqual({
  252. base: ChordBase.DIMINISHED,
  253. extensions: [{
  254. type: ChordExtensionType.DOMINANT,
  255. component: ChordComponent.SEVENTH,
  256. }],
  257. });
  258. });
  259. });
  260. describe('major seventh', () => {
  261. beforeEach(() => {
  262. chord.push(11);
  263. });
  264. it('describes diminished major seventh chord', () => {
  265. expect(analyzeIntervals(chord)).toEqual({
  266. base: ChordBase.DIMINISHED,
  267. extensions: [{
  268. type: ChordExtensionType.MAJOR,
  269. component: ChordComponent.SEVENTH,
  270. }],
  271. });
  272. });
  273. });
  274. });
  275. });
  276. });
  277. });
  278. describe('extensions', () => {
  279. it('analyzes complete ninth chords', () => {
  280. expect(analyzeIntervals([0, 4, 7, 10, 14])).toEqual({
  281. base: ChordBase.MAJOR,
  282. extensions: [
  283. {
  284. type: ChordExtensionType.DOMINANT,
  285. component: ChordComponent.SEVENTH,
  286. },
  287. {
  288. type: ChordExtensionType.MAJOR,
  289. component: ChordComponent.NINTH,
  290. },
  291. ],
  292. });
  293. });
  294. it('analyzes incomplete ninth chords', () => {
  295. expect(analyzeIntervals([0, 4, 7, 14])).toEqual({
  296. base: ChordBase.MAJOR,
  297. extensions: [
  298. {
  299. type: ChordExtensionType.MAJOR,
  300. component: ChordComponent.NINTH,
  301. },
  302. ],
  303. omissions: [ChordComponent.SEVENTH],
  304. });
  305. expect(analyzeIntervals([0, 4, 14])).toEqual({
  306. base: ChordBase.MAJOR,
  307. extensions: [
  308. {
  309. type: ChordExtensionType.MAJOR,
  310. component: ChordComponent.NINTH,
  311. },
  312. ],
  313. omissions: [ChordComponent.FIFTH, ChordComponent.SEVENTH],
  314. });
  315. });
  316. });
  317. describe('naming', () => {
  318. it('names major chords', () => {
  319. expect(getChordName(analyzeIntervals([0, 4, 7]))).toBe('');
  320. });
  321. it('names minor chords', () => {
  322. expect(getChordName(analyzeIntervals([0, 3, 7]))).toBe('minor');
  323. });
  324. it('names augmented chords', () => {
  325. expect(getChordName(analyzeIntervals([0, 4, 8]))).toBe('augmented');
  326. });
  327. it('names diminished chords', () => {
  328. expect(getChordName(analyzeIntervals([0, 3, 6]))).toBe('diminished');
  329. });
  330. it('names major seventh chords', () => {
  331. expect(getChordName(analyzeIntervals([0, 4, 7, 11]))).toBe('major seventh');
  332. });
  333. it('names minor seventh chords', () => {
  334. expect(getChordName(analyzeIntervals([0, 3, 7, 10]))).toBe('minor seventh');
  335. });
  336. it('names dominant seventh chords', () => {
  337. expect(getChordName(analyzeIntervals([0, 4, 7, 10]))).toBe('seventh');
  338. });
  339. it('names major ninth chords', () => {
  340. expect(getChordName(analyzeIntervals([0, 4, 7, 11, 14]))).toBe('major seventh ninth');
  341. });
  342. it('names minor ninth chords', () => {
  343. expect(getChordName(analyzeIntervals([0, 3, 7, 10, 14]))).toBe('minor seventh ninth');
  344. });
  345. it('names dominant ninth chords', () => {
  346. expect(getChordName(analyzeIntervals([0, 4, 7, 10, 14]))).toBe('seventh ninth');
  347. });
  348. it('names major eleventh chords', () => {
  349. expect(getChordName(analyzeIntervals([0, 4, 7, 11, 14, 18]))).toBe('major seventh ninth eleventh');
  350. });
  351. it('names minor eleventh chords', () => {
  352. expect(getChordName(analyzeIntervals([0, 3, 7, 10, 14, 18]))).toBe('minor seventh ninth eleventh');
  353. });
  354. it('names dominant eleventh chords', () => {
  355. expect(getChordName(analyzeIntervals([0, 4, 7, 10, 14, 18]))).toBe('seventh ninth eleventh');
  356. });
  357. it('names major thirteenth chords', () => {
  358. expect(getChordName(analyzeIntervals([0, 4, 7, 11, 14, 18, 21]))).toBe('major seventh ninth eleventh thirteenth');
  359. });
  360. it('names minor thirteenth chords', () => {
  361. expect(getChordName(analyzeIntervals([0, 3, 7, 10, 14, 18, 21]))).toBe('minor seventh ninth eleventh thirteenth');
  362. });
  363. it('names dominant thirteenth chords', () => {
  364. expect(getChordName(analyzeIntervals([0, 4, 7, 10, 14, 18, 21]))).toBe('seventh ninth eleventh thirteenth');
  365. });
  366. });
  367. });