Author Topic: School Project: Melody Maker  (Read 147 times)

Offline DivineHolinessjr

  • Newbie
  • Posts: 3
School Project: Melody Maker
« on: May 22, 2020, 01:29:58 PM »
So, I take Foundations of Programming at my highschool and the final project was to make anything you wanted as long as it did certain things. Here's the thing. Just wanted to see people's opinion on it and how to fix some things (for example, the play command makes music play three times despite being called once, and clicking on the save and load buttons seems to make the prompt show up three times as well. I assume this is because before it goes to the prompt, the if statement gets executed 3 times or something along those lines). Also looking for cool ideas because it would be nice to add more stuff to this and to give myself a reason to work on a project some more.

Code: QB64: [Select]
  1. DIM song(100, 100)
  2. DIM octave(1000)
  3. DIM notes$(12)
  4. DIM NLS(3)
  5. FOR a = 1 TO 100
  6.     FOR b = 1 TO 100
  7.         song(a, b) = 0
  8.     NEXT b
  9. FOR i = 1 TO 50
  10.     octave(i) = 2
  11. FOR i = 1 TO 3
  12.     NLS(i) = 0
  13. NLS(2) = 1
  14.  
  15. 'assigning notes
  16. notes$(1) = "C"
  17. notes$(2) = "C#"
  18. notes$(3) = "D"
  19. notes$(4) = "D#"
  20. notes$(5) = "E"
  21. notes$(6) = "F"
  22. notes$(7) = "F#"
  23. notes$(8) = "G"
  24. notes$(9) = "G#"
  25. notes$(10) = "A"
  26. notes$(11) = "A#"
  27. notes$(12) = "B"
  28. 'mouse on window
  29. _MOUSEMOVE 100, 100
  30.  
  31. 'menu
  32. menu:
  33. PRINT TAB(36); "Melody"
  34. PRINT TAB(36); "Creator"
  35. PRINT "  Editor"
  36. PRINT "  Help"
  37. PRINT "  Quit"
  38. CIRCLE (305, 120), 24, 15
  39. CIRCLE (305, 120), 23, 15
  40. LINE (328, 120)-(329, 20), 15, BF
  41. CIRCLE (400, 300), 20, 15
  42. CIRCLE (500, 275), 20, 15
  43. LINE (420, 300)-(420, 200), 15
  44. LINE (520, 275)-(520, 175), 15
  45. LINE -(420, 200), 15
  46. LINE (420, 220)-(520, 195), 15
  47. CIRCLE (100, 100), 20, 15
  48. LINE (120, 100)-(120, 25), 15
  49.         mx = _MOUSEX
  50.         my = _MOUSEY
  51.         mx = INT(mx / 8) + 1
  52.         my = INT(my / 16) + 1
  53.         IF _MOUSEBUTTON(1) AND my = 16 AND (mx >= 3 AND mx <= 8) THEN
  54.             GOTO editor
  55.         ELSEIF _MOUSEBUTTON(1) AND my = 19 AND (mx >= 3 AND mx <= 6) THEN
  56.             GOTO help
  57.         ELSEIF _MOUSEBUTTON(1) AND my = 22 AND (mx >= 3 AND mx <= 6) THEN
  58.             END
  59.         END IF
  60.     END IF
  61.  
  62. help:
  63. PRINT "Welcome to the Melody Creator! This a program where you can create melodies."
  64. PRINT "To start, click on the 'Editor' button, or click 'Quit' to exit the program."
  65. PRINT "Within the editor you can click the -'s and #'s to toggle notes on and off."
  66. PRINT "A - means a note is off, and a # means a note is on."
  67. PRINT "Down at the bottom there's a section labled 'Oct.' This stands for octave."
  68. PRINT "Click the arrows at the top and bottom to increase or decrease the octave."
  69. PRINT "Below the octave section is 's N l.'"
  70. PRINT "This stands for stacatto, normal note length, and legatto."
  71. PRINT "These buttons change the length of notes."
  72. PRINT "Finally is the play button, click this button to play the melody."
  73. PRINT "There is also the Save and Load buttons which can save, and load, melodies."
  74. PRINT "Simply give them the path towards a place to save, or load, a melody."
  75. PRINT "Back to Main Menu"
  76.         mx = _MOUSEX
  77.         my = _MOUSEY
  78.         mx = INT(mx / 8) + 1
  79.         my = INT(my / 16) + 1
  80.         IF _MOUSEBUTTON(1) AND my = 18 AND (mx >= 1 AND mx <= 18) THEN
  81.             GOTO menu
  82.         END IF
  83.     END IF
  84.  
  85. ' UI
  86. editor:
  87. PRINT "              11111111112222222222333333333344444444445"
  88. PRINT "     12345678901234567890123456789012345678901234567890"
  89. PRINT "________________________________________________________"
  90. PRINT " C | --------------------------------------------------|"
  91. PRINT " C#| --------------------------------------------------|"
  92. PRINT " D | --------------------------------------------------|"
  93. PRINT " D#| --------------------------------------------------|"
  94. PRINT " E | --------------------------------------------------|"
  95. PRINT " F | --------------------------------------------------|"
  96. PRINT " F#| --------------------------------------------------|"
  97. PRINT " G | --------------------------------------------------|"
  98. PRINT " G#| --------------------------------------------------|"
  99. PRINT " A | --------------------------------------------------|"
  100. PRINT " A#| --------------------------------------------------|"
  101. PRINT " B | --------------------------------------------------|"
  102. PRINT "_______________________________________________________|"
  103. PRINT "Oct| |"
  104. PRINT "   | 22222222222222222222222222222222222222222222222222|"
  105. PRINT "   | |"
  106. PRINT "________________________________________________________"
  107. PRINT " s N l"
  108. PRINT " Play"
  109. PRINT " Save"
  110. PRINT " Load"
  111. PRINT "Back to Main Menu"
  112. FOR i = 1 TO 50
  113.     FOR j = 1 TO 12
  114.         IF song(i, j) = 1 THEN
  115.             LOCATE j + 3, 5 + i
  116.             PRINT "#"
  117.         END IF
  118.     NEXT j
  119. FOR i = 1 TO 50
  120.     LOCATE 18, 5 + i
  121.     PRINT RIGHT$(STR$(octave(i)), 1)
  122. IF NLS(1) = 1 THEN
  123.     LOCATE 21, 2
  124.     PRINT "S n l"
  125. ELSEIF NLS(2) = 1 THEN
  126.     LOCATE 21, 2
  127.     PRINT "s N l"
  128. ELSEIF NLS(3) = 1 THEN
  129.     LOCATE 21, 2
  130.     PRINT "s n L"
  131.     'mouse tracking
  132.         mx = _MOUSEX
  133.         my = _MOUSEY
  134.         mx = INT(mx / 8) + 1
  135.         my = INT(my / 16) + 1
  136.         'LOCATE 25, 1
  137.         'PRINT mx, my
  138.         'LOCATE 26
  139.         'PRINT octave(1), octave(2), octave(3)
  140.         'PRINT octave(23), octave(24), octave(25)
  141.         'Note Chooser
  142.         IF _MOUSEBUTTON(1) AND (my > 3 AND my < 16) AND (mx > 5 AND mx < 56) THEN
  143.             IF song(mx - 5, my - 3) = 0 THEN
  144.                 LOCATE my, mx
  145.                 PRINT "#"
  146.                 song(mx - 5, my - 3) = 1
  147.             ELSEIF song(mx - 5, my - 3) = 1 THEN
  148.                 LOCATE my, mx
  149.                 PRINT "-"
  150.                 song(mx - 5, my - 3) = 0
  151.             END IF
  152.             'octave up
  153.         ELSEIF _MOUSEBUTTON(1) AND my = 17 AND (mx > 5 AND mx < 56) AND timerlast <> TIMER THEN
  154.             IF octave(mx - 5) < 6 THEN
  155.                 octave(mx - 5) = octave(mx - 5) + 1
  156.                 LOCATE 18, mx
  157.                 PRINT RIGHT$(STR$(octave(mx - 5)), 1)
  158.                 timerlast = TIMER
  159.             END IF
  160.             'octave down
  161.         ELSEIF _MOUSEBUTTON(1) AND my = 19 AND (mx > 5 AND mx < 56) AND timerlast <> TIMER THEN
  162.             IF octave(mx - 5) > 0 THEN
  163.                 octave(mx - 5) = octave(mx - 5) - 1
  164.                 LOCATE 18, mx
  165.                 PRINT RIGHT$(STR$(octave(mx - 5)), 1)
  166.                 timerlast = TIMER
  167.             END IF
  168.         ELSEIF _MOUSEBUTTON(1) AND my = 21 THEN
  169.             'Staccato
  170.             IF mx = 2 THEN
  171.                 FOR i = 1 TO 3
  172.                     NLS(i) = 0
  173.                 NEXT i
  174.                 NLS(1) = 1
  175.                 LOCATE 21, 2
  176.                 PRINT "S n l"
  177.                 'Normal
  178.             ELSEIF mx = 4 THEN
  179.                 FOR i = 1 TO 3
  180.                     NLS(i) = 0
  181.                 NEXT i
  182.                 NLS(2) = 1
  183.                 LOCATE 21, 2
  184.                 PRINT "s N l"
  185.                 'Legato
  186.             ELSEIF mx = 6 THEN
  187.                 FOR i = 1 TO 3
  188.                     NLS(i) = 0
  189.                 NEXT i
  190.                 NLS(3) = 1
  191.                 LOCATE 21, 2
  192.                 PRINT "s n L"
  193.             END IF
  194.             'play song
  195.         ELSEIF _MOUSEBUTTON(1) AND my = 22 AND (mx >= 2 AND mx <= 5) THEN
  196.             'LOCATE 30, 1
  197.             'PRINT "test"
  198.             symbols$ = stringy$ + "V25 MB "
  199.             'Note Length
  200.             IF NLS(1) = 1 THEN
  201.                 symbols$ = symbols$ + " MS"
  202.             ELSEIF NLS(2) = 1 THEN
  203.             ELSEIF NLS(3) = 1 THEN
  204.                 symbols$ = symbols$ + " ML"
  205.             END IF
  206.             total = 0
  207.             FOR i = 1 TO 50
  208.                 symbols$ = symbols$ + " O" + RIGHT$(STR$(octave(i)), 1) + " "
  209.                 'LOCATE 24, i
  210.                 ' PRINT RIGHT$(STR$(octave(i)), 1)
  211.                 FOR j = 1 TO 12
  212.                     IF song(i, j) = 1 AND thing = 1 THEN
  213.                         symbols$ = symbols$ + ", " + notes$(j)
  214.                     ELSEIF song(i, j) = 1 AND thing = 0 THEN
  215.                         symbols$ = symbols$ + " " + notes$(j)
  216.                         thing = 1
  217.                     ELSE
  218.                         total = total + 1
  219.                     END IF
  220.                 NEXT j
  221.                 IF total / 12 = 1 THEN
  222.                     symbols$ = symbols$ + " P4"
  223.                 END IF
  224.                 total = 0
  225.                 thing = 0
  226.             NEXT i
  227.             PLAY symbols$
  228.             ' LOCATE 29, 1
  229.             'PRINT symbols$
  230.             'PRINT stringy$
  231.             'PRINT octave
  232.  
  233.             'save
  234.         ELSEIF _MOUSEBUTTON(1) AND my = 23 AND (mx >= 2 AND mx <= 5) AND NOT toiming = TIMER THEN
  235.             toiming = TIMER
  236.             GOTO save
  237.             'load
  238.         ELSEIF _MOUSEBUTTON(1) AND my = 24 AND (mx >= 2 AND mx <= 5) AND NOT toiming = TIMER THEN
  239.             toiming = TIMER
  240.             GOTO load
  241.             'back to menu
  242.         ELSEIF _MOUSEBUTTON(1) AND my = 26 AND (mx >= 1 AND mx <= 18) THEN
  243.             GOTO menu
  244.         END IF
  245.     END IF
  246.  
  247. save:
  248. PRINT " ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿"
  249. PRINT " ³ Enter A Path To Save The File Or Type 'Cancel' 3x To Go Back:            ³"
  250. PRINT " ³                                                                          ³"
  251. PRINT " ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
  252. LOCATE 6, 4
  253. INPUT "", path$
  254. IF LCASE$(path$) = "cancel" THEN
  255.     GOTO editor
  256. ELSEIF NOT (RIGHT$(path$, 4) = ".txt" OR RIGHT$(path$, 4) = ".dat") THEN
  257.     CLS
  258.     PRINT "Please enter a valid path. "
  259.     PRINT "You should be pointing to a valid folder, and then end with a valid file."
  260.     PRINT "A valid file ends with .dat or .txt."
  261.     PRINT
  262.     PRINT "Press Any Key To Continue"
  263.     WHILE INKEY$ = ""
  264.     WEND
  265.     GOTO save
  266. OPEN path$ FOR OUTPUT AS #1
  267. FOR i = 1 TO 50
  268.     FOR j = 1 TO 12
  269.         PRINT #1, song(i, j);
  270.     NEXT j
  271.     PRINT #1, ,
  272. FOR i = 1 TO 50
  273.     PRINT #1, octave(i);
  274. PRINT #1, ,
  275. FOR i = 1 TO 3
  276.     PRINT #1, NLS(i);
  277. GOTO editor
  278.  
  279. load:
  280. PRINT " ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿"
  281. PRINT " ³ Enter A Path To Load The File Or Type 'Cancel' 3x To Go Back:            ³"
  282. PRINT " ³                                                                          ³"
  283. PRINT " ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
  284. LOCATE 6, 4
  285. INPUT "", path$
  286. IF LCASE$(path$) = "cancel" THEN
  287.     GOTO editor
  288. ELSEIF NOT (RIGHT$(path$, 4) = ".txt" OR RIGHT$(path$, 4) = ".dat") THEN
  289.     CLS
  290.     PRINT "Please enter a valid path. "
  291.     PRINT "You should be pointing to a valid folder, and then end with a valid file."
  292.     PRINT "A valid file ends with .dat or .txt."
  293.     PRINT
  294.     PRINT "Press Any Key To Continue"
  295.     WHILE INKEY$ = ""
  296.     WEND
  297.     GOTO save
  298. OPEN path$ FOR INPUT AS #1
  299. FOR i = 1 TO 50
  300.     FOR j = 1 TO 12
  301.         INPUT #1, song(i, j)
  302.     NEXT j
  303. FOR i = 1 TO 50
  304.     INPUT #1, octave(i)
  305. FOR i = 1 TO 3
  306.     INPUT #1, NLS(i)
  307. GOTO editor
  308.  

