Convert String to Number - 1micha.elok - 08-20-2024
Hi Marcus,
I'm making a tiny karaoke machine, but I can't find a function to convert string to number and to syncronize song and lyrics.
Could you please advise me ?
Code: 'TOBE...synchronize lyrics and timestamps
clearscreen()
set caret 10,10
for i = 1 to j-2
'time1 = left(lyrics[i],2) 'take the first two digits number of lyrics[i]
'convert time1 from string to number
'if 'real time' = time1 then display lyrics
wln mid(lyrics[i],3,80)
wait 3000 'this line should be removed if lyrics and timestamps are synchronized
next
Herewith the full code
Code: '==================================================================================
' T.I.N.Y K.A.R.A.O.K.E
'
' Songs :
' 1. Nathan Evans - Wellerman (Sea Shanty)
' https://www.youtube.com/watch?v=bNQSMTNSnUw
'
' DISCLAIMER
' It is not intended for commercial use and not for sale
' No person or entity associated with this game received payment
' or anything of value, or entered into any agreement,
' in connection with any game assets used in this game.
'
' All trademarks and game assets are the property of their respective owners.
' While every effort is made to acknowledge their works,
' some of the game assets used in in this tiny game may not have
' clear name of the artist/author/creator/developer to be referred with.
' It may not include all relevant facts or the most up-to-date information.
'
'==================================================================================
'-----------------
' INITIALIZATION
'-----------------
set window "Karaoke",500,225,false,2
' color definition
visible black = [0,0,0]
visible white = [255,255,255]
' table to store lyrics line by line
lyrics = []
'-----------
' MAIN LOOP
'-----------
do
clearscreen()
'karaoke menu
set caret 10,10
wln "Karaoke"
wln "* Choose music file (wav)"
wln "* Choose lyric file (txt)"
wln
wln "Press SPACE to continue or ESC to quit"
do
if keydown(KEY_ESCAPE,true) then end
wait 1
until keydown(KEY_SPACE,true)
'loop until filename is not blank
do
filemusic = openfiledialog("wav")
filelyrics = openfiledialog("txt")
until not filemusic="" and not filelyrics=""
'loop until ready
loopready("Are you ready",14)
'read lyrics from text file line by line
f = openfile(filelyrics)
j = 1
do
lyrics[j] = frln(f)
j = j + 1
until frln(f) = unset
free file f
'load and play music
load music 1,filemusic
play music 1
'TOBE...synchronize lyrics and timestamps
clearscreen()
set caret 10,10
for i = 1 to j-2
'time1 = left(lyrics[i],2) 'take the first two digits number of lyrics[i]
'convert time1 from string to number
'if 'real time' = time1 then display lyrics
wln mid(lyrics[i],3,80)
wait 3000 'this line should be removed if lyrics and timestamps are synchronized
next
'loop until ready
loopready("Next Song ",14)
free music 1
loop
'-----------
' FUNCTIONS
'-----------
function clearscreen()
set color black;cls;set color white
endfunc
function loopready(message,lineNum)
do
'clear inside a defined rectangle
set color black
draw rect 10,lineNum*15,300,15,1
'continue ?
set color white
set caret 10,lineNum*15
write message+" (Y/N) ?"
answer = rln()
if upper(answer)="N" then end
until upper(answer)="Y"
endfunc
RE: Convert String to Number - kevin - 08-20-2024
Hi - re converting a string to a number - you should be able to use the int function - i.e. time1 = int( left(lyrics[i],2)) ? I don't have a chance to test at the moment unfortunately.....
RE: Convert String to Number - 1micha.elok - 08-20-2024
(08-20-2024, 09:23 AM)kevin Wrote: Hi - re converting a string to a number - you should be able to use the int function - i.e. time1 = int( left(lyrics[i],2)) ? I don't have a chance to test at the moment unfortunately.....
Thank you, Kevin
...why can't I think earlier the int function ? my old brain ...
RE: Convert String to Number - johnno56 - 08-20-2024
This is brilliant! It is a shame that I cannot sing... lol
Well done!
|