📜 ⬆️ ⬇️

Ovation. Do-it-yourself chord table using JS and HTML5

Idea


I wondered somehow with the aim of shaping my own web chord sign with the goal of telling the person what they were eating these chords with.

Yes, I didn’t want a simple sign, but a feature that I could do:
And that's how I did it ...

Facilities


By virtue of the last point of the plan of the conceived possibilities, I decided that I would do everything entirely with the help of JavaScript.
To output the sound, I used HTML5 audio as the most promising technology. Simply put, I didn’t smile at all about messing with Flash integration, which I, as an amateur with OpenSource, always treated with some suspicion.
For rendering chord fingering, the HTML5 canvas was perfect, because I needed a freely scalable chord grid.

Implementation


The first thing was made a simple virtual keyboard. The keys are many divs with onClick events, the slider is made using jQuery-UI.
')
keyboard

Then the table of chords was added, the player of simple melodies (melodies are written as a set of notes and delays between them in milliseconds), a guitar finger viewer.

Problems and Solutions


Sound

As it always happens, the first problems appeared with the first successes in the work on the project. Initially, playing chords was made very simple: when loading a page, JS generated 49 audio elements — one for each synthesizer key, each with a corresponding sound clip. And everything would be fine, only, as it turned out, neither Chrome, nor Opera could digest 49 open audio streams, some notes were simply eaten. I solved the problem very simply: I limited the number of audio elements to 8, with the load on them distributed over the round-robin. The obvious disadvantage of such a scheme is the need to change the source of the audio elements. Yes, it is not a problem on the local machine, but uploading sound files from the server is not at all instantaneous. In order to minimize this kind of delay to a minimum, I used preloading audio files into the browser cache. Made it very simple. An additional audio element is created, to which all the audio files that will be used by the keyboard are sequentially transferred. Delays, of course, remained, but they are already quite tolerant.

Guitar Chord Fingering

Another important problem for me was guitar fingering. And here it’s not even a beautiful drawing of a chord grid, which is more tedious than complex. The point in the selection of comfortable fingering.

The criteria of convenience highlighted by me:
All this was valiantly inscribed in one formula, which selects the most suitable guitar chord fingering for my table. Generated by the C chord fingering script:
guitar chord fingering
Selection of the fingering can still slow down the application a little, because There is a complete search of chord notes on the strings. The problem is not very acute for the reason that the selection takes place in a separate thread through Web Workers.

results


As a result, I got a convenient tool for finding and building chords, searching for suitable fingering, which is not a shame to show to the person above. The project code is available on github.com under the license CC BY-NC-SA 3.0 . I would be grateful for any help with the project, whether it is valuable advice or ready-made patch.
You can try the code in the work directly on github: demo .

Source: https://habr.com/ru/post/148314/


All Articles