{"id":13525805,"url":"https://github.com/rxi/lovebpm","last_synced_at":"2025-05-06T08:31:12.397Z","repository":{"id":48110923,"uuid":"62452282","full_name":"rxi/lovebpm","owner":"rxi","description":"A LÖVE library for syncing events to the BPM of an audio track","archived":false,"fork":false,"pushed_at":"2021-08-06T03:57:23.000Z","size":261,"stargazers_count":89,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-30T18:05:48.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rxi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-02T13:34:41.000Z","updated_at":"2025-04-22T21:35:26.000Z","dependencies_parsed_at":"2022-08-12T18:50:23.519Z","dependency_job_id":null,"html_url":"https://github.com/rxi/lovebpm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Flovebpm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Flovebpm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Flovebpm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Flovebpm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rxi","download_url":"https://codeload.github.com/rxi/lovebpm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252648575,"owners_count":21782405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:22.320Z","updated_at":"2025-05-06T08:31:12.124Z","avatar_url":"https://github.com/rxi.png","language":"Lua","funding_links":[],"categories":["Music"],"sub_categories":[],"readme":"# Lovebpm\nA [LÖVE](https://love2d.org/) library for syncing events to the BPM of an audio\ntrack.\n\n\n## Installation\nThe [lovebpm.lua](lovebpm.lua?raw=1) file should be dropped into an existing\nproject and required by it:\n\n```lua\nlovebpm = require \"lovebpm\"\n```\n\nLovebpm requires LÖVE version 0.10.0 or above.\n\n\n## Getting Started\nFirst a `Track` object should be created using the `lovebpm.newTrack()`\nfunction:\n\n```lua\nmusic = lovebpm.newTrack()\n```\n\nThe `update()` method of each track should be called from within the\n`love.update()` function:\n\n```lua\nfunction love.update(dt)\n  music:update()\nend\n```\n\nThe track's `load()` method should be called to load in the music. The load\nmethod takes a single argument: the music's filename or a `SoundData` object.\nThe `setBPM()` method should be called with the BPM of the loaded track.\n\n```lua\nmusic:load(\"loop.ogg\")\nmusic:setBPM(127)\n```\n\nAn event handler function for the `beat` event can be set. This will be called\nat the start of each beat when the song is playing, the beat number is passed to\nthe handler function.\n\n```lua\nmusic:on(\"beat\", function(n) print(\"beat:\", n) end)\n```\n\nThe music can be played by using the `play()` method.\n\n```lua\nmusic:play()\n```\n\nSee the [demo](demo) directory for a small example project.\n\n\n## Functions\n#### lovebpm.newTrack()\nCreates and returns a new `Track` object.\n\n#### lovebpm.detectBPM(filename [, opts])\nTries to detect the BPM of a looped song. `filename` can be a filename or\n`SoundData` object. An `opts` table can be provided with additional options,\nconsisting of the following:\n\n Name        | Default  | Description\n-------------|----------|-------------------------------------------------------\n `minbpm`    | 75       | Minimum allowed BPM\n `maxbpm`    | 300      | Maximum allowed BPM\n\n#### Track:load(filename)\nLoads an audio file or `SoundData` object.\n\n#### Track:setBPM(n)\nSets the BPM of the current track; this is used when calculating the current\nbeat.\n\n#### Track:setVolume([volume])\nSets the volume of the track, by default this is `1`.\n\n#### Track:setPitch([pitch])\nSets the pitch of the track, by default this is `1`.\n\n#### Track:setLooping([loop])\nSets whether the track should loop when it reaches the end. By default this is\n`false`.\n\n#### Track:setOffset([n])\nOffsets the track's timing by `n` seconds. This function can be used to\ncompensate for audio latency. By default this is `0`.\n\n#### Track:on(name, fn)\nSets an event handler for the event of the given `name`. The `on()` function can\nbe called several times for the same event to set multiple handlers. The events\nwhich can be emitted by a track are as follows:\n\n Name     | Description                                 | Arguments\n----------|---------------------------------------------|-----------------------\n `beat`   | The start of a beat has occurred            | `current_beat`\n `update` | The track's update() function was called    | `track_delta_time`\n `loop`   | The track has reached the end and looped    |\n `end`    | The track has reached the end and stopped   |\n\n\n#### Track:play([restart])\nPlays the track if it is stopped or paused. If `restart` is `true` then the\ntrack starts playing from the beginning.\n\n#### Track:pause()\nPauses the track's progress, but retains the current play-position of the track.\n\n#### Track:stop()\nStops the track, reseting the current play-position to the beginning.\n\n#### Track:setTime(n)\nSets the current play-position of the track to `n` seconds.\n\n#### Track:setBeat(n)\nSets the current play-position of the track to the given beat number.\n\n#### Track:getTotalTime()\nReturns the length of the track in seconds.\n\n#### Track:getTotalBeats()\nReturns the total number of beats in the track.\n\n#### Track:getTime()\nReturns the current play-position of the track.\n\n#### Track:getBeat([multiplier])\nReturns the current beat and subbeat of the track. For example, if the track is\nexactly half way between beats 3 and 4, the values `3` and `0.5` will be\nreturned:\n\n```lua\nlocal beat, subbeat = music:getBeat()\n```\n\n#### Track:update()\nUpdates the track's internal state, and emits events if required. This should be\ncalled from the `love.update()` function.\n\n\n## License\nThis library is free software; you can redistribute it and/or modify it under\nthe terms of the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxi%2Flovebpm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frxi%2Flovebpm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxi%2Flovebpm/lists"}