-
-
Save benwilhelm/d9a7708af1734294390f5b4347951930 to your computer and use it in GitHub Desktop.
Banjo and String
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
class Banjo { | |
strings = [ | |
new BanjoString({ basePitch: 62 }), | |
new BanjoString({ basePitch: 59 }), | |
new BanjoString({ basePitch: 55 }), | |
new BanjoString({ basePitch: 50 }), | |
new BanjoString({ basePitch: 67 }) | |
] | |
fretString(stringIndex, fret) { | |
if (stringIndex === 4 && fret > 0 && fret < 6) { | |
throw new Error (`Fret ${fret} does not exist on stringIndex 4`) | |
} | |
const fretPosition = stringIndex === 4 ? fret - 5 : fret | |
this.strings[stringIndex].fret(fretPosition) | |
} | |
pickString(stringIndex, strength) { | |
const tone = this.strings[stringIndex].pick(strength) | |
return {...tone, stringIndex} | |
} | |
} | |
class BanjoString { | |
fretPosition = 0 | |
constructor(opts = { basePitch: 0 }) { | |
this.basePitch = opts.basePitch | |
} | |
fret(fretPosition) { | |
this.fretPosition = fretPosition | |
} | |
pick(strength) { | |
return { | |
pitch: this.basePitch + this.fretPosition, | |
volume: strength, | |
duration: strength * strength | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment