File: SimpleNumber-asTimeString.sc

package info (click to toggle)
supercollider-sc3-plugins 3.7.1~repack-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,332 kB
  • ctags: 11,704
  • sloc: cpp: 140,180; lisp: 14,746; ansic: 2,133; xml: 86; makefile: 82; haskell: 21; sh: 8
file content (26 lines) | stat: -rw-r--r-- 753 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
+ SimpleNumber{

	// receiver is a time in seconds
	// returns string "hh:mm:ss:ttt" where t is milliseconds
	asTimeStringLJP{
		var decimal, hours, minutes, seconds, mseconds, string;
		decimal = this.asInteger;

		hours = (decimal.div(3600)).asString;
		if(hours.size < 2, { hours = "0" ++ hours });

		minutes = (decimal.div(60) % 60).asString;
		if(minutes.size < 2, { minutes = "0" ++ minutes });

		seconds = (decimal % 60).asString;
		if(seconds.size < 2, { seconds = "0" ++ seconds });

		mseconds = (this.frac*1000).round.asInteger.asString;
		if(mseconds.size < 3, {
			mseconds = "0" ++ mseconds;
			if(mseconds.size < 3, { mseconds = "0" ++ mseconds });
		});

		^(hours ++ ":" ++ minutes ++ ":" ++ seconds ++ ":" ++ mseconds).asString
	}
}