diff --git a/extensions/community/SyncChannelBpm.json b/extensions/community/SyncChannelBpm.json new file mode 100644 index 000000000..a2e478b99 --- /dev/null +++ b/extensions/community/SyncChannelBpm.json @@ -0,0 +1,640 @@ +{ + "author": "", + "category": "Audio", + "extensionNamespace": "", + "fullName": "Sync Music or Sound Channel BPM", + "gdevelopVersion": "", + "helpPath": "", + "iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMy4wLjMsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iSWNvbnMiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgMzIgMzIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMyIDMyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8Zz4NCgk8cGF0aCBkPSJNMTYsMjFjMC4zLDAsMC42LTAuMSwwLjgtMC40bDEzLTE3YzAuMy0wLjQsMC4zLTEuMS0wLjItMS40Yy0wLjQtMC4zLTEuMS0wLjMtMS40LDAuMmwtNS43LDcuNWwtMS00LjgNCgkJYy0wLjQtMS44LTItMy4xLTMuOC0zLjFoLTMuNGMtMS44LDAtMy40LDEuMi0zLjgsM0w1LjgsMjUuNWMtMC4zLDEuMSwwLDIuMiwwLjcsMy4xQzcuMiwyOS41LDguMiwzMCw5LjMsMzBoMTMuMw0KCQljMS4xLDAsMi4yLTAuNSwyLjktMS40YzAuNy0wLjksMC45LTIsMC43LTMuMWwtMi41LTkuN2MtMC4xLTAuNS0wLjctMC45LTEuMi0wLjdjLTAuNSwwLjEtMC45LDAuNy0wLjcsMS4ybDEuNSw1LjhIOC42bDMuOC0xNi41DQoJCWMwLjItMC45LDEtMS41LDEuOC0xLjVoMy40YzAuOSwwLDEuNywwLjYsMS44LDEuNWwxLjQsNi41bC01LjYsNy40Yy0wLjMsMC40LTAuMywxLjEsMC4yLDEuNEMxNS42LDIwLjksMTUuOCwyMSwxNiwyMXoiLz4NCgk8cGF0aCBkPSJNMTUsOGgyYzAuNiwwLDEtMC40LDEtMXMtMC40LTEtMS0xaC0yYy0wLjYsMC0xLDAuNC0xLDFTMTQuNCw4LDE1LDh6Ii8+DQoJPHBhdGggZD0iTTE1LDExaDJjMC42LDAsMS0wLjQsMS0xcy0wLjQtMS0xLTFoLTJjLTAuNiwwLTEsMC40LTEsMVMxNC40LDExLDE1LDExeiIvPg0KCTxwYXRoIGQ9Ik0xNSwxNGgyYzAuNiwwLDEtMC40LDEtMXMtMC40LTEtMS0xaC0yYy0wLjYsMC0xLDAuNC0xLDFTMTQuNCwxNCwxNSwxNHoiLz4NCjwvZz4NCjwvc3ZnPg0K", + "name": "SyncChannelBpm", + "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/Glyphster Pack/Master/SVG/Music/ace14b0d551cd485b9f2655d58930490d2e4c8035f991a99badc388fbd328165_Music_metronome_tempo_beat_bpm.svg", + "shortDescription": "Set the BPM of a channel playing a sound and set up events to activate on a beat. ", + "version": "1.0.0", + "description": [ + "Set the BPM of a channel playing a sound and set up events to activate on a beat. ", + "For example, if you have an audio file on sound channel 1, you can set it's BPM. ", + "On the beat, you can activate events, such as a camera zoom tween, or color change.", + "", + "Reminder that the on beat detection must be running every frame of when you want it to detect the beats!" + ], + "origin": { + "identifier": "SyncChannelBpm", + "name": "gdevelop-extension-store" + }, + "tags": [ + "bpm", + "music", + "audio", + "rhythm" + ], + "authorIds": [ + "UPwCL8XsOqNwfJy62IjJnMtcJRh2" + ], + "dependencies": [], + "globalVariables": [ + { + "name": "BPM_MANAGER", + "type": "structure", + "children": [ + { + "name": "BPMMultiplier", + "type": "number", + "value": 1 + }, + { + "name": "BeatInterval", + "type": "number", + "value": 0 + }, + { + "name": "CurrentBeat", + "type": "number", + "value": 0 + }, + { + "name": "HasFocus", + "type": "number", + "value": 0 + }, + { + "name": "LastBeatIndex", + "type": "number", + "value": 0 + }, + { + "name": "TrackBPM", + "type": "number", + "value": 140 + } + ] + } + ], + "sceneVariables": [], + "eventsFunctions": [ + { + "description": "Checks for beats on a sound channel. This has to be running every frame for the beat detection to work.\n\nDo not run both sound and music handlers at the same time.", + "fullName": "Beat handler (Sound Channel)", + "functionType": "Action", + "group": "Sound Channel", + "name": "HandlerSound", + "sentence": "Check for beats on sound channel _PARAM1_", + "events": [ + { + "colorB": 228, + "colorG": 176, + "colorR": 74, + "creationTime": 0, + "folded": true, + "name": "ALL", + "source": "", + "type": "BuiltinCommonInstructions::Group", + "events": [ + { + "colorB": 228, + "colorG": 176, + "colorR": 74, + "creationTime": 0, + "folded": true, + "name": "CALCULATED", + "source": "", + "type": "BuiltinCommonInstructions::Group", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.BeatInterval", + "=", + "60 / BPM_MANAGER.TrackBPM" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.CurrentBeat", + "=", + "floor(SoundChannelPlayingOffset(Channel) / BPM_MANAGER.BeatInterval)" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NumberVariable" + }, + "parameters": [ + "BPM_MANAGER.CurrentBeat", + "<", + "BPM_MANAGER.LastBeatIndex" + ] + } + ], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.LastBeatIndex", + "=", + "0" + ] + } + ] + } + ], + "parameters": [] + }, + { + "colorB": 228, + "colorG": 176, + "colorR": 74, + "creationTime": 0, + "folded": true, + "name": "FOCUS_CHECK", + "source": "", + "type": "BuiltinCommonInstructions::Group", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "BuiltinCommonInstructions::And" + }, + "parameters": [], + "subInstructions": [ + { + "type": { + "value": "AdvancedWindow::IsFocused" + }, + "parameters": [ + "" + ] + }, + { + "type": { + "value": "NumberVariable" + }, + "parameters": [ + "BPM_MANAGER.HasFocus", + "!=", + "1" + ] + } + ] + } + ], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.LastBeatIndex", + "=", + "floor(SoundChannelPlayingOffset(Channel) / BPM_MANAGER.BeatInterval)" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.HasFocus", + "=", + "1" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "BuiltinCommonInstructions::And" + }, + "parameters": [], + "subInstructions": [ + { + "type": { + "inverted": true, + "value": "AdvancedWindow::IsFocused" + }, + "parameters": [ + "" + ] + }, + { + "type": { + "value": "NumberVariable" + }, + "parameters": [ + "BPM_MANAGER.HasFocus", + "=", + "1" + ] + } + ] + } + ], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.HasFocus", + "=", + "0" + ] + } + ] + } + ], + "parameters": [] + } + ], + "parameters": [] + } + ], + "parameters": [ + { + "description": "Channel", + "name": "Channel", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Checks if a beat on a sound channel is hit.\n\n", + "fullName": "If a beat on a sound channel is hit", + "functionType": "Condition", + "group": "Sound Channel", + "name": "OnBeatSound", + "sentence": "If a beat on sound channel _PARAM1_ is hit", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NumberVariable" + }, + "parameters": [ + "BPM_MANAGER.CurrentBeat", + ">", + "BPM_MANAGER.LastBeatIndex" + ] + }, + { + "type": { + "value": "BuiltinCommonInstructions::Once" + }, + "parameters": [] + } + ], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.LastBeatIndex", + "=", + "floor(SoundChannelPlayingOffset(Channel) / BPM_MANAGER.BeatInterval)" + ] + }, + { + "type": { + "value": "SetReturnBoolean" + }, + "parameters": [ + "True" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Channel", + "name": "Channel", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Sets the BPM. You must know the BPM of your song! (Ex. 140).\n", + "fullName": "Set the BPM", + "functionType": "Action", + "name": "BpmSet", + "sentence": "Set the BPM to _PARAM1_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.TrackBPM", + "=", + "BPM" + ] + } + ] + } + ], + "parameters": [ + { + "description": "BPM", + "name": "BPM", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Checks for beats on a music channel. This has to be running every frame for the beat detection to work.\n\nDo not run both sound and music handlers at the same time.", + "fullName": "Beat handler (Music Channel)", + "functionType": "Action", + "group": "Music Channel", + "name": "HandlerMusic", + "sentence": "Check for beats on music channel _PARAM1_", + "events": [ + { + "colorB": 228, + "colorG": 176, + "colorR": 74, + "creationTime": 0, + "name": "ALL", + "source": "", + "type": "BuiltinCommonInstructions::Group", + "events": [ + { + "colorB": 228, + "colorG": 176, + "colorR": 74, + "creationTime": 0, + "folded": true, + "name": "CALCULATED", + "source": "", + "type": "BuiltinCommonInstructions::Group", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.BeatInterval", + "=", + "60 / BPM_MANAGER.TrackBPM" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.CurrentBeat", + "=", + "floor(MusicChannelPlayingOffset(Channel) / BPM_MANAGER.BeatInterval)" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NumberVariable" + }, + "parameters": [ + "BPM_MANAGER.CurrentBeat", + "<", + "BPM_MANAGER.LastBeatIndex" + ] + } + ], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.LastBeatIndex", + "=", + "0" + ] + } + ] + } + ], + "parameters": [] + }, + { + "colorB": 228, + "colorG": 176, + "colorR": 74, + "creationTime": 0, + "name": "FOCUS_CHECK", + "source": "", + "type": "BuiltinCommonInstructions::Group", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "BuiltinCommonInstructions::And" + }, + "parameters": [], + "subInstructions": [ + { + "type": { + "value": "AdvancedWindow::IsFocused" + }, + "parameters": [ + "" + ] + }, + { + "type": { + "value": "NumberVariable" + }, + "parameters": [ + "BPM_MANAGER.HasFocus", + "!=", + "1" + ] + } + ] + } + ], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.LastBeatIndex", + "=", + "floor(MusicChannelPlayingOffset(Channel) / BPM_MANAGER.BeatInterval)" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.HasFocus", + "=", + "1" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "BuiltinCommonInstructions::And" + }, + "parameters": [], + "subInstructions": [ + { + "type": { + "inverted": true, + "value": "AdvancedWindow::IsFocused" + }, + "parameters": [ + "" + ] + }, + { + "type": { + "value": "NumberVariable" + }, + "parameters": [ + "BPM_MANAGER.HasFocus", + "=", + "1" + ] + } + ] + } + ], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.HasFocus", + "=", + "0" + ] + } + ] + } + ], + "parameters": [] + } + ], + "parameters": [] + } + ], + "parameters": [ + { + "description": "Channel", + "name": "Channel", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Checks if a beat on a music channel is hit.\n\n", + "fullName": "If a beat on a music channel is hit", + "functionType": "Condition", + "group": "Music Channel", + "name": "OnBeatMusic", + "sentence": "If a beat on music channel _PARAM1_ is hit", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NumberVariable" + }, + "parameters": [ + "BPM_MANAGER.CurrentBeat", + ">", + "BPM_MANAGER.LastBeatIndex" + ] + }, + { + "type": { + "value": "BuiltinCommonInstructions::Once" + }, + "parameters": [] + } + ], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "BPM_MANAGER.LastBeatIndex", + "=", + "floor(MusicChannelPlayingOffset(Channel) / BPM_MANAGER.BeatInterval)" + ] + }, + { + "type": { + "value": "SetReturnBoolean" + }, + "parameters": [ + "True" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Channel", + "name": "Channel", + "type": "expression" + } + ], + "objectGroups": [] + } + ], + "eventsBasedBehaviors": [], + "eventsBasedObjects": [] +} \ No newline at end of file