GetSoundBPM: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Improve example.)
 
(5 intermediate revisions by 4 users not shown)
Line 3: Line 3:
{{New feature/item|3.0131|1.3.0|4145|
{{New feature/item|3.0131|1.3.0|4145|
This function gets the beats per minute of a specific [[sound]] element.
This function gets the beats per minute of a specific [[sound]] element.
{{Warning|This function is expensive to call and will freeze the client about 1-3 seconds. Also, trying to get the BPM from a sound directly after creation will not work. You need a
{{Warning|This function is expensive to call and will freeze the client about 1-3 seconds. Also, trying to get the BPM from a sound directly after its creation will make the sound start only after the client freeze. You can use a [[setTimer]] to call this function after song creation so it can play normally.}}
[[setTimer]] to do this.}}
}}
}}


Line 19: Line 18:
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function bpm ()
function getBPM()
     -- Long version (might be more understandable as example)
     local soundElement = playSound("song.mp3") -- Play the song
    sound = playSound ( "song.mp3" ) -- Play the song
     local beatsValue = getSoundBPM(soundElement) -- Get the beats per minute of the song
     beats = getSoundBPM ( sound ) -- Get the beats per minute of the song
 
     outputChatBox ( "Long code version: " .. beats ) -- Output the beats to the chat box
     outputChatBox("BPM: "..beatsValue) -- Output the beats to the chat box
end
end
addCommandHandler ( "bpm", bpm )
addCommandHandler("bpm", getBPM)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
Line 38: Line 37:
[[ar:getSoundBPM]]
[[ar:getSoundBPM]]
[[RO:getSoundBPM]]
[[RO:getSoundBPM]]
[[PT-BR:getSoundBPM]]

Latest revision as of 15:54, 21 December 2021

This function gets the beats per minute of a specific sound element.

[[|link=|]] Warning: This function is expensive to call and will freeze the client about 1-3 seconds. Also, trying to get the BPM from a sound directly after its creation will make the sound start only after the client freeze. You can use a setTimer to call this function after song creation so it can play normally.

Syntax

int getSoundBPM ( element sound )

OOP Syntax Help! I don't understand this!

Method: sound:getBPM(...)


Required Arguments

Returns

Returns the beats per minute of the given sound.

Example

Click to collapse [-]
Client
function getBPM()
    local soundElement = playSound("song.mp3") -- Play the song
    local beatsValue = getSoundBPM(soundElement) -- Get the beats per minute of the song

    outputChatBox("BPM: "..beatsValue) -- Output the beats to the chat box
end
addCommandHandler("bpm", getBPM)

Requirements

Minimum server version n/a
Minimum client version 1.3.0-9.04162

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.3.0-9.04162" />

See Also