This is a js web application that tells you what chord you are playing on the piano in any inversion. Click or keypress the notes to build your chord! If you select two notes it will tell you what the interval is between those two notes.
I started by rewriting my previous C++ chord finder console application in javascript and added the web interface as I went.
Code is triggered by clicking or keypressing on the keyboard UI. Also using Automatic Semicolon Insertion.
// mouse click on piano key event
$(".key").click(function () {
//pass note id to add to chord
let noteCode = $(this).attr('id')
$(this).toggleClass("pressed") //toggle key color key when pressed
processDOMChord(noteCode, userChordIds)
})
// keyboard keypress event
$("html").keypress(function (element) {
let noteCode = keyMapping[element.which]
$("#" + noteCode).toggleClass("pressed")
processDOMChord(noteCode, userChordIds)
})
// reset button event
$(".reset").click(function (){
userChordIds.forEach((v)=>$("#" + v).toggleClass("pressed"))
userChordIds = []
processDOMChord(undefined, userChordIds)
})
Using Facebook's Jest for unit testing. Configured Travis-CI for continuos integration on every commit and pull request as well as coverage reporting from Coveralls
# download node modules locally
npm install
# run js tests
npm test
{
"build": "node env",
"test": "jest --coverage --coverageReporters=text-lcov | coveralls",
"jest-watch": "jest --watchAll --coverage",
"jest": "jest --coverage --coverageReporters=text-lcov | coveralls"
}
{
"build": "node env",
"test": "jest --coverage --coverageReporters=text-lcov",
"jest-watch": "jest --watchAll --coverage",
"jest": "jest --coverage --coverageReporters=text-lcov"
}
# download the repo locally from github and cd into the folder
gh repo clone ManuelVargas1251/Chord-Finder
cd Chord-Finder
# install dev node modules (includes browserify)
npm install
# build new bundle to view your changes
node_modules/.bin/browserify src/js/index.js > src/js/bundle.js
When testing sound locally I get CORS errors which prevent the sound from playing for security reasons. As a work around, run a local server from root:
npm install --global http-server
http-server ./
By using https://raw.githack.com/ I created a working lower environments to test code in any committed branch. I was also able to provide test statuses for every branch through Travis CI and Coveralls.