-
Notifications
You must be signed in to change notification settings - Fork 13
Feature/new clock #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
diegovdc
wants to merge
5
commits into
ojack:master
Choose a base branch
from
diegovdc:feature/new-clock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2e42f8c
Imports clock
diegovdc 9a7de04
Fixes Clock.setInterval
diegovdc 4f9bf01
Adds several methods to clock
diegovdc 715de83
Cambia class Clock a funcion makeClock
diegovdc 8cc60df
Merge remote-tracking branch 'origin/master' into feature/new-clock
diegovdc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| const { | ||
| range, | ||
| bpmToMs, | ||
| wrapAt, | ||
| foldAt, | ||
| wrapBetween, | ||
| foldBetween, | ||
| wrapSeq, | ||
| foldSeq | ||
| } = require('./utils') | ||
|
|
||
| // class Clock { | ||
| // constructor({ | ||
| // bpm, // if bpm is specified, then interval will not be used | ||
| // interval = 1000, // tick interval in milliseconds | ||
| // startAt = 0, | ||
| // countBy = 1, | ||
| // countWith = null, | ||
| // onTick = [() => {}] | ||
| // } = {}) { | ||
| // this.dt = 0 | ||
| // this.currentVal = startAt | ||
| // this.countBy = countBy | ||
| // this.countWith = countWith | ||
| // ? countWith | ||
| // : last => last + countBy | ||
| // this.interval = bpm ? bpmToMs(bpm) : interval | ||
| // this.onTick = onTick | ||
|
|
||
| // // Clock methods as function properties: shaders may crash if passed in a method instead of a function, so this is why. | ||
| // this.val = () => this.currentVal | ||
| // this.wrapAt = modulo => wrapAt(modulo, this.val()) | ||
| // this.warpBetween = (bottom, top) => wrapBetween(bottom, top, this.val()) | ||
| // this.warpSeq = (numberArray) => wrapSeq(numberArray, this.val()) | ||
| // this.foldAt = modulo => foldAt(modulo, this.val()) | ||
| // this.foldBetween = (bottom, top) => foldBetween(bottom, top, this.val()) | ||
| // this.foldSeq = (numberArray) => foldSeq(numberArray, this.val()) | ||
| // } | ||
|
|
||
| // update(dt) { | ||
| // this.dt = dt | ||
| // } | ||
| // } | ||
|
|
||
| // module.exports = Clock | ||
|
|
||
|
|
||
| // const loop = require('raf-loop') | ||
|
|
||
| // loop(dt) | ||
|
|
||
| const opable = (fn, initialVal, ops = []) => ({ | ||
|
|
||
| }) | ||
|
|
||
|
|
||
| function makeClock() { | ||
| let dt_ = 0 | ||
| const getVal = interval => dt_/interval | ||
| const clock = (interval) => ({ | ||
| val: () => getVal(interval), | ||
| wrapAt: modulo => wrapAt(modulo, getVal(interval)), | ||
| wrapBetween: (bottom, top) => wrapBetween(bottom, top, getVal(interval)), | ||
| wrapSeq: (numberArray) => wrapSeq(numberArray, getVal(interval)), | ||
| foldAt: modulo => foldAt(modulo, getVal(interval)), | ||
| foldBetween: (bottom, top) => foldBetween(bottom, top, getVal(interval)), | ||
| foldSeq: (numberArray) => foldSeq(numberArray, getVal(interval)), | ||
| }) | ||
| clock.update = dt => {dt_ = dt} | ||
| return clock | ||
| } | ||
|
|
||
| module.exports = makeClock | ||
| // const osc = console.log | ||
| // const clock = makeClock() | ||
| // range(0, 20).forEach(dt => { | ||
| // clock.update(dt) | ||
| // osc(clock(2).wrapAt(5)) | ||
| // }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| console.log(range(0, 20).map(x => wrapBetween(5, 10, x))) | ||
| console.log(range(0, 20).map(x => foldBetween(5, 10, x))) | ||
| console.log(range(0, 20).map(x => wrapSeq([4, 5 ,2, 3], x))) | ||
| console.log(range(0, 20).map(x => foldSeq([4, 5 ,2, 3], x))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // beats per minute to milliseconds | ||
| function bpmToMs(bpm) { | ||
| return 60/bpm*1000 | ||
| } | ||
|
|
||
| function range(from, to) { | ||
| const res = [] | ||
| for(let i = from; i<to; i++) { | ||
| res.push(i) | ||
| } | ||
| return res | ||
| } | ||
|
|
||
| // inspired by sclang's warpAt | ||
| function wrapAt(modulo, index) { | ||
| return index%(modulo+1) | ||
| } | ||
|
|
||
| function wrapBetween(bottom, top, index) { | ||
| return wrapAt(top - bottom, index) + bottom | ||
| } | ||
|
|
||
| // inspired by sclang's foldAt | ||
| function foldAt(modulo, index) { | ||
| let res; | ||
| res = index % modulo | ||
| let isUp = parseInt(index / modulo) % 2 === 0 | ||
| if (isUp) { | ||
| return res | ||
| } else { | ||
| return modulo - res | ||
| } | ||
| } | ||
|
|
||
| function foldBetween(bottom, top, index) { | ||
| return foldAt(top - bottom, index) + bottom | ||
| } | ||
|
|
||
| function wrapSeq(numberArray, index) { | ||
| const length = numberArray.length | ||
| return numberArray[index%(length)] | ||
| } | ||
|
|
||
| function foldSeq(numberArray, index) { | ||
| const length = numberArray.length | ||
| const index_ = foldAt(length - 1, index) | ||
| return numberArray[index_] | ||
| } | ||
|
|
||
| module.exports = { | ||
| bpmToMs, | ||
| range, | ||
| wrapAt, | ||
| foldAt, | ||
| wrapBetween, | ||
| foldBetween, | ||
| wrapSeq, | ||
| foldSeq | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Voy a quitar esto