From 811346e83d4a7f6cd014085baa494f6e9d5b59b1 Mon Sep 17 00:00:00 2001 From: Daria Cotocu Date: Wed, 24 May 2023 17:24:34 +0100 Subject: [PATCH 1/5] Solmization added --- packages/core/test/solmization.test.js | 17 +++++++++++++++++ packages/core/util.mjs | 21 ++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 packages/core/test/solmization.test.js diff --git a/packages/core/test/solmization.test.js b/packages/core/test/solmization.test.js new file mode 100644 index 00000000..28528aef --- /dev/null +++ b/packages/core/test/solmization.test.js @@ -0,0 +1,17 @@ + +/*test for issue 302 support alternative solmization types */ +import { midi2note } from '../util.mjs'; + +console.log(midi2note(60, 'letters')); /* should be C4*/ +console.log(midi2note(60, 'solfeggio')); /* should be Do4*/ +console.log(midi2note(60, 'indian')); /* should be Sa4*/ +console.log(midi2note(60, 'german')); /* should be C4*/ +console.log(midi2note(60, 'byzantine')); /* should be Ni4*/ +console.log(midi2note(60, 'japanese')); /* should be I4*/ + +console.log(midi2note(70, 'letters')); /* should be Bb4*/ +console.log(midi2note(70, 'solfeggio')); /* should be Sib4*/ +console.log(midi2note(70, 'indian')); /* should be Ni4*/ +console.log(midi2note(70, 'german')); /* should be Hb4*/ +console.log(midi2note(70, 'byzantine')); /* should be Zob4*/ +console.log(midi2note(70, 'japanese')); /* should be To4*/ diff --git a/packages/core/util.mjs b/packages/core/util.mjs index 2b43cf0b..6c20cbd7 100644 --- a/packages/core/util.mjs +++ b/packages/core/util.mjs @@ -71,11 +71,26 @@ export const getFreq = (noteOrMidi) => { * @deprecated does not appear to be referenced or invoked anywhere in the codebase * @noAutocomplete */ -export const midi2note = (n) => { +/* added code from here to solve issue 302*/ + +export const midi2note = (n,notation = 'letters') => { + const solfeggio = ['Do','Reb','Re', 'Mib','Mi','Fa', 'Solb','Sol', 'Lab', 'La', 'Sib','Si']; /*solffegio notes*/ + const indian = ['Sa', 'Re', 'Ga', 'Ma', 'Pa', 'Dha', 'Ni']; /*indian musical notes, seems like they do not use flats or sharps*/ + const german = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A','Hb','H']; /*german & dutch musical notes*/ + const byzantine = ['Ni', 'Pab', 'Pa', 'Voub', 'Vou', 'Ga', 'Dib', 'Di', 'Keb', 'Ke', 'Zob','Zo']; /*byzantine musical notes*/ + const japanese = [ 'I', 'Ro', 'Ha', 'Ni' , 'Ho' , 'He', 'To']; /*traditional japanese musical notes, seems like they do not use falts or sharps*/ + const pc = notation === 'solfeggio' ? solfeggio : /*check if its is any of the following*/ + notation === 'indian' ? indian : + notation === 'german' ? german : + notation === 'byzantine' ? byzantine : + notation === 'japanese' ? japanese : + ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']; /*if not use standard version*/ + const note = pc[n % 12]; /*calculating the midi value to the note*/ const oct = Math.floor(n / 12) - 1; - const pc = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'][n % 12]; - return pc + oct; + return note + oct; }; +/*testing if the function works by using the file solmization.test.mjs + in the test folder*/ // modulo that works with negative numbers e.g. _mod(-1, 3) = 2. Works on numbers (rather than patterns of numbers, as @mod@ from pattern.mjs does) export const _mod = (n, m) => ((n % m) + m) % m; From ccf775e976767b950ce2477ae41bbea24abfb382 Mon Sep 17 00:00:00 2001 From: Daria Cotocu Date: Wed, 24 May 2023 17:57:05 +0100 Subject: [PATCH 2/5] Format code --- packages/core/test/solmization.test.js | 1 - packages/core/util.mjs | 59 ++++++++++++++++++++------ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/packages/core/test/solmization.test.js b/packages/core/test/solmization.test.js index 28528aef..0c04a190 100644 --- a/packages/core/test/solmization.test.js +++ b/packages/core/test/solmization.test.js @@ -1,4 +1,3 @@ - /*test for issue 302 support alternative solmization types */ import { midi2note } from '../util.mjs'; diff --git a/packages/core/util.mjs b/packages/core/util.mjs index 6c20cbd7..1e6d9a7b 100644 --- a/packages/core/util.mjs +++ b/packages/core/util.mjs @@ -73,18 +73,53 @@ export const getFreq = (noteOrMidi) => { */ /* added code from here to solve issue 302*/ -export const midi2note = (n,notation = 'letters') => { - const solfeggio = ['Do','Reb','Re', 'Mib','Mi','Fa', 'Solb','Sol', 'Lab', 'La', 'Sib','Si']; /*solffegio notes*/ - const indian = ['Sa', 'Re', 'Ga', 'Ma', 'Pa', 'Dha', 'Ni']; /*indian musical notes, seems like they do not use flats or sharps*/ - const german = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A','Hb','H']; /*german & dutch musical notes*/ - const byzantine = ['Ni', 'Pab', 'Pa', 'Voub', 'Vou', 'Ga', 'Dib', 'Di', 'Keb', 'Ke', 'Zob','Zo']; /*byzantine musical notes*/ - const japanese = [ 'I', 'Ro', 'Ha', 'Ni' , 'Ho' , 'He', 'To']; /*traditional japanese musical notes, seems like they do not use falts or sharps*/ - const pc = notation === 'solfeggio' ? solfeggio : /*check if its is any of the following*/ - notation === 'indian' ? indian : - notation === 'german' ? german : - notation === 'byzantine' ? byzantine : - notation === 'japanese' ? japanese : - ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']; /*if not use standard version*/ +export const midi2note = (n, notation = 'letters') => { + const solfeggio = ['Do', 'Reb', 'Re', 'Mib', 'Mi', 'Fa', 'Solb', 'Sol', 'Lab', 'La', 'Sib', 'Si']; /*solffegio notes*/ + const indian = [ + 'Sa', + 'Re', + 'Ga', + 'Ma', + 'Pa', + 'Dha', + 'Ni', + ]; /*indian musical notes, seems like they do not use flats or sharps*/ + const german = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Hb', 'H']; /*german & dutch musical notes*/ + const byzantine = [ + 'Ni', + 'Pab', + 'Pa', + 'Voub', + 'Vou', + 'Ga', + 'Dib', + 'Di', + 'Keb', + 'Ke', + 'Zob', + 'Zo', + ]; /*byzantine musical notes*/ + const japanese = [ + 'I', + 'Ro', + 'Ha', + 'Ni', + 'Ho', + 'He', + 'To', + ]; /*traditional japanese musical notes, seems like they do not use falts or sharps*/ + const pc = + notation === 'solfeggio' + ? solfeggio /*check if its is any of the following*/ + : notation === 'indian' + ? indian + : notation === 'german' + ? german + : notation === 'byzantine' + ? byzantine + : notation === 'japanese' + ? japanese + : ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']; /*if not use standard version*/ const note = pc[n % 12]; /*calculating the midi value to the note*/ const oct = Math.floor(n / 12) - 1; return note + oct; From cd7bc09f9c0d1b5ad263d1116144330d21fb82b1 Mon Sep 17 00:00:00 2001 From: Daria Cotocu Date: Wed, 24 May 2023 18:43:24 +0100 Subject: [PATCH 3/5] Update solmization.test.js --- packages/core/test/solmization.test.js | 52 ++++++++++++++++++++------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/packages/core/test/solmization.test.js b/packages/core/test/solmization.test.js index 0c04a190..7a91c3b9 100644 --- a/packages/core/test/solmization.test.js +++ b/packages/core/test/solmization.test.js @@ -1,16 +1,44 @@ /*test for issue 302 support alternative solmization types */ import { midi2note } from '../util.mjs'; +import { test } from 'vitest'; +import assert from 'assert'; + +test('midi2note - letters', () => { + const result = midi2note(60, 'letters'); + const expected = 'C4'; + assert.equal(result, expected); +}); + +test('midi2note - solfeggio', () => { + const result = midi2note(60, 'solfeggio'); + const expected = 'Do4'; + assert.equal(result, expected); +}); + + +test('midi2note - indian', () => { + const result = midi2note(60, 'indian'); + const expected = 'Sa4'; + assert.equal(result, expected); + }); + +test('midi2note - german', () => { + const result = midi2note(60, 'german'); + const expected = 'C4'; + assert.equal(result, expected); + }); + +test('midi2note - byzantine', () => { + const result = midi2note(60, 'byzantine'); + const expected = 'Ni4'; + assert.equal(result, expected); + }); + +test('midi2note - japanese', () => { + const result = midi2note(60, 'japanese'); + const expected = 'I4'; + assert.equal(result, expected); + }); + -console.log(midi2note(60, 'letters')); /* should be C4*/ -console.log(midi2note(60, 'solfeggio')); /* should be Do4*/ -console.log(midi2note(60, 'indian')); /* should be Sa4*/ -console.log(midi2note(60, 'german')); /* should be C4*/ -console.log(midi2note(60, 'byzantine')); /* should be Ni4*/ -console.log(midi2note(60, 'japanese')); /* should be I4*/ -console.log(midi2note(70, 'letters')); /* should be Bb4*/ -console.log(midi2note(70, 'solfeggio')); /* should be Sib4*/ -console.log(midi2note(70, 'indian')); /* should be Ni4*/ -console.log(midi2note(70, 'german')); /* should be Hb4*/ -console.log(midi2note(70, 'byzantine')); /* should be Zob4*/ -console.log(midi2note(70, 'japanese')); /* should be To4*/ From b63f4eb503db9edd4182d5895a33677b5440dc84 Mon Sep 17 00:00:00 2001 From: Daria Cotocu Date: Wed, 24 May 2023 18:58:11 +0100 Subject: [PATCH 4/5] Update solmization.test.js --- package.json | 6 +-- packages/core/test/solmization.test.js | 36 ++++++++--------- pnpm-lock.yaml | 54 ++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 76d60cb3..ee26531c 100644 --- a/package.json +++ b/package.json @@ -52,8 +52,7 @@ "@strudel.cycles/webaudio": "workspace:*", "@strudel.cycles/xen": "workspace:*", "acorn": "^8.8.1", - "dependency-tree": "^9.0.0", - "vitest": "^0.28.0" + "dependency-tree": "^9.0.0" }, "devDependencies": { "@vitest/ui": "^0.28.0", @@ -66,6 +65,7 @@ "jsdoc-to-markdown": "^8.0.0", "lerna": "^6.6.1", "prettier": "^2.8.8", - "rollup-plugin-visualizer": "^5.8.1" + "rollup-plugin-visualizer": "^5.8.1", + "vitest": "^0.28.0" } } diff --git a/packages/core/test/solmization.test.js b/packages/core/test/solmization.test.js index 7a91c3b9..fe66a4a8 100644 --- a/packages/core/test/solmization.test.js +++ b/packages/core/test/solmization.test.js @@ -15,30 +15,26 @@ test('midi2note - solfeggio', () => { assert.equal(result, expected); }); - test('midi2note - indian', () => { - const result = midi2note(60, 'indian'); - const expected = 'Sa4'; - assert.equal(result, expected); - }); + const result = midi2note(60, 'indian'); + const expected = 'Sa4'; + assert.equal(result, expected); +}); test('midi2note - german', () => { - const result = midi2note(60, 'german'); - const expected = 'C4'; - assert.equal(result, expected); - }); + const result = midi2note(60, 'german'); + const expected = 'C4'; + assert.equal(result, expected); +}); test('midi2note - byzantine', () => { - const result = midi2note(60, 'byzantine'); - const expected = 'Ni4'; - assert.equal(result, expected); - }); + const result = midi2note(60, 'byzantine'); + const expected = 'Ni4'; + assert.equal(result, expected); +}); test('midi2note - japanese', () => { - const result = midi2note(60, 'japanese'); - const expected = 'I4'; - assert.equal(result, expected); - }); - - - + const result = midi2note(60, 'japanese'); + const expected = 'I4'; + assert.equal(result, expected); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a4df850b..3731b000 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,9 +28,6 @@ importers: dependency-tree: specifier: ^9.0.0 version: 9.0.0 - vitest: - specifier: ^0.28.0 - version: 0.28.0(@vitest/ui@0.28.0) devDependencies: '@vitest/ui': specifier: ^0.28.0 @@ -65,6 +62,9 @@ importers: rollup-plugin-visualizer: specifier: ^5.8.1 version: 5.9.0 + vitest: + specifier: ^0.28.0 + version: 0.28.0(@vitest/ui@0.28.0) packages/core: dependencies: @@ -3443,6 +3443,7 @@ packages: /@polka/url@1.0.0-next.21: resolution: {integrity: sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==} + dev: true /@proload/core@0.3.3: resolution: {integrity: sha512-7dAFWsIK84C90AMl24+N/ProHKm4iw0akcnoKjRvbfHifJZBLhaDsDus1QJmhG12lXj4e/uB/8mB/0aduCW+NQ==} @@ -3890,9 +3891,11 @@ packages: resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==} dependencies: '@types/chai': 4.3.4 + dev: true /@types/chai@4.3.4: resolution: {integrity: sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==} + dev: true /@types/debug@4.1.7: resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==} @@ -3969,6 +3972,7 @@ packages: /@types/node@18.11.18: resolution: {integrity: sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==} + dev: true /@types/node@18.16.3: resolution: {integrity: sha512-OPs5WnnT1xkCBiuQrZA4+YAV4HEJejmHneyraIaxsbev5yCEr6KMwINNFP9wQeFIw8FWcoTqF3vQsa5CDaI+8Q==} @@ -4422,6 +4426,7 @@ packages: '@vitest/spy': 0.28.0 '@vitest/utils': 0.28.0 chai: 4.3.7 + dev: true /@vitest/runner@0.28.0: resolution: {integrity: sha512-SXQO9aubp7Hg4DV4D5DP70wJ/4o0krH1gAPrSt+rhEZQbQvMaBJAHWOxEibwzLkklgoHreaMEvETFILkGQWXww==} @@ -4429,11 +4434,13 @@ packages: '@vitest/utils': 0.28.0 p-limit: 4.0.0 pathe: 1.1.0 + dev: true /@vitest/spy@0.28.0: resolution: {integrity: sha512-gYBDQIP0QDvxrscl2Id0BTbzLUbuAzFiFur3eHxH9Yt5cM6YCH/kxBrSHhmXTbu92UenLx53Gwq17u5N0zGNDQ==} dependencies: tinyspy: 1.0.2 + dev: true /@vitest/ui@0.28.0: resolution: {integrity: sha512-ihcVEx8t1gZXMboPGcIvoHk+PxiW5USxDMqnZOeUVIUm+XrRCtoJ96YDXdeR6MyPWeYLBPXfBWSxp5gMqoNSkw==} @@ -4443,6 +4450,7 @@ packages: pathe: 1.1.0 picocolors: 1.0.0 sirv: 2.0.2 + dev: true /@vitest/utils@0.28.0: resolution: {integrity: sha512-Dt+jDZbwriZWzJ5Hi9nAUnz9IPgNb+ACE96tWiXPp/u9NmCYWIWcuNoUOYS8HQyGFz31GiNYGvaZ4ZEDjAgi1g==} @@ -4452,6 +4460,7 @@ packages: loupe: 2.3.6 picocolors: 1.0.0 pretty-format: 27.5.1 + dev: true /@vscode/emmet-helper@2.8.6: resolution: {integrity: sha512-IIB8jbiKy37zN8bAIHx59YmnIelY78CGHtThnibD/d3tQOKRY83bYVi9blwmZVUZh6l9nfkYH3tvReaiNxY9EQ==} @@ -4517,6 +4526,7 @@ packages: /acorn-walk@8.2.0: resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} engines: {node: '>=0.4.0'} + dev: true /acorn@8.8.2: resolution: {integrity: sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==} @@ -4641,6 +4651,7 @@ packages: /ansi-styles@5.2.0: resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} engines: {node: '>=10'} + dev: true /ansi-styles@6.2.1: resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==} @@ -4790,6 +4801,7 @@ packages: /assertion-error@1.1.0: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} + dev: true /ast-module-types@3.0.0: resolution: {integrity: sha512-CMxMCOCS+4D+DkOQfuZf+vLrSEmY/7xtORwdxs4wtcC1wVgvk2MqFFTwQCFhvWsI4KPU9lcWXPI8DgRiz+xetQ==} @@ -5059,6 +5071,7 @@ packages: /buffer-from@1.1.2: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} + dev: true /buffer@5.7.1: resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} @@ -5109,6 +5122,7 @@ packages: /cac@6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} + dev: true /cacache@16.1.3: resolution: {integrity: sha512-/+Emcj9DAXxX4cwlLmRI9c166RuL3w30zp4R7Joiv2cQTtTtA+jeuCAjH3ZlGnYS3tKENSrKhAzVVP9GVyzeYQ==} @@ -5238,6 +5252,7 @@ packages: loupe: 2.3.6 pathval: 1.1.1 type-detect: 4.0.8 + dev: true /chalk@2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} @@ -5285,6 +5300,7 @@ packages: /check-error@1.0.2: resolution: {integrity: sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==} + dev: true /chokidar@3.5.3: resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==} @@ -5359,6 +5375,7 @@ packages: dependencies: slice-ansi: 5.0.0 string-width: 5.1.2 + dev: true /cli-width@3.0.0: resolution: {integrity: sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw==} @@ -5838,6 +5855,7 @@ packages: engines: {node: '>=6'} dependencies: type-detect: 4.0.8 + dev: true /deep-extend@0.6.0: resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==} @@ -7036,6 +7054,7 @@ packages: /get-func-name@2.0.0: resolution: {integrity: sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==} + dev: true /get-intrinsic@1.2.0: resolution: {integrity: sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==} @@ -7867,6 +7886,7 @@ packages: /is-fullwidth-code-point@4.0.0: resolution: {integrity: sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==} engines: {node: '>=12'} + dev: true /is-glob@4.0.3: resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} @@ -8510,6 +8530,7 @@ packages: /local-pkg@0.4.3: resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==} engines: {node: '>=14'} + dev: true /locate-path@2.0.0: resolution: {integrity: sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==} @@ -8602,6 +8623,7 @@ packages: resolution: {integrity: sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==} dependencies: get-func-name: 2.0.0 + dev: true /lru-cache@5.1.1: resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} @@ -9496,6 +9518,7 @@ packages: pathe: 1.1.0 pkg-types: 1.0.2 ufo: 1.1.1 + dev: true /modify-values@1.0.1: resolution: {integrity: sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==} @@ -9541,6 +9564,7 @@ packages: /mrmime@1.0.1: resolution: {integrity: sha512-hzzEagAgDyoU1Q6yg5uI+AorQgdvMCur3FcKf7NhMKWsaYg+RnbTyHRa/9IlLF9rf455MOCtcqqrQQ83pPP7Uw==} engines: {node: '>=10'} + dev: true /ms@2.0.0: resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} @@ -10221,6 +10245,7 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: yocto-queue: 1.0.0 + dev: true /p-locate@2.0.0: resolution: {integrity: sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==} @@ -10473,9 +10498,11 @@ packages: /pathe@1.1.0: resolution: {integrity: sha512-ODbEPR0KKHqECXW1GoxdDb+AZvULmXjVPy4rt+pGo2+TnjJTIPJQSVS6N63n8T2Ip+syHhbn52OewKicV0373w==} + dev: true /pathval@1.1.1: resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==} + dev: true /peggy@3.0.2: resolution: {integrity: sha512-n7chtCbEoGYRwZZ0i/O3t1cPr6o+d9Xx4Zwy2LYfzv0vjchMBU0tO+qYYyvZloBPcgRgzYvALzGWHe609JjEpg==} @@ -10552,6 +10579,7 @@ packages: jsonc-parser: 3.2.0 mlly: 1.2.0 pathe: 1.1.0 + dev: true /pkg@5.8.1: resolution: {integrity: sha512-CjBWtFStCfIiT4Bde9QpJy0KeH19jCfwZRJqHFDFXfhUklCx8JoFmMj3wgnEYIwGmZVNkhsStPHEOnrtrQhEXA==} @@ -10753,6 +10781,7 @@ packages: ansi-regex: 5.0.1 ansi-styles: 5.2.0 react-is: 17.0.2 + dev: true /pretty-format@29.4.3: resolution: {integrity: sha512-cvpcHTc42lcsvOOAzd3XuNWTcvk1Jmnzqeu+WsOuiPmxUJTnkbAcFNsRKvEpBEUFVUgy/GTZLulZDcDEi+CIlA==} @@ -10912,6 +10941,7 @@ packages: /react-is@17.0.2: resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} + dev: true /react-is@18.2.0: resolution: {integrity: sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==} @@ -11665,6 +11695,7 @@ packages: /siginfo@2.0.0: resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} + dev: true /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} @@ -11712,6 +11743,7 @@ packages: '@polka/url': 1.0.0-next.21 mrmime: 1.0.1 totalist: 3.0.0 + dev: true /sisteransi@1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} @@ -11730,6 +11762,7 @@ packages: dependencies: ansi-styles: 6.2.1 is-fullwidth-code-point: 4.0.0 + dev: true /smart-buffer@4.2.0: resolution: {integrity: sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==} @@ -11788,6 +11821,7 @@ packages: dependencies: buffer-from: 1.1.2 source-map: 0.6.1 + dev: true /source-map@0.5.7: resolution: {integrity: sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==} @@ -11870,6 +11904,7 @@ packages: /stackback@0.0.2: resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} + dev: true /standardized-audio-context@25.3.37: resolution: {integrity: sha512-lr0+RH/IJXYMts95oYKIJ+orTmstOZN3GXWVGmlkbMj8OLahREkRh7DhNGLYgBGDkBkhhc4ev5pYGSFN3gltHw==} @@ -11881,6 +11916,7 @@ packages: /std-env@3.3.2: resolution: {integrity: sha512-uUZI65yrV2Qva5gqE0+A7uVAvO40iPo6jGhs7s8keRfHCmtg+uB2X6EiLGCI9IgL1J17xGhvoOqSz79lzICPTA==} + dev: true /stdopt@2.2.0: resolution: {integrity: sha512-D/p41NgXOkcj1SeGhfXOwv9z1K6EV3sjAUY5aeepVbgEHv7DpKWLTjhjScyzMWAQCAgUQys1mjH0eArm4cjRGw==} @@ -12051,6 +12087,7 @@ packages: resolution: {integrity: sha512-QZTsipNpa2Ppr6v1AmJHESqJ3Uz247MUS0OjrnnZjFAvEoWqxuyFuXn2xLgMtRnijJShAa1HL0gtJyUs7u7n3Q==} dependencies: acorn: 8.8.2 + dev: true /strong-log-transformer@2.1.0: resolution: {integrity: sha512-B3Hgul+z0L9a236FAUC9iZsL+nVHgoCJnqCbN588DjYxvGXaXaaFbfmQ/JhvKjZwsOukuR72XbHv71Qkug0HxA==} @@ -12337,14 +12374,17 @@ packages: /tinybench@2.5.0: resolution: {integrity: sha512-kRwSG8Zx4tjF9ZiyH4bhaebu+EDz1BOx9hOigYHlUW4xxI/wKIUQUqo018UlU4ar6ATPBsaMrdbKZ+tmPdohFA==} + dev: true /tinypool@0.3.1: resolution: {integrity: sha512-zLA1ZXlstbU2rlpA4CIeVaqvWq41MTWqLY3FfsAXgC8+f7Pk7zroaJQxDgxn1xNudKW6Kmj4808rPFShUlIRmQ==} engines: {node: '>=14.0.0'} + dev: true /tinyspy@1.0.2: resolution: {integrity: sha512-bSGlgwLBYf7PnUsQ6WOc6SJ3pGOcd+d8AA6EUnLDDM0kWEstC1JIlSZA3UNliDXhd9ABoS7hiRBDCu+XP/sf1Q==} engines: {node: '>=14.0.0'} + dev: true /tmp@0.0.33: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} @@ -12380,6 +12420,7 @@ packages: /totalist@3.0.0: resolution: {integrity: sha512-eM+pCBxXO/njtF7vdFsHuqb+ElbxqtI4r5EAvk6grfAFyJ6IvWlSkfZ5T9ozC6xWw3Fj1fGoSmrl0gUs46JVIw==} engines: {node: '>=6'} + dev: true /tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} @@ -12486,6 +12527,7 @@ packages: /type-detect@4.0.8: resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==} engines: {node: '>=4'} + dev: true /type-fest@0.13.1: resolution: {integrity: sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==} @@ -12586,6 +12628,7 @@ packages: /ufo@1.1.1: resolution: {integrity: sha512-MvlCc4GHrmZdAllBc0iUDowff36Q9Ndw/UzqmEKyrfSzokTd9ZCy1i+IIk5hrYKkjoYVQyNbrw7/F8XJ2rEwTg==} + dev: true /uglify-js@3.17.4: resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==} @@ -12961,6 +13004,7 @@ packages: - sugarss - supports-color - terser + dev: true /vite-plugin-pwa@0.14.7(vite@4.3.3)(workbox-build@6.5.4)(workbox-window@6.5.4): resolution: {integrity: sha512-dNJaf0fYOWncmjxv9HiSa2xrSjipjff7IkYE5oIUJ2x5HKu3cXgA8LRgzOwTc5MhwyFYRSU0xyN0Phbx3NsQYw==} @@ -13012,6 +13056,7 @@ packages: rollup: 3.21.0 optionalDependencies: fsevents: 2.3.2 + dev: true /vite@4.3.3(@types/node@18.16.3): resolution: {integrity: sha512-MwFlLBO4udZXd+VBcezo3u8mC77YQk+ik+fbc0GZWGgzfbPP+8Kf0fldhARqvSYmtIWoAJ5BXPClUbMTlqFxrA==} @@ -13109,6 +13154,7 @@ packages: - sugarss - supports-color - terser + dev: true /vscode-css-languageservice@6.2.3: resolution: {integrity: sha512-EAyhyIVHpEaf+GjtI+tVe7SekdoANfG0aubnspsQwak3Qkimn/97FpAufNyXk636ngW05pjNKAR9zyTCzo6avQ==} @@ -13296,6 +13342,7 @@ packages: dependencies: siginfo: 2.0.0 stackback: 0.0.2 + dev: true /wide-align@1.1.5: resolution: {integrity: sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==} @@ -13629,6 +13676,7 @@ packages: /yocto-queue@1.0.0: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} + dev: true /zod@3.21.4: resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==} From 190fe37a9f7612adfe85ac85858c9fa7384a2f96 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 11 Jun 2023 19:55:24 +0200 Subject: [PATCH 5/5] move solmization logic from midi2note to sol2note --- packages/core/test/solmization.test.js | 26 +++--- packages/core/util.mjs | 122 ++++++++++++------------- 2 files changed, 71 insertions(+), 77 deletions(-) diff --git a/packages/core/test/solmization.test.js b/packages/core/test/solmization.test.js index fe66a4a8..17352951 100644 --- a/packages/core/test/solmization.test.js +++ b/packages/core/test/solmization.test.js @@ -1,40 +1,40 @@ /*test for issue 302 support alternative solmization types */ -import { midi2note } from '../util.mjs'; +import { sol2note } from '../util.mjs'; import { test } from 'vitest'; import assert from 'assert'; -test('midi2note - letters', () => { - const result = midi2note(60, 'letters'); +test('solmization - letters', () => { + const result = sol2note(60, 'letters'); const expected = 'C4'; assert.equal(result, expected); }); -test('midi2note - solfeggio', () => { - const result = midi2note(60, 'solfeggio'); +test('solmization - solfeggio', () => { + const result = sol2note(60, 'solfeggio'); const expected = 'Do4'; assert.equal(result, expected); }); -test('midi2note - indian', () => { - const result = midi2note(60, 'indian'); +test('solmization - indian', () => { + const result = sol2note(60, 'indian'); const expected = 'Sa4'; assert.equal(result, expected); }); -test('midi2note - german', () => { - const result = midi2note(60, 'german'); +test('solmization - german', () => { + const result = sol2note(60, 'german'); const expected = 'C4'; assert.equal(result, expected); }); -test('midi2note - byzantine', () => { - const result = midi2note(60, 'byzantine'); +test('solmization - byzantine', () => { + const result = sol2note(60, 'byzantine'); const expected = 'Ni4'; assert.equal(result, expected); }); -test('midi2note - japanese', () => { - const result = midi2note(60, 'japanese'); +test('solmization - japanese', () => { + const result = sol2note(60, 'japanese'); const expected = 'I4'; assert.equal(result, expected); }); diff --git a/packages/core/util.mjs b/packages/core/util.mjs index f5af7151..3bad9199 100644 --- a/packages/core/util.mjs +++ b/packages/core/util.mjs @@ -67,78 +67,16 @@ export const getFreq = (noteOrMidi) => { return midiToFreq(noteToMidi(noteOrMidi)); }; - -/* added code from here to solve issue 302*/ -const solfeggio = ['Do', 'Reb', 'Re', 'Mib', 'Mi', 'Fa', 'Solb', 'Sol', 'Lab', 'La', 'Sib', 'Si']; /*solffegio notes*/ - const indian = [ - 'Sa', - 'Re', - 'Ga', - 'Ma', - 'Pa', - 'Dha', - 'Ni', - ]; /*indian musical notes, seems like they do not use flats or sharps*/ - const german = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Hb', 'H']; /*german & dutch musical notes*/ - const byzantine = [ - 'Ni', - 'Pab', - 'Pa', - 'Voub', - 'Vou', - 'Ga', - 'Dib', - 'Di', - 'Keb', - 'Ke', - 'Zob', - 'Zo', - ]; /*byzantine musical notes*/ - const japanese = [ - 'I', - 'Ro', - 'Ha', - 'Ni', - 'Ho', - 'He', - 'To', - ]; /*traditional japanese musical notes, seems like they do not use falts or sharps*/ - -const english = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'] - -export const sol2note = (n, notation = 'letters') => { - - const pc = - notation === 'solfeggio' - ? solfeggio /*check if its is any of the following*/ - : notation === 'indian' - ? indian - : notation === 'german' - ? german - : notation === 'byzantine' - ? byzantine - : notation === 'japanese' - ? japanese - : english; /*if not use standard version*/ - const note = pc[n % 12]; /*calculating the midi value to the note*/ - const oct = Math.floor(n / 12) - 1; - return note + oct; -}; - - const pcs = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']; /** - * @deprecated only used in workshop atm + * @deprecated only used in workshop (first-notes) * @noAutocomplete */ -export const midi2note = (n, notation = 'letters') => { +export const midi2note = (n) => { const oct = Math.floor(n / 12) - 1; - //return note + oct; const pc = pcs[n % 12]; return pc + oct; }; -/*testing if the function works by using the file solmization.test.mjs - in the test folder*/ // modulo that works with negative numbers e.g. _mod(-1, 3) = 2. Works on numbers (rather than patterns of numbers, as @mod@ from pattern.mjs does) export const _mod = (n, m) => ((n % m) + m) % m; @@ -277,3 +215,59 @@ export const splitAt = function (index, value) { export const zipWith = (f, xs, ys) => xs.map((n, i) => f(n, ys[i])); export const clamp = (num, min, max) => Math.min(Math.max(num, min), max); + +/* solmization, not used yet */ +const solfeggio = ['Do', 'Reb', 'Re', 'Mib', 'Mi', 'Fa', 'Solb', 'Sol', 'Lab', 'La', 'Sib', 'Si']; /*solffegio notes*/ +const indian = [ + 'Sa', + 'Re', + 'Ga', + 'Ma', + 'Pa', + 'Dha', + 'Ni', +]; /*indian musical notes, seems like they do not use flats or sharps*/ +const german = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Hb', 'H']; /*german & dutch musical notes*/ +const byzantine = [ + 'Ni', + 'Pab', + 'Pa', + 'Voub', + 'Vou', + 'Ga', + 'Dib', + 'Di', + 'Keb', + 'Ke', + 'Zob', + 'Zo', +]; /*byzantine musical notes*/ +const japanese = [ + 'I', + 'Ro', + 'Ha', + 'Ni', + 'Ho', + 'He', + 'To', +]; /*traditional japanese musical notes, seems like they do not use falts or sharps*/ + +const english = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']; + +export const sol2note = (n, notation = 'letters') => { + const pc = + notation === 'solfeggio' + ? solfeggio /*check if its is any of the following*/ + : notation === 'indian' + ? indian + : notation === 'german' + ? german + : notation === 'byzantine' + ? byzantine + : notation === 'japanese' + ? japanese + : english; /*if not use standard version*/ + const note = pc[n % 12]; /*calculating the midi value to the note*/ + const oct = Math.floor(n / 12) - 1; + return note + oct; +};