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

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

Also feel free to rate my mediocre documentation.

#### FellippeHeitor

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

#### 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.

#### 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,

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

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.
13.

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

#### FellippeHeitor

• QB64 Developer
• Forum Resident
• Posts: 2025
• LET IT = BE
##### 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...

#### SpriggsySpriggs

• Newbie
• Posts: 48
##### 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!

#### 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,

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 »

#### FellippeHeitor

• QB64 Developer
• Forum Resident
• Posts: 2025
• LET IT = BE
##### 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