Sign in to follow this  
Followers 0
crashdemons

PCSA Player and Keyboard

1 post in this topic

#1 ·  Posted (edited)

This is a Beep-form audio Player and keyboard

which use a not-so-original type of file format;

Part of the keyboard was created using Paulies Beep-Song script (The Frequency table was used in the keyboard)

PCSA_Keyboard.au3

[autoit]#include <Array.au3>

#include <GUIConstants.au3>

#Include <WinAPI.au3>

Func _PCSNotesToRaw($notes,$isstring=1)

If $isstring=1 Then $notes=StringSplit($notes,',')

$u=UBound($notes)-1

$rawbuff=''

For $i=1 To $u

$notesa=StringSplit($notes[$i],':')

If (UBound($notesa)-1)<2 Then ContinueLoop

$notesb=_DimToGIFDim($notesa[1])

$length=_DimToGIFDim($notesa[2])

$rawbuff&=Chr($notesb[0])&Chr($notesb[1])&Chr($length[0])&Chr($length[1])

Next

Return $rawbuff

EndFunc

Func _CountSets($i,$ii)

;counts the sets of $ii in $i and the remainder

;$ii should be smaller than $i

$r=StringSplit('..','')

$r[0]=0

$r[1]=0

If $ii>$i Then

$r[1]=$i

Return $r

EndIf

If $ii=$i Then

$r[0]=1

$r[1]=0

Return $r

EndIf

$r[0]=Int($i/$ii)

$r[1]=$i-($r[0]*$ii)

Return $r

EndFunc

Func _IsGIF($gifdata)

$gif98a=StringUpper(StringMid($gifdata,1,6))

If $gif98a="GIF89A" Then Return True

Return False

EndFunc

Func _GIFDimToDim($x,$xe)

Return $x+($xe*256)

EndFunc

Func _DimToGIFDim($x)

$o=_CountSets($x,256)

$xx=$o[1]

$xe=$o[0]

$o[0]=$xx

$o[1]=$xe

Return $o

EndFunc

Func _PCSPlayRaw($raw=-1,$speed=1)

; every 2 bytes adds up to each note

; 37 through 32,767

; (0x25 through 0x7FFF).

Global $_PCSLoad

;Global $_PCSTLenL, $PCSTPosS, $_PCSTPosL

Global $_PCSPosition

Global $_PCSPlaying

If $raw=-1 Then $raw=$_PCSLoad

$_PCSLoad=$raw

Dim $speed

$e=StringLen($raw)

;$len=_PCSGetLen($raw,1,$speed)

;GUICtrlSetData($_PCSTLenL,"Track Length: "&$len&"ms")

;_GUICtrlSlider_SetRange($PCSTPosS,0,$e)

$_PCSPlaying=1

;ConsoleWrite(@CRLF&"PCS Playing Raw..."&@CRLF)

$_PCSPosition=0

For $i=1 To $e Step 4

If $_PCSPlaying=0 Then ExitLoop

$note=_GIFDimToDim(Asc(StringMid($raw,$i ,1)),Asc(StringMid($raw,$i+1,1)))

$leng=_GIFDimToDim(Asc(StringMid($raw,$i+2,1)),Asc(StringMid($raw,$i+3,1)))

; ConsoleWrite($note&',')

If $note<37 Or $note>32767 Then

Sleep($leng*$speed)

Else

;Sleep($speed)

Beep($note,$leng*$speed)

EndIf

;If $_PCSPosition>0 Then

; $i=$_PCSPosition

; $_PCSPosition=0

;EndIf

;GUICtrlSetData($_PCSTPosL,Floor(($i/2)*$speed)&"ms")

;_GUICtrlSlider_SetPos($PCSTPosS, $i)

Next

EndFunc

Func FileOverwrite($file, $data)

$fh = FileOpen($file, 2 + 16)

$d = FileWrite($fh, StringToBinary($data))

