support for piano
This commit is contained in:
parent
4c62df1112
commit
d858bd0fe8
@ -8,7 +8,7 @@ namespace music {
|
|||||||
*/
|
*/
|
||||||
//% help=music/play-tone weight=90
|
//% help=music/play-tone weight=90
|
||||||
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
|
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
|
||||||
//% parts="speaker" async
|
//% parts="speaker" async useEnumVal=1
|
||||||
void playTone(int frequency, int ms) {
|
void playTone(int frequency, int ms) {
|
||||||
if(frequency > 0) uBit.soundmotor.soundOn(frequency);
|
if(frequency > 0) uBit.soundmotor.soundOn(frequency);
|
||||||
else uBit.soundmotor.soundOff();
|
else uBit.soundmotor.soundOff();
|
||||||
|
@ -1,112 +1,112 @@
|
|||||||
enum Note {
|
enum Note {
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=262
|
||||||
C = 262,
|
C = 262,
|
||||||
//% block=C#
|
//% block=C#
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=277
|
||||||
CSharp = 277,
|
CSharp = 277,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=294
|
||||||
D = 294,
|
D = 294,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=311
|
||||||
Eb = 311,
|
Eb = 311,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=330
|
||||||
E = 330,
|
E = 330,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=349
|
||||||
F = 349,
|
F = 349,
|
||||||
//% block=F#
|
//% block=F#
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=370
|
||||||
FSharp = 370,
|
FSharp = 370,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=392
|
||||||
G = 392,
|
G = 392,
|
||||||
//% block=G#
|
//% block=G#
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=415
|
||||||
GSharp = 415,
|
GSharp = 415,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=440
|
||||||
A = 440,
|
A = 440,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=466
|
||||||
Bb = 466,
|
Bb = 466,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=494
|
||||||
B = 494,
|
B = 494,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=131
|
||||||
C3 = 131,
|
C3 = 131,
|
||||||
//% block=C#3
|
//% block=C#3
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=139
|
||||||
CSharp3 = 139,
|
CSharp3 = 139,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=147
|
||||||
D3 = 147,
|
D3 = 147,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=156
|
||||||
Eb3 = 156,
|
Eb3 = 156,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=165
|
||||||
E3 = 165,
|
E3 = 165,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=175
|
||||||
F3 = 175,
|
F3 = 175,
|
||||||
//% block=F#3
|
//% block=F#3
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=185
|
||||||
FSharp3 = 185,
|
FSharp3 = 185,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=196
|
||||||
G3 = 196,
|
G3 = 196,
|
||||||
//% block=G#3
|
//% block=G#3
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=208
|
||||||
GSharp3 = 208,
|
GSharp3 = 208,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=220
|
||||||
A3 = 220,
|
A3 = 220,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=233
|
||||||
Bb3 = 233,
|
Bb3 = 233,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=247
|
||||||
B3 = 247,
|
B3 = 247,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=262
|
||||||
C4 = 262,
|
C4 = 262,
|
||||||
//% block=C#4
|
//% block=C#4
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=277
|
||||||
CSharp4 = 277,
|
CSharp4 = 277,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=294
|
||||||
D4 = 294,
|
D4 = 294,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=311
|
||||||
Eb4 = 311,
|
Eb4 = 311,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=330
|
||||||
E4 = 330,
|
E4 = 330,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=349
|
||||||
F4 = 349,
|
F4 = 349,
|
||||||
//% block=F#4
|
//% block=F#4
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=370
|
||||||
FSharp4 = 370,
|
FSharp4 = 370,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=392
|
||||||
G4 = 392,
|
G4 = 392,
|
||||||
//% block=G#4
|
//% block=G#4
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=415
|
||||||
GSharp4 = 415,
|
GSharp4 = 415,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=440
|
||||||
A4 = 440,
|
A4 = 440,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=466
|
||||||
Bb4 = 466,
|
Bb4 = 466,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=494
|
||||||
B4 = 494,
|
B4 = 494,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=523
|
||||||
C5 = 523,
|
C5 = 523,
|
||||||
//% block=C#5
|
//% block=C#5
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=555
|
||||||
CSharp5 = 555,
|
CSharp5 = 555,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=587
|
||||||
D5 = 587,
|
D5 = 587,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=622
|
||||||
Eb5 = 622,
|
Eb5 = 622,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=659
|
||||||
E5 = 659,
|
E5 = 659,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=698
|
||||||
F5 = 698,
|
F5 = 698,
|
||||||
//% block=F#5
|
//% block=F#5
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=740
|
||||||
FSharp5 = 740,
|
FSharp5 = 740,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=784
|
||||||
G5 = 784,
|
G5 = 784,
|
||||||
//% block=G#5
|
//% block=G#5
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=831
|
||||||
GSharp5 = 831,
|
GSharp5 = 831,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=880
|
||||||
A5 = 880,
|
A5 = 880,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=932
|
||||||
Bb5 = 932,
|
Bb5 = 932,
|
||||||
//% blockIdentity=music.noteFrequency
|
//% blockIdentity=music.noteFrequency enumval=988
|
||||||
B5 = 989,
|
B5 = 988,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BeatFraction {
|
enum BeatFraction {
|
||||||
@ -147,6 +147,7 @@ namespace music {
|
|||||||
//% help=music/ring-tone weight=80
|
//% help=music/ring-tone weight=80
|
||||||
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" blockGap=8
|
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" blockGap=8
|
||||||
//% parts="speaker" async
|
//% parts="speaker" async
|
||||||
|
//% useEnumVal=1
|
||||||
export function ringTone(frequency: number) {
|
export function ringTone(frequency: number) {
|
||||||
playTone(frequency, 0);
|
playTone(frequency, 0);
|
||||||
}
|
}
|
||||||
@ -157,7 +158,9 @@ namespace music {
|
|||||||
*/
|
*/
|
||||||
//% weight=50 help=music/note-frequency
|
//% weight=50 help=music/note-frequency
|
||||||
//% blockId=device_note block="%note"
|
//% blockId=device_note block="%note"
|
||||||
//% shim=TD_ID
|
//% shim=TD_ID blockHidden=true
|
||||||
|
//% blockFieldEditor="note_editor"
|
||||||
|
//% useEnumVal = 1
|
||||||
export function noteFrequency(name: Note): number {
|
export function noteFrequency(name: Note): number {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
2
libs/core/shims.d.ts
vendored
2
libs/core/shims.d.ts
vendored
@ -554,7 +554,7 @@ declare namespace music {
|
|||||||
*/
|
*/
|
||||||
//% help=music/play-tone weight=90
|
//% help=music/play-tone weight=90
|
||||||
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
|
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
|
||||||
//% parts="speaker" async shim=music::playTone
|
//% parts="speaker" async useEnumVal=1 shim=music::playTone
|
||||||
function playTone(frequency: number, ms: number): void;
|
function playTone(frequency: number, ms: number): void;
|
||||||
}
|
}
|
||||||
declare namespace pins {
|
declare namespace pins {
|
||||||
|
Loading…
Reference in New Issue
Block a user