Also feel free to rate my mediocre documentation.

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2025
  • LET IT = BE
    • QB64.org
Re: School Project: Melody Maker
« Reply #1 on: May 22, 2020, 01:38:36 PM »
Awesome forum debut, welcome DivineHolinessjr!

Offline DivineHolinessjr

  • Newbie
  • Posts: 3
Re: School Project: Melody Maker
« Reply #2 on: May 22, 2020, 01:40:46 PM »
Thanks! Surprised to already have gotten a reply, and from a member of the team themselves. Been lurking here for a few days and only just thought to upload the project once I finished it.

Offline Petr

  • Forum Resident
  • Posts: 1254
  • The best code is the DNA of the hops.
Re: School Project: Melody Maker
« Reply #3 on: May 22, 2020, 03:25:17 PM »
Welcome to the forum DivineHolinessjr,

Small upgrade for mouse calling can repairing your 3x reactions:

Code: QB64: [Select]
  1. DIM song(100, 100)
  2. DIM octave(1000)
  3. DIM notes$(12)
  4. DIM NLS(3)
  5. FOR a = 1 TO 100
  6.     FOR b = 1 TO 100
  7.         song(a, b) = 0
  8.     NEXT b
  9. FOR i = 1 TO 50
  10.     octave(i) = 2
  11. FOR i = 1 TO 3
  12.     NLS(i) = 0
  13. NLS(2) = 1
  14.  
  15. 'assigning notes
  16. notes$(1) = "C"
  17. notes$(2) = "C#"
  18. notes$(3) = "D"
  19. notes$(4) = "D#"
  20. notes$(5) = "E"
  21. notes$(6) = "F"
  22. notes$(7) = "F#"
  23. notes$(8) = "G"
  24. notes$(9) = "G#"
  25. notes$(10) = "A"
  26. notes$(11) = "A#"
  27. notes$(12) = "B"
  28. 'mouse on window
  29. _MOUSEMOVE 100, 100
  30.  
  31. 'menu
  32. menu:
  33. PRINT TAB(36); "Melody"
  34. PRINT TAB(36); "Creator"
  35. PRINT "  Editor"
  36. PRINT "  Help"
  37. PRINT "  Quit"
  38. CIRCLE (305, 120), 24, 15
  39. CIRCLE (305, 120), 23, 15
  40. LINE (328, 120)-(329, 20), 15, BF
  41. CIRCLE (400, 300), 20, 15
  42. CIRCLE (500, 275), 20, 15
  43. LINE (420, 300)-(420, 200), 15
  44. LINE (520, 275)-(520, 175), 15
  45. LINE -(420, 200), 15
  46. LINE (420, 220)-(520, 195), 15
  47. CIRCLE (100, 100), 20, 15
  48. LINE (120, 100)-(120, 25), 15
  49.         mx = _MOUSEX
  50.         my = _MOUSEY
  51.         mx = INT(mx / 8) + 1
  52.         my = INT(my / 16) + 1
  53.         IF _MOUSEBUTTON(1) AND my = 16 AND (mx >= 3 AND mx <= 8) THEN
  54.             GOTO editor
  55.         ELSEIF _MOUSEBUTTON(1) AND my = 19 AND (mx >= 3 AND mx <= 6) THEN
  56.             GOTO help
  57.         ELSEIF _MOUSEBUTTON(1) AND my = 22 AND (mx >= 3 AND mx <= 6) THEN
  58.             END
  59.         END IF
  60.     END IF
  61.  
  62. help:
  63. PRINT "Welcome to the Melody Creator! This a program where you can create melodies."
  64. PRINT "To start, click on the 'Editor' button, or click 'Quit' to exit the program."
  65. PRINT "Within the editor you can click the -'s and #'s to toggle notes on and off."
  66. PRINT "A - means a note is off, and a # means a note is on."
  67. PRINT "Down at the bottom there's a section labled 'Oct.' This stands for octave."
  68. PRINT "Click the arrows at the top and bottom to increase or decrease the octave."
  69. PRINT "Below the octave section is 's N l.'"
  70. PRINT "This stands for stacatto, normal note length, and legatto."
  71. PRINT "These buttons change the length of notes."
  72. PRINT "Finally is the play button, click this button to play the melody."
  73. PRINT "There is also the Save and Load buttons which can save, and load, melodies."
  74. PRINT "Simply give them the path towards a place to save, or load, a melody."
  75. PRINT "Back to Main Menu"
  76.         mx = _MOUSEX
  77.         my = _MOUSEY
  78.         mx = INT(mx / 8) + 1
  79.         my = INT(my / 16) + 1
  80.         IF _MOUSEBUTTON(1) AND my = 18 AND (mx >= 1 AND mx <= 18) THEN
  81.             GOTO menu
  82.         END IF
  83.     END IF
  84.  
  85. ' UI
  86. editor:
  87. PRINT "              11111111112222222222333333333344444444445"
  88. PRINT "     12345678901234567890123456789012345678901234567890"
  89. PRINT "________________________________________________________"
  90. PRINT " C | --------------------------------------------------|"
  91. PRINT " C#| --------------------------------------------------|"
  92. PRINT " D | --------------------------------------------------|"
  93. PRINT " D#| --------------------------------------------------|"
  94. PRINT " E | --------------------------------------------------|"
  95. PRINT " F | --------------------------------------------------|"
  96. PRINT " F#| --------------------------------------------------|"
  97. PRINT " G | --------------------------------------------------|"
  98. PRINT " G#| --------------------------------------------------|"
  99. PRINT " A | --------------------------------------------------|"
  100. PRINT " A#| --------------------------------------------------|"
  101. PRINT " B | --------------------------------------------------|"
  102. PRINT "_______________________________________________________|"
  103. PRINT "Oct| |"
  104. PRINT "   | 22222222222222222222222222222222222222222222222222|"
  105. PRINT "   | |"
  106. PRINT "________________________________________________________"
  107. PRINT " s N l"
  108. PRINT " Play"
  109. PRINT " Save"
  110. PRINT " Load"
  111. PRINT "Back to Main Menu"
  112. FOR i = 1 TO 50
  113.     FOR j = 1 TO 12
  114.         IF song(i, j) = 1 THEN
  115.             LOCATE j + 3, 5 + i
  116.             PRINT "#"
  117.         END IF
  118.     NEXT j
  119. FOR i = 1 TO 50
  120.     LOCATE 18, 5 + i
  121.     PRINT RIGHT$(STR$(octave(i)), 1)
  122. IF NLS(1) = 1 THEN
  123.     LOCATE 21, 2
  124.     PRINT "S n l"
  125. ELSEIF NLS(2) = 1 THEN
  126.     LOCATE 21, 2
  127.     PRINT "s N l"
  128. ELSEIF NLS(3) = 1 THEN
  129.     LOCATE 21, 2
  130.     PRINT "s n L"
  131.     'mouse tracking
  132.     mx = _MOUSEX
  133.     my = _MOUSEY
  134.     MB1 = _MOUSEBUTTON(1)
  135.     mx = INT(mx / 8) + 1
  136.     my = INT(my / 16) + 1
  137.     'LOCATE 25, 1
  138.     'PRINT mx, my
  139.     'LOCATE 26
  140.     'PRINT octave(1), octave(2), octave(3)
  141.     'PRINT octave(23), octave(24), octave(25)
  142.     'Note Chooser
  143.     IF _MOUSEBUTTON(1) AND (my > 3 AND my < 16) AND (mx > 5 AND mx < 56) THEN
  144.         IF song(mx - 5, my - 3) = 0 THEN
  145.             LOCATE my, mx
  146.             PRINT "#"
  147.             song(mx - 5, my - 3) = 1
  148.         ELSEIF song(mx - 5, my - 3) = 1 THEN
  149.             LOCATE my, mx
  150.             PRINT "-"
  151.             song(mx - 5, my - 3) = 0
  152.         END IF
  153.         'octave up
  154.     ELSEIF MB1 AND my = 17 AND (mx > 5 AND mx < 56) AND timerlast <> TIMER THEN
  155.         IF octave(mx - 5) < 6 THEN
  156.             octave(mx - 5) = octave(mx - 5) + 1
  157.             LOCATE 18, mx
  158.             PRINT RIGHT$(STR$(octave(mx - 5)), 1)
  159.             timerlast = TIMER
  160.         END IF
  161.         'octave down
  162.     ELSEIF MB1 AND my = 19 AND (mx > 5 AND mx < 56) AND timerlast <> TIMER THEN
  163.         IF octave(mx - 5) > 0 THEN
  164.             octave(mx - 5) = octave(mx - 5) - 1
  165.             LOCATE 18, mx
  166.             PRINT RIGHT$(STR$(octave(mx - 5)), 1)
  167.             timerlast = TIMER
  168.         END IF
  169.     ELSEIF MB1 AND my = 21 THEN
  170.         'Staccato
  171.         IF mx = 2 THEN
  172.             FOR i = 1 TO 3
  173.                 NLS(i) = 0
  174.             NEXT i
  175.             NLS(1) = 1
  176.             LOCATE 21, 2
  177.             PRINT "S n l"
  178.             'Normal
  179.         ELSEIF mx = 4 THEN
  180.             FOR i = 1 TO 3
  181.                 NLS(i) = 0
  182.             NEXT i
  183.             NLS(2) = 1
  184.             LOCATE 21, 2
  185.             PRINT "s N l"
  186.             'Legato
  187.         ELSEIF mx = 6 THEN
  188.             FOR i = 1 TO 3
  189.                 NLS(i) = 0
  190.             NEXT i
  191.             NLS(3) = 1
  192.             LOCATE 21, 2
  193.             PRINT "s n L"
  194.         END IF
  195.         'play song
  196.     ELSEIF MB1 AND my = 22 AND (mx >= 2 AND mx <= 5) THEN
  197.         'LOCATE 30, 1
  198.         'PRINT "test"
  199.         symbol$ = ""
  200.         symbols$ = stringy$ + "V25 MB "
  201.         'Note Length
  202.         IF NLS(1) = 1 THEN
  203.             symbols$ = symbols$ + " MS"
  204.         ELSEIF NLS(2) = 1 THEN
  205.         ELSEIF NLS(3) = 1 THEN
  206.             symbols$ = symbols$ + " ML"
  207.         END IF
  208.         total = 0
  209.         FOR i = 1 TO 50
  210.             symbols$ = symbols$ + " O" + RIGHT$(STR$(octave(i)), 1) + " "
  211.             'LOCATE 24, i
  212.             ' PRINT RIGHT$(STR$(octave(i)), 1)
  213.             FOR j = 1 TO 12
  214.                 IF song(i, j) = 1 AND thing = 1 THEN
  215.                     symbols$ = symbols$ + ", " + notes$(j)
  216.                 ELSEIF song(i, j) = 1 AND thing = 0 THEN
  217.                     symbols$ = symbols$ + " " + notes$(j)
  218.                     thing = 1
  219.                 ELSE
  220.                     total = total + 1
  221.                 END IF
  222.             NEXT j
  223.             IF total / 12 = 1 THEN
  224.                 symbols$ = symbols$ + " P4"
  225.             END IF
  226.             total = 0
  227.             thing = 0
  228.         NEXT i
  229.         '    CLS
  230.         '    R = R + 1 'number of runnings
  231.         '    PRINT R
  232.  
  233.  
  234.         PLAY symbols$
  235.         ' LOCATE 29, 1
  236.         'PRINT symbols$
  237.         'PRINT stringy$
  238.         'PRINT octave
  239.  
  240.         'save
  241.     ELSEIF MB1 AND my = 23 AND (mx >= 2 AND mx <= 5) AND NOT toiming = TIMER THEN
  242.         toiming = TIMER
  243.         GOTO save
  244.         'load
  245.     ELSEIF MB1 AND my = 24 AND (mx >= 2 AND mx <= 5) AND NOT toiming = TIMER THEN
  246.         toiming = TIMER
  247.         GOTO load
  248.         'back to menu
  249.     ELSEIF MB1 AND my = 26 AND (mx >= 1 AND mx <= 18) THEN
  250.         GOTO menu
  251.     END IF
  252.     _LIMIT 15
  253.  
  254. save:
  255. PRINT " ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ?"
  256. PRINT " 3 Enter A Path To Save The File Or Type 'Cancel' 3x To Go Back:            3"
  257. PRINT " 3                                                                          3"
  258. PRINT " AÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄU"
  259. LOCATE 6, 4
  260. INPUT "", path$
  261. IF LCASE$(path$) = "cancel" THEN
  262.     GOTO editor
  263. ELSEIF NOT (RIGHT$(path$, 4) = ".txt" OR RIGHT$(path$, 4) = ".dat") THEN
  264.     CLS
  265.     PRINT "Please enter a valid path. "
  266.     PRINT "You should be pointing to a valid folder, and then end with a valid file."
  267.     PRINT "A valid file ends with .dat or .txt."
  268.     PRINT
  269.     PRINT "Press Any Key To Continue"
  270.     WHILE INKEY$ = ""
  271.     WEND
  272.     GOTO save
  273. OPEN path$ FOR OUTPUT AS #1
  274. FOR i = 1 TO 50
  275.     FOR j = 1 TO 12
  276.         PRINT #1, song(i, j);
  277.     NEXT j
  278.     PRINT #1, ,
  279. FOR i = 1 TO 50
  280.     PRINT #1, octave(i);
  281. PRINT #1, ,
  282. FOR i = 1 TO 3
  283.     PRINT #1, NLS(i);
  284. GOTO editor
  285.  
  286. load:
  287. PRINT " ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ?"
  288. PRINT " 3 Enter A Path To Load The File Or Type 'Cancel' 3x To Go Back:            3"
  289. PRINT " 3                                                                          3"
  290. PRINT " AÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄU"
  291. LOCATE 6, 4
  292. INPUT "", path$
  293. IF LCASE$(path$) = "cancel" THEN
  294.     GOTO editor
  295. ELSEIF NOT (RIGHT$(path$, 4) = ".txt" OR RIGHT$(path$, 4) = ".dat") THEN
  296.     CLS
  297.     PRINT "Please enter a valid path. "
  298.     PRINT "You should be pointing to a valid folder, and then end with a valid file."
  299.     PRINT "A valid file ends with .dat or .txt."
  300.     PRINT
  301.     PRINT "Press Any Key To Continue"
  302.     WHILE INKEY$ = ""
  303.     WEND
  304.     GOTO save
  305. OPEN path$ FOR INPUT AS #1
  306. FOR i = 1 TO 50
  307.     FOR j = 1 TO 12
  308.         INPUT #1, song(i, j)
  309.     NEXT j
  310. FOR i = 1 TO 50
  311.     INPUT #1, octave(i)
  312. FOR i = 1 TO 3
  313.     INPUT #1, NLS(i)
  314. GOTO editor
  315.  

