Author Topic: Piano  (Read 3884 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Piano
« on: April 30, 2020, 06:37:32 pm »
Today I was checking out my programs and found an old QBasic one from the 1990's of a piano I made that still used line numbers lol. QBasic used the old internal beep speaker so this didn't last too long. Later an old friend showed me how to use the Sound Blaster sound card with QBasic but that was tons of code way beyond me. So I am really happy that QB64 automatically uses the sound card for any sounds. So today I converted that old piano program into a QB64 and added more notes and the ability to change the note length using your up and down arrow keys. Everything is self-explanatory. I remember awhile back B+ said he didn't know about the PLAY command, so here it is B+, turned into a piano. There's no graphics on this program, you just press keyboard keys and it plays. Of course there's a limit on how fast the computer transmits to the sound card, so if you play kinda fast and stop, it will keep playing until all of your keys you typed are played out. Try going down to Note Length 2 and typing pretty fast, it's pretty cool! You might notice that instead of using the a,b,c,d,e,f note code, I am using the n21,n22,n23.... I did that to make it easier to expand past just the usual 7 notes.

Code: QB64: [Select]
  1. _TITLE "My Piano      by SierraKen"
  2. PRINT "To play press letters: q, w, e, r, t, y, u, i, o, p, [, ], \"
  3. PRINT "Press up and down arrow keys for higher or lower note length."
  4. PRINT "Press <Esc> to quit."
  5. l = 12
  6. ll = 12
  7. LOCATE 6, 1: PRINT "Note Length:"; ll
  8.     a$ = INKEY$
  9.  
  10.     IF a$ = "q" OR a$ = "Q" THEN n$ = "n21"
  11.     IF a$ = "w" OR a$ = "W" THEN n$ = "n22"
  12.     IF a$ = "e" OR a$ = "E" THEN n$ = "n23"
  13.     IF a$ = "r" OR a$ = "R" THEN n$ = "n24"
  14.     IF a$ = "t" OR a$ = "T" THEN n$ = "n25"
  15.     IF a$ = "y" OR a$ = "Y" THEN n$ = "n26"
  16.     IF a$ = "u" OR a$ = "U" THEN n$ = "n27"
  17.     IF a$ = "i" OR a$ = "I" THEN n$ = "n28"
  18.     IF a$ = "o" OR a$ = "O" THEN n$ = "n29"
  19.     IF a$ = "p" OR a$ = "P" THEN n$ = "n30"
  20.     IF a$ = "[" OR a$ = "{" THEN n$ = "n31"
  21.     IF a$ = "]" OR a$ = "}" THEN n$ = "n32"
  22.     IF a$ = "\" OR a$ = "|" THEN n$ = "n33"
  23.     IF a$ = CHR$(27) THEN END
  24.     IF a$ = CHR$(0) + CHR$(80) THEN
  25.         l = l + 1
  26.         ll = ll - 1
  27.         IF l > 18 THEN l = 18
  28.         IF ll < 2 THEN ll = 2
  29.         LOCATE 6, 1: PRINT "Note Length:"; ll
  30.     END IF
  31.     IF a$ = CHR$(0) + CHR$(72) THEN
  32.         l = l - 1
  33.         ll = ll + 1
  34.         IF l < 2 THEN l = 2
  35.         IF ll > 18 THEN ll = 18
  36.         LOCATE 6, 1: PRINT "Note Length:"; ll
  37.     END IF
  38.     IF n$ <> "" THEN
  39.         l$ = STR$(l)
  40.         PLAY "L" + l$ + n$
  41.         n$ = ""
  42.     END IF
  43.  
« Last Edit: April 30, 2020, 06:39:36 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Piano
« Reply #1 on: April 30, 2020, 08:30:48 pm »
Hey ken, you are on Terry's wave-link too!
https://www.qb64.org/forum/index.php?topic=2400.0