Well here it is, musak! But this is just one example. If allowed it plays five songs at a time, each song is about a minute long. Press [ESC] key to leave.
One fault with this program is that it doesn't play phrases (or "hooks", don't know how to say it out of the popular music industry) so one could recognize which song it is LOL. This program creates music which is too random. I programmed the "phrases" thing half-successfully with my Lua script for "1bitr". With "phrases" this program could make a good companion to bplus' program indicated in this thread:
https://staging.qb64phoenix.com/showthread.php?tid=1668
Purposely I set the songs playing fairly fast, ie. using "L32" instead of "L16" that I preferred, however PLAY statement doesn't allow tempos higher than 255. The logic of this program isn't very good for computing music with lengths and amplitude, which could be improved.
Code: (Select All)
'by mnrvovrfc 18-June-2023
'requires QB64 Phoenix Edition v3.8 or later
OPTION _EXPLICIT
REDIM scales(1 TO 1) AS STRING
DIM sequ(1 TO 2, 1 TO 20) AS INTEGER
DIM SHARED thiscale(1 TO 5) AS INTEGER, altscale(1 TO 5) AS INTEGER
DIM AS INTEGER i, lscales, song, si, so, u, basenote, numnote, athird
DIM AS INTEGER down
DIM e$
RANDOMIZE TIMER
RESTORE scaleslist
READ e$
DO UNTIL e$ = "END"
lscales = lscales + 1
IF lscales > 1 THEN
REDIM _PRESERVE scales(1 TO lscales) AS STRING
END IF
scales(lscales) = e$
READ e$
LOOP
PRINT "Now if only we have some animation!"
_TITLE "Press [ESC] to quit, [SPACE] for next song."
FOR song = 1 TO 5
PRINT: PRINT "Song"; song
u = Rand(18, 24) * 2
basenote = u
down = 0
si = Random1(lscales)
DO
so = Random1(lscales)
LOOP WHILE si = so
thiscale(1) = basenote
FOR i = 1 TO 4
basenote = basenote + VAL(MID$(scales(si), i, 1))
if basenote > 84 then down = 12
thiscale(i + 1) = basenote
NEXT
for i = 1 to 5
thiscale(i) = thiscale(i) - down
next
basenote = u
down = 0
altscale(1) = basenote
FOR i = 1 TO 4
basenote = basenote + VAL(MID$(scales(so), i, 1))
if basenote > 84 then down = 12
altscale(i + 1) = basenote
NEXT
for i = 1 to 5
altscale(i) = altscale(i) - down
next
e$ = "MB"
IF Random1(3) = 1 THEN e$ = e$ + "MS" ELSE e$ = e$ + "MN"
e$ = e$ + "T" + _TRIM$(STR$(Rand(9, 16) * 10))
e$ = e$ + "@" + _TRIM$(STR$(Random1(3)))
e$ = e$ + "Q10V50"
numnote = Rand(50, 150) * 4
athird = numnote \ 3
DO
e$ = e$ + "V50"
u = Random1(20)
SELECT CASE u
CASE 1
e$ = e$ + "L32" + en$(2) + en$(5) + en$(2) + en$(5)
numnote = numnote - 4
CASE 2
e$ = e$ + "L32" + en$(1) + en$(5) + en$(2) + en$(5)
numnote = numnote - 4
CASE 3
e$ = e$ + "L32" + en$(5) + en$(5) + "L16" + en$(5)
numnote = numnote - 3
CASE 4
e$ = e$ + "L16" + en$(5) + "L32" + en$(5) + en$(5)
numnote = numnote - 3
CASE 5
e$ = e$ + "L16" + en$(5) + en$(5)
numnote = numnote - 2
CASE 6
e$ = e$ + "L16" + en$(5) + en$(5)
numnote = numnote - 2
CASE 7
e$ = e$ + "L16" + en$(5) + en$(5) + "L8" + en$(5)
numnote = numnote - 3
CASE 8
e$ = e$ + "L8" + en$(5) + "L16" + en$(5) + en$(5)
numnote = numnote - 3
CASE 9
e$ = e$ + "L8" + en$(5) + en$(5)
numnote = numnote - 2
CASE 10
e$ = e$ + "L8" + enft$(1, 2) + en$(5)
numnote = numnote - 2
CASE 11
e$ = e$ + "L32" + en$(2) + "V25" + en$(5) + en$(2) + "V50" + en$(5)
numnote = numnote - 4
CASE 12
e$ = e$ + "L32" + en$(1) + "V25" + en$(5) + "V50" + en$(2) + en$(5)
numnote = numnote - 4
CASE 13
e$ = e$ + "L32" + en$(5) + "V25" + en$(5) + "V50L16" + en$(5)
numnote = numnote - 3
CASE 14
e$ = e$ + "L16" + en$(5) + "L32" + en$(5) + "V25" + en$(5)
numnote = numnote - 3
CASE 15
e$ = e$ + "L16" + en$(5) + "V25" + en$(5)
numnote = numnote - 2
CASE 16
e$ = e$ + "L16" + en$(5) + "V25" + en$(5)
numnote = numnote - 2
CASE 17
e$ = e$ + "L16" + en$(5) + "V25" + en$(5) + "V50L8" + en$(5)
numnote = numnote - 3
CASE 18
e$ = e$ + "L8" + en$(5) + "L16" + en$(5) + "V25" + en$(5)
numnote = numnote - 3
CASE 19
e$ = e$ + "L8" + en$(5) + "V25" + en$(5)
numnote = numnote - 2
CASE 20
e$ = e$ + "L8" + en$(5) + "V25" + en$(5)
numnote = numnote - 2
END SELECT
LOOP WHILE numnote > athird * 2
DO
e$ = e$ + "V50"
u = Random1(20)
SELECT CASE u
CASE 1
e$ = e$ + "L32" + anft$(1, 2) + anft$(1, 5) + anft$(1, 2) + anft$(1, 5)
numnote = numnote - 4
CASE 2
e$ = e$ + "L32" + anft$(1, 2) + anft$(1, 5) + anft$(1, 2) + anft$(3, 5)
numnote = numnote - 4
CASE 3
e$ = e$ + "L32" + anft$(1, 2) + anft$(3, 5) + "L16" + anft$(1, 2)
numnote = numnote - 3
CASE 4
e$ = e$ + "L16" + anft$(1, 2) + "L32" + anft$(1, 2) + anft$(3, 5)
numnote = numnote - 3
CASE 5
e$ = e$ + "L16" + anft$(1, 2) + anft$(3, 5)
numnote = numnote - 2
CASE 6
e$ = e$ + "L16" + anft$(1, 5) + anft$(1, 5)
numnote = numnote - 2
CASE 7
e$ = e$ + "L16" + anft$(1, 2) + anft$(3, 5) + "L8" + anft$(1, 2)
numnote = numnote - 3
CASE 8
e$ = e$ + "L8" + anft$(1, 2) + "L16" + anft$(1, 2) + anft$(3, 5)
numnote = numnote - 3
CASE 9
e$ = e$ + "L8" + anft$(1, 2) + anft$(3, 5)
numnote = numnote - 2
CASE 10
e$ = e$ + "L8" + anft$(1, 5) + anft$(1, 5)
numnote = numnote - 2
CASE 11
e$ = e$ + "L32" + anft$(1, 2) + "V25" + anft$(1, 5) + "V50" + anft$(1, 2) + "V25" + anft$(1, 5)
numnote = numnote - 4
CASE 12
e$ = e$ + "L32" + anft$(1, 2) + "V25" + anft$(1, 5) + "V50" + anft$(1, 2) + "V25" + anft$(3, 5)
numnote = numnote - 4
CASE 13
e$ = e$ + "L32" + anft$(1, 2) + "V25" + anft$(3, 5) + "V50L16" + anft$(1, 2)
numnote = numnote - 3
CASE 14
e$ = e$ + "L16" + anft$(1, 2) + "V25L32" + anft$(1, 2) + "V50" + anft$(3, 5)
numnote = numnote - 3
CASE 15
e$ = e$ + "L16" + anft$(1, 2) + "V25" + anft$(3, 5)
numnote = numnote - 2
CASE 16
e$ = e$ + "L16" + anft$(1, 5) + "V25" + anft$(1, 5)
numnote = numnote - 2
CASE 17
e$ = e$ + "L16" + anft$(1, 2) + "V25" + anft$(3, 5) + "V50L8" + anft$(1, 2)
numnote = numnote - 3
CASE 18
e$ = e$ + "L8" + anft$(1, 2) + "L16" + anft$(1, 2) + "V25" + anft$(3, 5)
numnote = numnote - 3
CASE 19
e$ = e$ + "L8" + anft$(1, 2) + "V25" + anft$(3, 5)
numnote = numnote - 2
CASE 20
e$ = e$ + "L8" + anft$(1, 5) + "V25" + anft$(1, 5)
numnote = numnote - 2
END SELECT
LOOP WHILE numnote > athird
DO
e$ = e$ + "V50"
u = Random1(20)
SELECT CASE u
CASE 1
e$ = e$ + "L32" + en$(2) + en$(5) + en$(2) + enft$(3, 5)
numnote = numnote - 4
CASE 2
e$ = e$ + "L32" + en$(2) + enft$(3, 5) + en$(2) + enft$(3, 5)
numnote = numnote - 4
CASE 3
e$ = e$ + "L32" + en$(5) + en$(5) + "L16" + en$(5)
numnote = numnote - 3
CASE 4
e$ = e$ + "L16" + en$(5) + "L32" + en$(5) + enft$(3, 5)
numnote = numnote - 3
CASE 5
e$ = e$ + "L16" + en$(5) + en$(5)
numnote = numnote - 2
CASE 6
e$ = e$ + "L16" + en$(2) + enft$(3, 5)
numnote = numnote - 2
CASE 7
e$ = e$ + "L16" + en$(2) + enft$(3, 5) + "L8" + en$(5)
numnote = numnote - 3
CASE 8
e$ = e$ + "L8" + en$(5) + "L16" + en$(2) + enft$(3, 5)
numnote = numnote - 3
CASE 9
e$ = e$ + "L8" + en$(2) + en$(5)
numnote = numnote - 2
CASE 10
e$ = e$ + "L8" + en$(2) + enft$(3, 5)
numnote = numnote - 2
CASE 11
e$ = e$ + "L32" + en$(2) + "V25" + en$(5) + "V50" + en$(2) + "V25" + enft$(3, 5)
numnote = numnote - 4
CASE 12
e$ = e$ + "L32" + en$(2) + "V25" + enft$(3, 5) + en$(2) + "V50" + enft$(3, 5)
numnote = numnote - 4
CASE 13
e$ = e$ + "L32" + en$(5) + "V25" + en$(5) + "V50L16" + en$(5)
numnote = numnote - 3
CASE 14
e$ = e$ + "L16" + en$(5) + "V25L32" + en$(5) + "V50" + enft$(3, 5)
numnote = numnote - 3
CASE 15
e$ = e$ + "L16" + en$(5) + "V25" + en$(5)
numnote = numnote - 2
CASE 16
e$ = e$ + "L16" + en$(2) + "V25" + enft$(3, 5)
numnote = numnote - 2
CASE 17
e$ = e$ + "L16" + en$(2) + "V25" + enft$(3, 5) + "V50L8" + en$(5)
numnote = numnote - 3
CASE 18
e$ = e$ + "L8" + en$(5) + "L16" + en$(2) + "V25" + enft$(3, 5)
numnote = numnote - 3
CASE 19
e$ = e$ + "L8" + en$(2) + "V25" + en$(5)
numnote = numnote - 2
CASE 20
e$ = e$ + "L8" + en$(2) + "V25" + enft$(3, 5)
numnote = numnote - 2
END SELECT
LOOP WHILE numnote > 0
PLAY e$
DO WHILE PLAY(0) > 0
_LIMIT 600
IF _KEYDOWN(32) THEN EXIT DO
IF _KEYDOWN(27) THEN EXIT DO
LOOP
IF _KEYDOWN(27) THEN EXIT FOR
DO : LOOP WHILE _KEYDOWN(32)
NEXT 'song
SYSTEM
scaleslist:
DATA "3334","3344","3444","3445","3454","3545","4545","4543","3456","4565","4546"
DATA "4556","4666","5666","5444","5334","5355","5463","6444","6445","6366","6463"
DATA "END"
FUNCTION en$ (topval AS INTEGER)
en$ = "N" + _TRIM$(STR$(thiscale(Random1(topval))))
END FUNCTION
FUNCTION enft$ (fromval AS INTEGER, totoval AS INTEGER)
enft$ = "N" + _TRIM$(STR$(thiscale(Rand(fromval, totoval))))
END FUNCTION
FUNCTION anft$ (fromval AS INTEGER, totoval AS INTEGER)
anft$ = "N" + _TRIM$(STR$(altscale(Rand(fromval, totoval))))
END FUNCTION
FUNCTION Rand& (fromval&, toval&)
DIM sg%, f&, t&
IF fromval& = toval& THEN
Rand& = fromval&
EXIT FUNCTION
END IF
f& = fromval&
t& = toval&
IF (f& < 0) AND (t& < 0) THEN
sg% = -1
f& = f& * -1
t& = t& * -1
ELSE
sg% = 1
END IF
IF f& > t& THEN SWAP f&, t&
Rand& = INT(RND * (t& - f& + 1) + f&) * sg%
END FUNCTION
FUNCTION Random1& (maxvaluu&)
DIM sg%
sg% = SGN(maxvaluu&)
IF sg% = 0 THEN
Random1& = 0
ELSE
IF sg% = -1 THEN maxvaluu& = maxvaluu& * -1
Random1& = INT(RND * maxvaluu& + 1) * sg%
END IF
END FUNCTION
One fault with this program is that it doesn't play phrases (or "hooks", don't know how to say it out of the popular music industry) so one could recognize which song it is LOL. This program creates music which is too random. I programmed the "phrases" thing half-successfully with my Lua script for "1bitr". With "phrases" this program could make a good companion to bplus' program indicated in this thread:
https://staging.qb64phoenix.com/showthread.php?tid=1668
Purposely I set the songs playing fairly fast, ie. using "L32" instead of "L16" that I preferred, however PLAY statement doesn't allow tempos higher than 255. The logic of this program isn't very good for computing music with lengths and amplitude, which could be improved.