FileClose($fh)

Return $d

EndFunc ;==>FileOverwrite

Global $KeyNotes=StringSplit("4186.01|3951.07|"& _

"3729.31|3520.00|3322.44|"& _

"3135.96|2959.96|2793.83|"& _

"2637.02|2489.02|2349.32|"& _

"2217.46|2093.00|1975.53|"& _

"1864.66|1760.00|1661.22|"& _

"1567.98|1479.98|1396.91|"& _

"1318.51|1244.51|1174.66|"& _

"1108.73|1046.50|987.767|"& _

"932.328|880.000|830.609|"& _

"783.991|739.989|698.456|"& _

"659.255|622.254|587.330|"& _

"554.365|523.251|493.883|"& _

"466.164|440.000|415.305|"& _

"391.995|369.994|349.228|"& _

"329.628|311.127|293.665|"& _

"277.183|261.626|246.942|"& _

"233.082|220.000|207.652|"& _

"195.998|184.997|174.614|"& _

"164.814|155.563|146.832|"& _

"138.591|130.813|123.471|"& _

"116.541|110.000|103.826|"& _

"97.9989|92.4986|87.3071|"& _

"82.4069|77.7817|73.4162|"& _

"69.2957|65.4064|61.7354|"& _

"58.2705|55.0000|51.9130|"& _

"48.9995|46.2493|43.6536|"& _

"41.2035|38.8909|36.7081|"& _

"34.6479|32.7032|30.8677|"& _

"29.1353|27.5000|", "|")

$Keys="A|A#|B|C|C#|D|D#|E|F|F#|G|G#"

$Keys=StringSplit($Keys,'|')

Func _exit()

Exit

EndFunc

;#include <_custom.au3>

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("PCSA Keyboard", 602+20, 207, 230, 180)

GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

$MenuItem1 = GUICtrlCreateMenu("File")

$MenuItem5 = GUICtrlCreateMenuItem("Save", $MenuItem1)

GUICtrlSetOnEvent(-1, "SavePCSA")

$MenuItem6 = GUICtrlCreateMenuItem("", $MenuItem1)

$MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem1)

GUICtrlSetOnEvent(-1, "_exit")

$MenuItemx = GUICtrlCreateMenu("Options")

;$MenuItemy = GUICtrlCreateMenuItem("Enable the number row as keys(1-0, - and +)", $MenuItemx)

;GUICtrlSetOnEvent(-1, "NumKeys")

;GUICtrlSetState($MenuItemy,$GUI_UNCHECKED)