And here is small example, how program can repairing bad filename on input:

Code: QB64: [Select]
  1. FOR test = 1 TO 3
  2.     givemename:
  3.     INPUT "Input filename for save:"; savename$
  4.     IF LEN(savename$) = 0 THEN GOTO givemename
  5.     IF INSTR(1, savename$, ".txt") THEN
  6.         PRINT "Extension supported, saved as "; savename$
  7.     ELSEIF INSTR(1, savename$, ".") THEN
  8.         newname$ = MID$(savename$, 1, INSTR(1, savename$, ".")) + "txt"
  9.         PRINT "Renamed as: "; newname$
  10.     ELSE newname$ = savename$ + ".txt"
  11.         PRINT "added extension as: "; newname$
  12.     END IF
  13.  
  14.  

 
« Last Edit: May 22, 2020, 03:44:30 PM by Petr »

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2025
  • LET IT = BE
    • QB64.org
Re: School Project: Melody Maker
« Reply #4 on: May 22, 2020, 03:26:59 PM »
I wish I could recover my program that drew the note events from a PLAY string onto a "piano roll" of sorts, but I couldn't find it anywhere. It'd be an interesting merger with this program.

It may have been lost forever in the corrupted realms of qb64.net...

Offline SpriggsySpriggs

  • Newbie
  • Posts: 48
    • My Github
