Show HN: Play music by typing
benzguo.com
benzguo.com
// SETTINGS
var input = "rsa ecde srgu yhgr bv rsa ecde srgu yhgr bv hybtg ser erv";
input += " hybtg iii r hybtg ser erv tvr rrr rvgres rrr rvg rrr rvgres ";
input += "ggg rgh grs sxebbe cuuuhbgres grs sxebbe cbbbgvrsai";
var TIME_INTERVAL = 300;
// Add jquery
var script = document.createElement('script');
script.src = 'http://code.jquery.com/jquery-1.11.0.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
function play () {
// Sound array setup
var soundArray = [];
var down = $.Event("keydown");
var up = $.Event("keyup");
input = ' ' + input; // hack
for (var i = 0; i < input.length; ++i) {
soundArray.push(input.toUpperCase().charCodeAt(i));
}
// Start sound
var index = 0;
function playSound () {
up.which = soundArray[index];
$("body").trigger(up);
++index;
down.which = soundArray[index];
$("body").trigger(down);
// // is there another?
if (index < soundArray.length) {
setTimeout(playSound, TIME_INTERVAL);
}
}
playSound();
}
(function loadjQuery () {
if (typeof jQuery === 'undefined') {
setTimeout(loadjQuery, 100);
} else {
play();
}
})();"uyvyu,pl,ynuuupl,kmk,,uyvuyvyu,pl,ynuuupl,kmk,,uyvppp;[[;plp;;;pl,kmk,ynuu,,,kmmml;pl,,kuu,lp;[,lp;l,"
completely breaks it about half way through.
Anyway, cool hack!
Since KeyboardJS is already loaded via requirejs, we can require it and then use it to get the keyCode for each character in the for loop.
var KeyboardJS = require('lib/keyboard');
[...]
for (var i = 0; i < input.length; ++i) {
var code = KeyboardJS.key.code(input.charAt(i));
if (code) {
soundArray.push(code);
} else {
soundArray.push(32);
}
}
Here's an updated version of the script, using your example as input: https://gist.github.com/peterjmag/489364ca58330c348c33rsa ecde srgu yhgr bv rsa ecde srgu yhgr bv hybtg ser erv hybtg iii r hybtg ser erv tvr rrr rvgres rrr rvg rrr rvgres ggg rgh grs sxebbe cuuuhbgres grs sxebbe cbbbgvrsai
It'd be cool to integrate my site http://www.soundslice.com/ into this.
rsa ecde sghu bhg rvc (play this line twice)
hybtg xer erv hybtg iii hybtg xer erv tvr
rrr rvgres rrr rvg rrr rvgres ggg rgh
grs sxebbe cuuuhbgres grs sxebbe cbbbgvrsai
And a couple of additions:
rsa ece xdx szs
Play this one fast:
srghil;l xrtnio/o dvbj,. '''i (I couldn't find a high enough A)
rieudj rieudj b.v,to b.v,to tvfr tvxsf rybgjun tcdex
g e rvg e rvc
v s rcv s rce
(bhu g bhu g bhu g)
I love the idea of having a layout where all patterns are movable. Going diagonally up-right gives you whole tone steps, diagonally down-right gives you semitone steps. An octave is QT, a major triad is QSD, a minor triad is QWD, a major scale is QZSXDRVT or AWXECFTG or ASEDRVGB. I could pick this up right away, in some ways it's easier than the piano, which I've played a lot. I really wish there was touch response, but computer keyboards don't support it.The behavior of cmd as the pedal is a little weird. When you release the pedal, the sound should stop. Maybe it's just a Mac bug, though.
The top row seems to be an octave higher than it should be, that interferes with moveability. Though I understand you probably wanted to expand the range.
The idea of fully movable chords was drilled into my head by the design of the Ableton Push, and I've always loved it, though I think that's far more intuitive than this.
How does the ableton push solve this problem? Looking at a video it almost felt like they were switching modes for a scale (almost like a harp does with its pedals). I'm probably off here, but I couldn't quickly find docs on how it worked.
8[8 [;plol mum yhtg cec esaqa qwertyuiopluyn
tgytgytgytgy huyhuyhuyhuy 4iu4iu4iu4
Transposed down a half step to D-flat minor to better fit this thing's range. It's not a perfect transcription by any means (the arpeggio suffers from limited polyphony, for one), but it's pretty cool that it was so easy to get this far!More music please from the talented among us!
I've tried things like this before, but this is great.
I knew playing all those typing race games would come in handy one day!
https://gist.github.com/aclissold/c6dcdee3838f23cee7cd
…But I stopped caring when I got to filling in the dictionary of notes, so if somebody else wants to finish it, be my guest! ;]
Is a shame there are some chords that you can't play (chord: pressing notes at the same time), such as "yup". But I think is a hardware limitation rather than a bug in the JavaScript.
uyvyu,pl,ynuuupl,kmk,,uyvuyvyu,pl,ynuuupl,kmk,,uyvppp;[[;plp;;;pl,kmk,ynuu,,,kmmml;pl,,kuu,lp;[,lp;l,
I would love to hear nonsensical boops as I code.
<script data-main="js/app" src="js/require.js"></script>
That data-main attribute is a magic signal to require.js to load js/app.js. From there, app.js tells it what else to load.https://www.image-line.com/support/FLHelp/html/img_glob/qwer...
Also, perfect thing to test my N-key rollover keyboard (which only goes to 6 due to USB limitations...)!
236 236 ; 7;7;oi ibnji ibnjh 236 236 ; 7;7;oi ibnji ib
Maybe the keyboard makes different sounds sometimes? Or maybe I'm off by a key...
edit: is this open source such that people can contribute?
Also, you can make a key stay down by holding down Control (Command on a Mac)
I would like to same some kind of feedback, like piano diodes that get on and of for you to follow a tune or tell you when you get wrong.
d h dthc r rfvh cdey bx e d hdthc r rfvh rrthxrthr rtherthr c d h dthc r rfvh cdey bx
q s drd q s drd q s drd q s drd q s drd ...
The scales produced by typing along one row reminded me of the castle theme from Super Mario World. If my javascript-foo was greater, I would write a function that types this, but alas.
This is the best part of the app! A simple string is simplified music notation for this keyboard, and if you are a touch typist, that means you can play anything on the fly!