' ' KEYBOARD.BAS 2.01 ' ' Made by Olle Bergkvist, 2006 ' Feedback: olle dot bergkvist at yahoo dot se ' Website: www.olle.tk **or** web.telia.com/~u89107348 ' Programmers Heaven: casio-games.tk ' ' Version 2.01 ' Fixed so buffer is not being filled in the sub Open and so that sub checks the keyboard properly ' ' Version 2.00.00 ' New keyboard routine - it responds much faster when recording, ' and you dont need to set the speed ' ' Version 1.04.00 ' Structured programming :-D ' ' Version 1.03.00 ' Fixed Append function ' You can set the sound length when recording to match your computer! ' Fixed error message when recording special characters like †, „ or ”. ' ' Version 1.02.00 ' Fixed "Out of data" error when recording multiple times. ' Fixed "Illegal function call" when pressing i.e. Ctrl in Record. ' Fixed the wrong frequency - it didn't match piano. ' ' This program is used to record, modify and play melodies. ' It uses the internal speaker, so it works on all computers ' (except mobile phones :-D). To be able to double-click a file to play it, ' you have to compile this program. ' Or use that advanced QBasic function called /CMD to play a file in QBasic. ' (In special for you who use QBasic 1.1.) ' ' There is no warranty and I am not responsible for data loss. ' Dont use this program to record to important files which already exists. ' You will get a message, but the program has already written some data ' to the end of the file. ' So WATCH OUT when recording to config.sys or something! ' ' 'Module level code starts here DECLARE SUB RecordCheck () DECLARE SUB Record () DECLARE SUB OpenFile () DECLARE SUB OpenAdvanced () '--------Global variables COMMON SHARED tempo COMMON SHARED save COMMON SHARED OpenName$ COMMON SHARED SaveName$ LET tempo = 1 LET save = 1 LET OpenName$ = "" LET SaveName$ = "" DATA 86,30,44,31,45,46,33,47,34,48,35,49,50 DATA 16,3,17,4,18,19,6,20,7,21,8,22,23 ' This receives the command line used to open the compiled program. ' Thanks to Anthrax11 for remembering this command! ' (And getting me started with programming :-D) ' OpenName$ = COMMAND$ IF OpenName$ <> "" THEN OpenFile ' ' Main menu ' start: CLS PRINT "Welcome to my keyboard! Version 2.00.00" PRINT PRINT "What do you want to do?" PRINT PRINT "1 Record a new song" PRINT "2 Play a song from a file path" PRINT "3 Play a song with tempo setting" PRINT "F4 Exit" PRINT PRINT "Made by Olle Bergkvist 2006" PRINT DO SLEEP key$ = INKEY$ SELECT CASE key$ CASE "1" RecordCheck IF save = 3 THEN GOTO start: Record GOTO start CASE "2" OpenFile GOTO start CASE "3" OpenAdvanced OpenFile GOTO start CASE CHR$(0) + ">" END END SELECT LOOP SUB OpenAdvanced PRINT "These settings remains until you shut down this program." PRINT "Which tempo do you want? Current tempo is"; tempo INPUT "1 is the default.", tempo END SUB SUB OpenFile ' ' ' This part of the program plays a file. ' IF OpenName$ = "" THEN INPUT "Enter the path to the file to play.", OpenName$ PRINT "Press Esc to quit." PRINT "Press Spacebar to enable or disable Sustain pedal." OPEN OpenName$ FOR INPUT AS 1 lastfreq = 0 sustain = -1 ' ------------------ Main loop starts here DO INPUT #1, tone INPUT #1, length freq = 246.9417 * 2 ^ (tone / 12) time = TIMER IF tone > 0 OR (sustain = 1 AND lastfreq > 0) THEN SOUND freq, length * 18.2 / tempo lastfreq = freq DO dum$ = INKEY$ LOOP WHILE time + length / tempo > TIMER keyn = INP(96) IF keyn = 57 THEN sustain = -sustain PRINT "Sustain pedal status:"; (sustain + 1) / 2 END IF LOOP UNTIL keyn = 1 OR EOF(1) EndOfPlay: CLOSE END SUB SUB Record ' This part opens the file and records to it. It uses INP(96) for the ' keyboard input. That makes the prgram respond much faster. Thanks to IDK! SELECT CASE save CASE 1 OPEN SaveName$ FOR OUTPUT AS 1 CASE 2 OPEN SaveName$ FOR APPEND AS 1 END SELECT PRINT PRINT "Press Esc to save and exit." DIM keys(0 TO 255) RESTORE FOR temptone = 1 TO 13 READ tempkeynum keys(tempkeynum) = temptone NEXT FOR temptone = 13 TO 25 READ tempkeynum keys(tempkeynum) = temptone NEXT sleepat = TIMER ' -------------- Main loop starts here DO SLEEP playat = TIMER PRINT #1, 0 PRINT #1, playat - sleepat keynum = INP(96) IF keynum = 1 THEN GOTO EndOfRec tone = keys(keynum) freq = 246.9417 * 2 ^ (tone / 12) DO IF tone > 0 THEN SOUND freq, .1 END IF key$ = INKEY$ ' to avoid filled buffer LOOP WHILE INP(96) = keynum SOUND 37, 0 ' to make the speaker shut down sleepat = TIMER PRINT #1, tone PRINT #1, sleepat - playat LOOP EndOfRec: CLOSE PRINT "Saved as "; SaveName$; " Press any key to return to main menu." DO LOOP WHILE INKEY$ = CHR$(27) SLEEP END SUB SUB RecordCheck ' ' ' This part checks if a file exists before recording to it. ' PRINT INPUT "Create file name"; SaveName$ SaveName$ = SaveName$ + ".ton" randomvar = RND / 100 OPEN SaveName$ FOR APPEND AS 1 PRINT #1, 0 PRINT #1, randomvar CLOSE OPEN SaveName$ FOR INPUT AS 1 INPUT #1, line1 INPUT #1, check CLOSE save = 1 IF randomvar <> check THEN PRINT PRINT "The file already exists!" PRINT "Press 1 to overwrite, 2 to add on the end" PRINT "or Esc to exit." PRINT DO SLEEP key$ = INKEY$ SELECT CASE key$ CASE "1" EXIT SUB CASE "2" save = 2 EXIT SUB CASE CHR$(27) save = 3 EXIT SUB END SELECT LOOP END IF END SUB