Created
April 20, 2021 22:41
-
-
Save juanigaray/630b1afacfa55d1dc4f01842a1e9d02b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* To be used with Deno as a CLI utility | |
* Trasposes a note a given number of semitones | |
* E.G: `deno transpose.ts D# 15` | |
* -> E | |
*/ | |
const notes = [ | |
"A", | |
"Bb", | |
"B", | |
"C", | |
"C#", | |
"D", | |
"D#", | |
"E", | |
"F", | |
"F#", | |
"G", | |
"G#", | |
]; | |
const transpose = ([note, sNum]: [string, string]) => { | |
if (isNaN(+sNum)) throw Error("invalid number"); | |
if (!notes.includes(note)) throw Error("Invalid note"); | |
const noteIndex = notes.indexOf(note); | |
const num = +sNum; | |
console.log(notes[(noteIndex + num) % notes.length]); | |
}; | |
if (Deno.args.length === 2) transpose([Deno.args[0], Deno.args[1]]); |
@Cafony sadly I do not know or care to learn new OOP languages but it should be trivial enough! If you have any questions about how the code works, send them my way!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code:
Im trying to make one code that transpose chords.
Can you translate this to C#.
Thanks