aboutsummaryrefslogtreecommitdiff
path: root/site/udo/txt_tools.udo
blob: e26063591246db9078d3aabbdd10fb4247bd0778 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef UDO_TXTTOOLS
#define UDO_TXTTOOLS ##
/*
	Text tools

	This file is part of the SONICS UDO collection by Richard Knight 2024
		License: GPL-2.0-or-later
		http://1bpm.net
*/


/*
	Print a notification prepended with a line of asterisks
	
	tt_notify Stext

	Stext	text to print
*/
opcode tt_notify, 0, S
	Stext xin
	Snew = "\n"
	iwidth = 60
	index = 0
	while (index < iwidth) do
		Snew = strcat(Snew, "*");
		index += 1
	od
	prints strcat(strcat(Snew, "\n"), strcat(Stext, "\n\n"))
endop



/*
	Print a notification prepended with a line of asterisks and exit
	
	tt_notify Stext

	Stext	text to print
*/
opcode tt_notify_fatal, 0, S
	Stext xin
	tt_notify(Stext)
	exitnow
endop


/*
	Return a number of seconds as HH:MM:SS format
	
	Stime tt_parsetime iseconds

	iseconds	seconds to parse
	
	Stime		formatted time

*/
opcode tt_parsetime, S, i
	input xin
	ihours = floor(input / 3600)
	iminutes = floor((input - (ihours * 3600)) / 60)
	iseconds = input - (ihours * 3600) - (iminutes * 60)
	xout sprintf("%02d:%02d:%05.2f", ihours, iminutes, iseconds)
endop


/*
	Print a timestamped notification prepended with a line of asterisks and exit
	
	tt_notifytime Stext

	Stext	text to print
*/
opcode tt_notifytime, 0, S
	Stext xin
	Stime tt_parsetime times()
	tt_notify sprintf("%s | %s", Stime, Stext)
endop


/*
	Strip newline from end of line: built-in opcode has some problems

	Soutput tt_stripnewline Sinput

	Soutput		processed without newline at end if existent
	
	Sinput		line to process
*/
opcode tt_stripnewline, S, S
	Sline xin
	index = strindex(Sline, "\n")
	if (index != -1) then
		Sline = strsub(Sline, 0, index)
	endif
	xout Sline
endop

#end