-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MusicEx.exw
74 lines (54 loc) · 1.71 KB
/
MusicEx.exw
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
--Render Window Example
--Written By Andy P.
--Copyright (c) 2022
--Note: Song "Hey!" from bensound.com
--By: Benjamin Tissot
--Used for testing, not included in repository due to licensing issues
--Easy to find or you can use your own music and change the source accordingly
without warning
without type_check
include std/machine.e
include std/dll.e
include flags.e
include System.ew
include Graphics.ew
include Audio.ew
atom win = sfRenderWindow_create(800,600,32,"Music Example - Press Space to play/Z to stop",sfClose,0)
atom song = sfMusic_createFromFile("hey.ogg")
if win = -1 then
puts(1,"Failed to create Render Window!\n")
abort(0)
end if
constant event = allocate(4 * 6) --allocate memory for events
atom blue = sfColor_fromRGB(0,0,255) --blue
--Use RGB values (i.e. red is 255,0,0)
--You can also use sfColor_fromRGBA to add in a alpha color
--use to change color of window
while sfRenderWindow_isOpen(win) do
while sfRenderWindow_pollEvent(win,event) do
atom eventType = peek4s(event)
atom code = peek4s(event+4)
atom alt = peek4s(event+8)
atom control = peek4s(event+13)
atom shift = peek4s(event+16)
atom system = peek4s(event+20)
if eventType = sfEvtClosed then
sfRenderWindow_close(win)
end if
if eventType = sfEvtKeyPressed then
if code = sfKeySpace then
sfMusic_play(song)
elsif code = sfKeyZ then
sfMusic_stop(song)
elsif code = sfKeyEscape then
sfRenderWindow_close(win)
end if
end if
end while
sfRenderWindow_clear(win,sfBLACK)
sfRenderWindow_display(win)
end while
free(event) --free event to prevent memory leaks
sfMusic_destroy(song)
sfRenderWindow_destroy(win)
8.78