Skip to content

Instantly share code, notes, and snippets.

@benwilhelm
Created January 12, 2021 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benwilhelm/d9a7708af1734294390f5b4347951930 to your computer and use it in GitHub Desktop.
Save benwilhelm/d9a7708af1734294390f5b4347951930 to your computer and use it in GitHub Desktop.
Banjo and String
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