No update of float
when writing json
after first (few) tracks.
#3758
-
Hello! Let's say we want to write
If we do this - we get float, but it stops updating after 1-2 tracks.
Same here. No relevant output after first track. It just stops.
How to get this working with float instead of string? What I'm doing wrong? Thanks!
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Hi @gAlleb, def write_json()
print(1)
j = json()
print(2)
j.add("track_info",{elapsed = source.elapsed(s), duration = source.duration(s)})
print(3)
data = json.stringify(j)
print(4)
ignore(file.write(data=data, "/m.json"))
print(5)
end
thread.run(every=.1, write_json, fast=false) Most likely, def write_json(s)
def write_data()
source_record = {
track_info = {
elapsed = source.elapsed(s),
duration = source.duration(s)
}
}
data = json.stringify(source_record, compact=true) ^ "\n"
file.write("/m.json", data=data)
end
thread.run(write_data, every=.1, fast=false)
end
write_json(s) Also, sometimes |
Beta Was this translation helpful? Give feedback.
-
Maybe it's better with something like:
and the
|
Beta Was this translation helpful? Give feedback.
-
You should add some kind of safeguard. def float.json_safe(number)
list.mem(abs(number), [infinity, nan]) ? null() : number
end
def source.stats(source)
{
is_fallible = source.fallible,
is_ready = source.is_ready(),
is_up = source.is_up(),
is_active = source.is_active(),
is_self_sync = source.self_sync(),
clock_time = source.time(),
remaining = float.json_safe(source.remaining()),
duration = float.json_safe(source.duration()),
elapsed = source.elapsed(),
}
end
def write_json(s)
def write_data()
data = json.stringify(source.stats(s), compact=true) ^ "\n"
file.write("/m.json", data=data)
end
thread.run(write_data, every=.1, fast=false)
end
write_json(s)
Here's the simplified version. def write_json()
def null_float(f)
f == infinity ? null() : f
end
source_stats = {
track_info = {
elapsed = null_float(source.elapsed(s)),
duration = null_float(source.duration(s))
}
}
file.write(data=json.stringify(source_stats), "/m.json")
end
thread.run(write_json, every=.1, fast=false) |
Beta Was this translation helpful? Give feedback.
You should add some kind of safeguard.