A lot of people knows this command from QuickBasic.
Yes, I know, its 15 years to late...
But here is it. The "play"-function for PureBasic.
Reference:
Playspeed : t{value from 0 to 255} Example: t100
Notelenght : l{value from 0 to 255} Example: l100
Octave : o{value from 0 to 255} Example: o2
Notes:
- c
#c
d
#d
e
f
#f
g
#g
a
#a
b (like german h)
The notes with rhombus sounds a halftone higher.
Important: Set spaces between the commands.
Code: Select all
Procedure PlayJob (a) ; Don't use this function
Shared ShNoten.s
octave.l=1
notelenght.l=100
speed.l=0
For x=1 To CountString (ShNoten.s,Chr(32))+1
part.s=Trim(LCase (StringField (ShNoten.s,x,Chr(32))))
Select part.s
Case "c"
Beep_(278*octave.l,notelenght.l)
Case "#c"
Beep_(295*octave.l,notelenght.l)
Case "d"
Beep_(313*octave.l,notelenght.l)
Case "#d"
Beep_(331*octave.l,notelenght.l)
Case "e"
Beep_(351*octave.l,notelenght.l)
Case "f"
Beep_(372*octave.l,notelenght.l)
Case "#f"
Beep_(394*octave.l,notelenght.l)
Case "g"
Beep_(417*octave.l,notelenght.l)
Case "#g"
Beep_(442*octave.l,notelenght.l)
Case "a"
Beep_(468*octave.l,notelenght.l)
Case "#a"
Beep_(496*octave.l,notelenght.l)
Case "b"
Beep_(526*octave.l,notelenght.l)
Case "p"
Delay (notelenght.l)
EndSelect
If Mid(part.s,1,1)="o": octave.l=Val(Mid(part.s,2,1)) :psoff.l=1:EndIf
If octave.l<1:octave.l=1:EndIf
If octave.l>4:octave.l=4:EndIf
If Mid(part.s,1,1)="l": notelenght.l=Val(Mid(part.s,2,Len(part.s)-1)):psoff.l=1 :EndIf
If notelenght.l<1:notelenght.l=1:EndIf
If notelenght.l>255:notelenght.l=255:EndIf
If Mid(part.s,1,1)="t": tempo.l=Val(Mid(part.s,2,Len(part.s)-1)) :psoff.l=1:EndIf
If tempo.l<1:tempo.l=1:EndIf
If tempo.l>255:tempo.l=255:EndIf
If psoff.l=0 And part.s<>"":Delay (255-tempo.l):EndIf
psoff.l=0
Next x
EndProcedure
Procedure PlayMelody (noten.s)
Shared ShNoten.s
ShNoten.s=noten.s
CreateThread(@PlayJob(),0)
EndProcedure
PlayMelody ("t200 l50 o1 c e g c e g c e g e g b e g b f a c f a c f a c b g e b g e b g e o2 l50 c e g c e g c e g e g b e g b f a c f a c f a c b g e b g e b g e ")
MessageRequester ("Pure playing","Music non stop ;-)",0)
Feel free to optimize this code how ever you want.