{"id":16282850,"url":"https://github.com/zya/wa-metro","last_synced_at":"2025-09-08T05:33:29.016Z","repository":{"id":31563122,"uuid":"35127850","full_name":"zya/wa-metro","owner":"zya","description":"Simple scheduler for web-audio api","archived":false,"fork":false,"pushed_at":"2015-11-19T11:30:48.000Z","size":25,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-01T00:11:39.653Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-05T22:51:35.000Z","updated_at":"2024-07-14T08:14:08.000Z","dependencies_parsed_at":"2022-07-24T17:17:08.769Z","dependency_job_id":null,"html_url":"https://github.com/zya/wa-metro","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zya%2Fwa-metro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zya%2Fwa-metro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zya%2Fwa-metro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zya%2Fwa-metro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zya","download_url":"https://codeload.github.com/zya/wa-metro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232282925,"owners_count":18499331,"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-10-10T19:11:51.367Z","updated_at":"2025-01-03T03:12:46.240Z","avatar_url":"https://github.com/zya.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wa-metro\nSimple event scheduler for Web Audio API.\n\nThis library is based on [Chris Wilson](https://twitter.com/cwilso)'s scheduling [method](http://www.html5rocks.com/en/tutorials/audio/scheduling/) used in his [metronome](https://github.com/cwilso/metronome) example. \n\n### Installation\nYou can install `wa-metro` from npm.\n````\nnpm install wa-metro\n````\nOr grab the latest version from [build folder](https://github.com/zya/wa-metro/tree/master/build) and include it in your html.\n````html\n\n\u003cscript src='wa-metro.min.js'\u003e\u003c/script\u003e\n````\n### Example Usage\n````js\nvar context = new AudioContext();\nvar callback = function (time, step) {\n\t//schedule audio events with time and step number\n};\nvar metro = new Metro(context, callback);\nmetro.start();\n````\n### Callback\nThe callback function will have `time`, `step` and `timeFromScheduled` parameters. You can use these values to create dynamic loops and animations.\n\n#### Callback Parameters\n* `time` - the audio time for the step which can be used to schedule audio events.\n* `step`  - the number of the scheduled step.\n* `timeFromScheduled`  - the time (in seconds) that the event will be triggered from the schedule event (`time - context.currentTime`). This time can be used to schedule animations and other events as shown in the example below.\n\n````js\nvar metro = new Metro(context, callback);\nfunction callback(time, step, timeFromScheduled) {\n\tvar osc = context.createOscillator();\n\tosc.connect(context.destination);\n\tif(step === 1) {\n\t\tosc.frequency.value = 880;\n\t}\n\tosc.start(time);\n\tosc.stop(time + 0.1);\n\n  setTimeout(function(){\n    // trigger some js event\n  }, timeFromScheduled * 1000);\n}\n````\n### Methods\n````js\nvar metro = new Metro(context, callback);\nmetro.start(); // starts the clock and schedules events\nmetro.stop(); // stops the clock and resets the step to 1\nmetro.pause(); // pauses the clock and keeps the current step number\n````\n### Configuration\n````js\nvar metro = new Metro(context, callback);\nmetro.tempo = 100; // in BPM, defaults to 120\nmetro.steps = 8; // number of steps in a bar. defaults to 16\nmetro.look_ahead = 0.5; // look ahead time in Seconds. defaults to 1.0\nmetro.callback = function(time, step){}; // change the callback\n````\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzya%2Fwa-metro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzya%2Fwa-metro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzya%2Fwa-metro/lists"}