10
2
Task
You should write a program that when a button is pressed, it outputs a different sound for each key.
The keys that you will use are:
1!2"34$5%6^78*9(0qQwWeErtTyYuiIoOpPasSdDfgGhHjJklLzZxcCvVbBnm
The notes begin at C
and each key above adds one semitone.
Lets make it slightly easier for you though. You can choose between 2 similar tasks,
1) Output a different note when a key is pressed that continues until another key is pressed. This program runs indefinitely
2) Take a string as input that only contains the characters above that will output each note for exactly 1 second (0.05 second variation allowed)
Input
- A key being pressed
- A single string containing only the symbols above
Output
- A single musical note that sounds until another key is pressed
- A series of notes, each one 1 second long
Notes
Letter | Note
-------+-------
1 | C
! | C#
2 | D
" | D#
3 | E
4 | F
$ | F#
5 | G
% | G#
6 | A
^ | A#
7 | B
8 | C
* | C#
9 | D
( | D#
0 | E
q | F
Q | F#
w | G
W | G#
e | A
E | A#
r | B
t | C <-- middle C
T | C#
y | D
Y | D#
u | E
i | F
I | F#
o | G
O | G#
p | A
P | A#
a | B
s | C
S | C#
d | D
D | D#
f | E
g | F
G | F#
h | G
H | G#
j | A
J | A#
k | B
l | C
L | C#
z | D
Z | D#
x | E
c | F
C | F#
v | G
V | G#
b | A
B | A#
n | B
m | C
Rules
- You may choose between the tasks but please say which one in your answer
- You are given a ±0.05 second variation in task 2
- Each symbol along increments the tone by 1 semitone.
- The individual notes are shown above
- This is a code-golf so shortest code wins
This was originally taken from here with caird coinheringaahing's consent
To open this up to languages that don't have audio libraries, I recommend a third output format: a WAV file containing the option 2 output, written to stdout. That would allow entries in any language that can print binary data. – Ray – 2017-06-04T20:54:56.300