Skip to content

Instantly share code, notes, and snippets.

@juanigaray
Created April 20, 2021 22:41
Show Gist options
  • Save juanigaray/630b1afacfa55d1dc4f01842a1e9d02b to your computer and use it in GitHub Desktop.
Save juanigaray/630b1afacfa55d1dc4f01842a1e9d02b to your computer and use it in GitHub Desktop.
/* 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
Copy link

Cafony commented Jun 20, 2022

Thanks for the code:
Im trying to make one code that transpose chords.
Can you translate this to C#.
Thanks

@juanigaray
Copy link
Author

@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