English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Scripting (https://eab.abime.net/forumdisplay.php?f=117)
-   -   Time conversion in Arexx (https://eab.abime.net/showthread.php?t=83238)

KONEY 24 June 2016 23:35

Time conversion in Arexx
 
I'm writing an Arexx script for OctaMED SoundStudio which will calculate (roughly) the total playing time of a song.

Now I've got a quite correct amount of seconds which I'd like to show as minutes:seconds. Problem is, just dividing by 60 is returning a value which is minute and part of minute elapsed, not seconds.

Code:

TRUNC(total_ms/1000/60,1)
example: 270 seconds should be 4:30, not 4.5.

I'm not very familiar with Arexx and I don't know if there's a way to format time, or a ready to use code or library without having to manually split the value etc.

Any help?

thomas 25 June 2016 02:14

Code:

seconds = (total_ms + 500) % 1000
mm = seconds % 60
ss = seconds // 60
time = mm":"right(ss,2,'0')

% is division without decimals
// is modulo

KONEY 25 June 2016 13:15

Thanks! this works nicely! I just removed the addition of 500ms to the total because it made no sense to me.

thomas 25 June 2016 15:31

Quote:

Originally Posted by KONEY (Post 1098037)
I just removed the addition of 500ms to the total because it made no sense to me.

It's rounding, same result as trunc(total_ms / 1000 + 0.5)

If the song is 29.9 seconds long (29900 ms), you might want to display 0:30 rather than 0:29.

daxb 25 June 2016 19:14

Do you want to show us how do you calculate the total playing time of a OctaMED SoundStudio song? It would be nice to know if scanning of all pattern data is needed.

Usually I use the following to eliminate decimal digits from a given seconds value:
Code:

s = (sec // 60) % 1
If this isn`t a good idea, please let me know.

KONEY 25 June 2016 19:48

Quote:

Originally Posted by thomas (Post 1098044)
It's rounding,
If the song is 29.9 seconds long (29900 ms), you might want to display 0:30 rather than 0:29.

you're right, I'll put it back!

KONEY 25 June 2016 19:57

Quote:

Originally Posted by daxb (Post 1098065)
Do you want to show us how do you calculate the total playing time of a OctaMED SoundStudio song? It would be nice to know if scanning of all pattern data is needed.

Sure. Well actually I realized that an average value must be accepted, or you need to play the song fully. I assumed no premature end commands are used as they're not needed in OctaMED, since it allows custom block length. Also full stops "FFE" in the middle of the songs are not detected. I also assumed that TPL changing commands would be at the top of the block, otherwise a full scan of each line of each track would be necessary.

So the script in pseudo code will:
play the song
cycle blocks in sequence
allow a few ms to tpl commands to eventually get applied
calculate lines ms accordingly to bpm and tpl
add to a total
finish cycle
stop playing
format the output
show output

I am quite satisfied with the resulting values, they quite match the real song playing time.

I made a video also: https://www.youtube.com/watch?v=Fc_SkySeS90

if you want I can upload the script

daxb 25 June 2016 22:27

I guess for most mods it will work. Only on some mods with several/regular speed/tempo changes won`t taken into account. A play song in fast motion function would be nice. :)

KONEY 26 June 2016 09:06

yes and 90% of the mods you mentioned change TPL at every line to simulate quantize/shuffle therefore the final bpm are quite the same, so I suppose it would do a good job anyway :)


All times are GMT +2. The time now is 02:47.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04205 seconds with 11 queries