- Joined
- Mar 11, 2022
- Messages
- 226
- Reaction score
- 32
On my Weekend i was fooling around with ChatGPT. Well, to say "im impressed" is a sheer understatement. Holy sh....
I let it do a couple tasks. From easy PHP to heavy Java and Kotlin. In the middle of it of course also Javascript.
I gave it a task to code an organ which can be played on the computer keyboard. y(german keyboard) to M (white keys), A to l (black keys). Of course it messed up, but unfortunately not that much. This is only V3 (2021) V4 is coming in weeks (which reach a completely new level).
But let's just check out the organ of V3. I never had a hand in it. Just copy and paste. Woooooooooow.
https://jsfiddle.net/kwngjfet/
Or for those who can't wait
I let it do a couple tasks. From easy PHP to heavy Java and Kotlin. In the middle of it of course also Javascript.
I gave it a task to code an organ which can be played on the computer keyboard. y(german keyboard) to M (white keys), A to l (black keys). Of course it messed up, but unfortunately not that much. This is only V3 (2021) V4 is coming in weeks (which reach a completely new level).
But let's just check out the organ of V3. I never had a hand in it. Just copy and paste. Woooooooooow.
https://jsfiddle.net/kwngjfet/
Or for those who can't wait
Code:
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Define the frequencies of the notes
const notes = {
"y": 261.63,
"x": 277.18,
"c": 293.66,
"v": 311.13,
"b": 329.63,
"n": 349.23,
"m": 369.99,
"a": 392.00,
"s": 415.30,
"d": 440.00,
"f": 466.16,
"g": 493.88,
"h": 523.25,
"j": 554.37,
"k": 587.33,
"l": 622.25,
"w": 659.25,
"e": 698.46,
"r": 739.99,
"t": 783.99,
"z": 830.61,
"u": 880.00,
"i": 932.33,
"o": 987.77,
"p": 1046.50
};
let oscillators = {};
document.addEventListener("keydown", (event) => {
if (event.key in notes) {
if(!(event.key in oscillators)){
oscillators[event.key] = audioCtx.createOscillator();
oscillators[event.key].frequency.value = notes[event.key];
oscillators[event.key].type = "sine";
oscillators[event.key].connect(audioCtx.destination);
oscillators[event.key].start();
}
}
});
document.addEventListener("keyup", (event) => {
if (event.key in oscillators) {
oscillators[event.key].stop();
delete oscillators[event.key];
}
});