mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 21:58:37 +00:00
Add continuous signals (sine, cosine, saw, etc)
This commit is contained in:
parent
74040e52b4
commit
b4b303a2d9
25
strudel.mjs
25
strudel.mjs
@ -148,7 +148,7 @@ class TimeSpan {
|
||||
return result
|
||||
}
|
||||
|
||||
get midpoint() {
|
||||
midpoint() {
|
||||
return(this.begin.add((this.end.sub(this.begin)).div(Fraction(2))))
|
||||
}
|
||||
|
||||
@ -671,6 +671,29 @@ function steady(value) {
|
||||
return new Pattern(span => Hap(undefined, span, value))
|
||||
}
|
||||
|
||||
export const signal = func => {
|
||||
const query = span => [new Hap(undefined, span, func(span.midpoint()))]
|
||||
return new Pattern(query)
|
||||
}
|
||||
|
||||
export const sine2 = signal(t => Math.sin(Math.PI * 2 * t))
|
||||
export const sine = signal(t => (Math.sin(Math.PI * 2 * t) + 1) / 2)
|
||||
|
||||
export const cosine2 = sine2._early(0.25)
|
||||
export const cosine = sine._early(0.25)
|
||||
|
||||
export const saw2 = signal(t => (t % 1) * 2)
|
||||
export const saw = signal(t => t % 1)
|
||||
|
||||
export const isaw2 = signal(t => (1 - (t % 1)) * 2)
|
||||
export const isaw = signal(t => 1 - (t % 1))
|
||||
|
||||
export const tri2 = fastcat(isaw2, saw2)
|
||||
export const tri = fastcat(isaw, saw)
|
||||
|
||||
export const square2 = signal(t => (Math.floor((t*2) % 2) * 2) - 1)
|
||||
export const square = signal(t => Math.floor((t*2) % 2))
|
||||
|
||||
function reify(thing) {
|
||||
// Tunrs something into a pattern, unless it's already a pattern
|
||||
if (thing?.constructor?.name == "Pattern") {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user