Skip to content

Commit e8ef58b

Browse files
committed
Audio & Sound functions
1 parent 6516b86 commit e8ef58b

File tree

127 files changed

+2460
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+2460
-130
lines changed

functions/Announcement/getRuleValue.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ server:
66
values:
77
- type: string|nil
88
name: rule value
9-
description: This example shows how you can check if a rule is set.
9+
description: Returns a [[string]] containing the value set for the specified key, false if invalid arguments were specified.
1010

1111
examples:
1212
- path: examples/getRuleValue-1.lua
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
addCommandHandler("getradio", function ()
2+
local radio = getRadioChannelName(getRadioChannel())
3+
outputChatBox("You're currently listening to "..radio.."!")
4+
end)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
addCommandHandler("getradio", function()
2+
local radio = getRadioChannelName(getRadioChannel())
3+
outputChatBox("You're currently listening to "..radio.."!")
4+
end)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (not getSFXStatus("spc_ea")) then
2+
outputChatBox("Please install the missing audio files to enjoy the full gaming experience")
3+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local function getBPM()
2+
local soundElement = playSound("song.mp3") -- Play the song
3+
local beatsValue = getSoundBPM(soundElement) -- Get the beats per minute of the song
4+
5+
outputChatBox("BPM: "..beatsValue) -- Output the beats to the chat box
6+
end
7+
addCommandHandler("bpm", getBPM)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local function getBPM()
2+
local soundElement = Sound("song.mp3") -- Play the song
3+
local beatsValue = soundElement:getBPM() -- Get the beats per minute of the song
4+
5+
outputChatBox("BPM: "..beatsValue) -- Output the beats to the chat box
6+
end
7+
addCommandHandler("bpm", getBPM)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
local screenSize = Vector2(guiGetScreenSize())
2+
local BOX_SIZE = Vector2(300, 100)
3+
local LINE_SIZE = Vector2(BOX_SIZE.x, 10)
4+
local BOX_POSITION = screenSize / 2 - BOX_SIZE / 2
5+
local TITLE_POSITION = BOX_POSITION + Vector2(8, 8)
6+
local ARTIST_POSITION = BOX_POSITION + Vector2(8, 32)
7+
8+
local sound
9+
10+
addCommandHandler("playsound", function ()
11+
if isElement(sound) then
12+
destroyElement(sound)
13+
end
14+
sound = playSound("https://example.com/song.mp3")
15+
end)
16+
17+
addCommandHandler("stopsound", function ()
18+
if isElement(sound) then
19+
destroyElement(sound)
20+
end
21+
end)
22+
23+
addEventHandler("onClientRender", root, function ()
24+
if isElement(sound) then
25+
local soundLength = getSoundLength(sound)
26+
local soundPosition = getSoundPosition(sound)
27+
local soundBufferLength = getSoundBufferLength(sound)
28+
29+
local meta = getSoundMetaTags(sound)
30+
31+
dxDrawRectangle(BOX_POSITION, BOX_SIZE, tocolor(20, 20, 20, 255), false, false)
32+
33+
if meta.title then
34+
dxDrawText(meta.title, TITLE_POSITION, 0, 0, tocolor(255, 255, 255, 255), 1.5, 1.5, "clear")
35+
end
36+
if meta.artist then
37+
dxDrawText(meta.artist, ARTIST_POSITION, 0, 0, tocolor(255, 255, 255, 255), 1.0, 1.0, "clear")
38+
end
39+
40+
dxDrawText(("%d:%02d"):format(soundPosition / 60, soundPosition % 60), BOX_POSITION + Vector2(8, BOX_SIZE.y - 32), BOX_POSITION + BOX_SIZE - Vector2(8, 0), tocolor(255, 255, 255, 255), 1.0, 1.0, "clear", "left", "top")
41+
dxDrawText(("%d:%02d"):format(soundLength / 60, soundLength % 60), BOX_POSITION + Vector2(8, BOX_SIZE.y - 32), BOX_POSITION + BOX_SIZE - Vector2(8, 0), tocolor(255, 255, 255, 255), 1.0, 1.0, "clear", "right", "top")
42+
43+
-- draw seek bar
44+
local linePosition = Vector2(BOX_POSITION.x, BOX_POSITION.y + BOX_SIZE.y - LINE_SIZE.y)
45+
dxDrawRectangle(linePosition, LINE_SIZE, tocolor(255, 255, 255, 128), false, false)
46+
47+
-- draw buffer length
48+
if soundBufferLength then
49+
dxDrawRectangle(linePosition, Vector2(LINE_SIZE.x * (soundBufferLength / soundLength), LINE_SIZE.y), tocolor(255, 255, 255, 96), false, false)
50+
end
51+
-- draw current position
52+
dxDrawRectangle(linePosition, Vector2(LINE_SIZE.x * (soundPosition / soundLength), LINE_SIZE.y), tocolor(255, 255, 255, 255), false, false)
53+
end
54+
end)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
local screenSize = Vector2(guiGetScreenSize())
2+
local BOX_SIZE = Vector2(300, 100)
3+
local LINE_SIZE = Vector2(BOX_SIZE.x, 10)
4+
local BOX_POSITION = screenSize / 2 - BOX_SIZE / 2
5+
local TITLE_POSITION = BOX_POSITION + Vector2(8, 8)
6+
local ARTIST_POSITION = BOX_POSITION + Vector2(8, 32)
7+
8+
local sound
9+
10+
addCommandHandler("playsound", function ()
11+
if isElement(sound) then
12+
sound:destroy()
13+
end
14+
sound = Sound("https://example.com/song.mp3")
15+
end)
16+
17+
addCommandHandler("stopsound", function ()
18+
if isElement(sound) then
19+
sound:destroy()
20+
end
21+
end)
22+
23+
addEventHandler("onClientRender", root, function ()
24+
if isElement(sound) then
25+
local soundLength = sound.length
26+
local soundPosition = sound.playbackPosition
27+
local soundBufferLength = sound.bufferLength
28+
29+
local meta = sound:getMetaTags()
30+
31+
dxDrawRectangle(BOX_POSITION, BOX_SIZE, tocolor(20, 20, 20, 255), false, false)
32+
33+
if meta.title then
34+
dxDrawText(meta.title, TITLE_POSITION, 0, 0, tocolor(255, 255, 255, 255), 1.5, 1.5, "clear")
35+
end
36+
if meta.artist then
37+
dxDrawText(meta.artist, ARTIST_POSITION, 0, 0, tocolor(255, 255, 255, 255), 1.0, 1.0, "clear")
38+
end
39+
40+
dxDrawText(("%d:%02d"):format(soundPosition / 60, soundPosition % 60), BOX_POSITION + Vector2(8, BOX_SIZE.y - 32), BOX_POSITION + BOX_SIZE - Vector2(8, 0), tocolor(255, 255, 255, 255), 1.0, 1.0, "clear", "left", "top")
41+
dxDrawText(("%d:%02d"):format(soundLength / 60, soundLength % 60), BOX_POSITION + Vector2(8, BOX_SIZE.y - 32), BOX_POSITION + BOX_SIZE - Vector2(8, 0), tocolor(255, 255, 255, 255), 1.0, 1.0, "clear", "right", "top")
42+
43+
-- draw seek bar
44+
local linePosition = Vector2(BOX_POSITION.x, BOX_POSITION.y + BOX_SIZE.y - LINE_SIZE.y)
45+
dxDrawRectangle(linePosition, LINE_SIZE, tocolor(255, 255, 255, 128), false, false)
46+
47+
-- draw buffer length
48+
if soundBufferLength then
49+
dxDrawRectangle(linePosition, Vector2(LINE_SIZE.x * (soundBufferLength / soundLength), LINE_SIZE.y), tocolor(255, 255, 255, 96), false, false)
50+
end
51+
-- draw current position
52+
dxDrawRectangle(linePosition, Vector2(LINE_SIZE.x * (soundPosition / soundLength), LINE_SIZE.y), tocolor(255, 255, 255, 255), false, false)
53+
end
54+
end)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local sound = playSound ("music.mp3")
2+
setSoundEffectEnabled (sound, "echo", true)
3+
4+
local echoParams = getSoundEffectParameters (sound, "echo")
5+
print (echoParams.feedback) -- 50
6+
iprint (echoParams)
7+
--[[
8+
{
9+
feedback = 50,
10+
leftDelay = 500,
11+
panDelay = false,
12+
rightDelay = 500,
13+
wetDryMix = 50
14+
}
15+
]]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local sound = Sound ("music.mp3")
2+
sound:setEffectEnabled("echo", true)
3+
4+
local echoParams = sound:getEffectParameters("echo")
5+
print (echoParams.feedback) -- 50
6+
iprint (echoParams)
7+
--[[
8+
{
9+
feedback = 50,
10+
leftDelay = 500,
11+
panDelay = false,
12+
rightDelay = 500,
13+
wetDryMix = 50
14+
}
15+
]]

0 commit comments

Comments
 (0)