$Label1 = GUICtrlCreateLabel("ALabel1", 2, 2, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel1Click")

$Label2 = GUICtrlCreateLabel("ALabel1", 46, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0x000000)

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel2Click")

$Label3 = GUICtrlCreateLabel("ALabel1", 90, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel3Click")

$Label4 = GUICtrlCreateLabel("ALabel1", 134, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel4Click")

$Label5 = GUICtrlCreateLabel("ALabel1", 179, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0x000000)

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel5Click")

$Label6 = GUICtrlCreateLabel("ALabel1", 223, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel6Click")

$Label7 = GUICtrlCreateLabel("ALabel1", 266, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0x000000)

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel7Click")

$Label8 = GUICtrlCreateLabel("ALabel1", 310, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel8Click")

$Label9 = GUICtrlCreateLabel("ALabel1", 354, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel9Click")

$Label10 = GUICtrlCreateLabel("ALabel1", 398, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0x000000)

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel10Click")

$Label11 = GUICtrlCreateLabel("ALabel1", 442, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel11Click")

$Label12 = GUICtrlCreateLabel("ALabel1", 485, 1, 43, 121, -1, 1)

GUICtrlSetBkColor(-1, 0x000000)

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent(-1, "ALabel12Click")

$Button1 = GUICtrlCreateButton("AButton1", 529, 0, 89, 124, 0)

GUICtrlSetOnEvent(-1, "AButton1Click")

$Button2 = GUICtrlCreateButton("Clear PCSA Layout", 529-300, 124, 100, 40)

GUICtrlSetOnEvent(-1, "ClearNotes")

$Button3 = GUICtrlCreateButton("Play Layout", 529-300, 124+40, 100, 20)

GUICtrlSetOnEvent(-1, "PlayNotes")

$Edit1 = GUICtrlCreateEdit('', 529-200, 124, 89+200, 60)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

$pressed=$WS_EX_CLIENTEDGE

$notpressed=1

$BEEPIT=0

$KEY=-11

$KEY2=0

$NumKeys=0

_ArrayReverse($KeyNotes,1,88)

_ArrayDelete($KeyNotes,89)

AButton1Click()

While 1

;Sleep(100)

sleep(300)

WEnd

Func NumKeys()

Switch $NumKeys

Case 0

$NumKeys=1

GUICtrlSetState($MenuItemy,$GUI_CHECKED)

For $i=1 To 12

HotKeySet(String($i),'ALabel'&$i&'Click')

Next

Case 1

$NumKeys=0

GUICtrlSetState($MenuItemy,$GUI_UNCHECKED)

For $i=1 To 12

HotKeySet(String($i))

Next

EndSwitch

EndFunc

Func AButton1Click()

$KEY+=12

If $KEY>88 Then $KEY=1

$lKEY=$KEY

$KEY2=0

While $lKEY>0

$lKEY-=12

$KEY2+=1

WEnd

GUICtrlSetData($Button1,'-->')

For $i=1 To 12

$keytemp=$KEY+($i-1)

If $keytemp>(UBound($KeyNotes)-1) Then

GUICtrlSetState(Eval('Label'&$i),$GUI_HIDE)

GUICtrlSetData(Eval('Label'&$i),$Keys[$i])

Else

GUICtrlSetState(Eval('Label'&$i),$GUI_SHOW)

$notetemp=$KeyNotes[$keytemp]

GUICtrlSetData(Eval('Label'&$i),$Keys[$i]&$KEY2&@CRLF&$keytemp&@CRLF&Round($notetemp,0)&"Hz")

If $notetemp<37 Then GUICtrlSetState(Eval('Label'&$i),$GUI_HIDE)

EndIf

Next

EndFunc

Func SavePCSA()

$file=FileSaveDialog("Save Data...", @ScriptDir, "PCS Audio (*.pcsa)", 2 + 16)

If $file == "" Then Return ''

$r=_PCSNotesToRaw(GUICtrlRead($Edit1))

FileOverwrite($file,$r)

EndFunc

Func PlayNotes()

$r=_PCSNotesToRaw(GUICtrlRead($Edit1))

_PCSPlayRaw($r)

EndFunc

Func ClearNotes()

GUICtrlSetData($Edit1,'')

EndFunc

Func NoteAdd($n,$t)

$d=GUICtrlRead($Edit1)

$l=StringLen($d)

If $l>0 Then $d&=','

$d&=Round($n,2)&":"&Round($t,2)

GUICtrlSetData($Edit1,$d)

EndFunc

Func ALabel1Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+0]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0 ;Or Abs(_WinAPI_GetAsyncKeyState(49))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel2Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+1]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel3Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+2]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel4Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+3]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel5Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+4]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel6Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+5]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel7Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+6]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel8Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+7]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel9Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+8]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel10Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+9]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel11Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+10]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Func ALabel12Click()

GUICtrlSetStyle(@GUI_CTRLID,-1,$pressed)

$n=$KeyNotes[$KEY+11]

$ts=TimerInit()

While Abs(_WinAPI_GetAsyncKeyState(1))>0

Beep($n,300)

WEnd

$t=TimerDiff($ts)

NoteAdd($n,$t)

GUICtrlSetStyle(@GUI_CTRLID,-1,$notpressed)

EndFunc

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0