Re: School Project: Melody Maker
« Reply #5 on: May 22, 2020, 03:49:35 PM »
That is impressive! I wasn't making programs like this in high school! I was just doing stuff to help me with my math homework haha. Of course, I'm pretty sure I was using the old SDL version anyways and wasn't really trying to make anything super complex. It wasn't until I saw Fellippe's library, InForm, that I really got back into QB64. Now I spend most of my free time doing it. Looking forward to seeing more from you! You could maybe even convert your program to using InForm by making custom piano-key shaped buttons!

Offline DivineHolinessjr

  • Newbie
  • Posts: 3
Re: School Project: Melody Maker
« Reply #6 on: May 22, 2020, 04:28:46 PM »
That is impressive! I wasn't making programs like this in high school! I was just doing stuff to help me with my math homework haha. Of course, I'm pretty sure I was using the old SDL version anyways and wasn't really trying to make anything super complex. It wasn't until I saw Fellippe's library, InForm, that I really got back into QB64. Now I spend most of my free time doing it. Looking forward to seeing more from you! You could maybe even convert your program to using InForm by making custom piano-key shaped buttons!

Sounds like a good idea. I've had InForm on my computer for a while but couldn't really figure out how to use it with code. I'll probably start playing with it and looking stuff up now and try to convert it into an InForm interface now though.

Welcome to the forum DivineHolinessjr,

Small upgrade for mouse calling can repairing your 3x reactions:

 


I'll go ahead and take use of that, would've never thought of that fix personally. I'll try and keep that in mind for any future programs I decide to make.

Edit: Right after I posted I noticed that instead of future I put feature. How do I keep replacing words while typing.
« Last Edit: May 22, 2020, 04:29:48 PM by DivineHolinessjr »

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2025
  • LET IT = BE
    • QB64.org
Re: School Project: Melody Maker
« Reply #7 on: May 23, 2020, 01:02:05 AM »
I found my old PLAY string parser/visualizer. If it's any useful to you, feel free to use it (or parts of it): https://www.qb64.org/forum/index.php?topic=2625.msg118429#msg118429