-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmain.odin
More file actions
61 lines (44 loc) · 1.43 KB
/
main.odin
File metadata and controls
61 lines (44 loc) · 1.43 KB
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
package flowtimer
import "core:slice"
import "core:time"
import rl "vendor:raylib"
import rlimgui "../thirdparty/imgui_impl_raylib"
import imgui "../thirdparty/odin-imgui"
main :: proc() {
rl.InitWindow(640, 360, "flowtimer")
defer rl.CloseWindow()
imgui.CreateContext(nil)
defer imgui.DestroyContext(nil)
rlimgui.init()
defer rlimgui.shutdown()
metronome: Metronome
create_metronome(&metronome)
defer delete_metronome(&metronome)
offsets := []time.Duration{time.Millisecond * 5000, time.Millisecond * 10000}
max_offset := slice.max(offsets)
set_beep(&metronome, "beeps/ping1.wav")
prepare_metronome(&metronome, offsets, time.Millisecond * 500, 5)
start_tick: time.Tick
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.BLACK)
rlimgui.begin()
imgui.Begin("Window")
if imgui.Button("Beep") {
start_tick = time.tick_now()
play_audio(&metronome, &metronome.buffer)
}
time_remaining := max_offset
if start_tick._nsec != 0 {
time_remaining = max_offset - time.tick_since(start_tick)
if time_remaining < 0 {
time_remaining = 0
start_tick._nsec = 0
}
}
imgui.LabelText("##", "%.0f", time.duration_milliseconds(time_remaining))
imgui.End()
rlimgui.end()
rl.EndDrawing()
}
}