jevstrudel.git / website / src / pages / learn / hydra.mdx
hydra.mdx102 lines · 2.3 KB · raw
1---
2title: Hydra
3layout: ../../layouts/MainLayout.astro
4---
5
6import { MiniRepl } from '../../docs/MiniRepl';
7
8# Using Hydra inside Strudel
9
10You can write [hydra](https://hydra.ojack.xyz/) code in strudel! All you have to do is to call `await initHydra()` at the top:
11
12<MiniRepl
13  client:only="react"
14  tune={`await initHydra()
15// licensed with CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
16// by Zach Krall
17// http://zachkrall.online/
18
19osc(10, 0.9, 300)
20.color(0.9, 0.7, 0.8)
21.diff(
22osc(45, 0.3, 100)
23.color(0.9, 0.9, 0.9)
24.rotate(0.18)
25.pixelate(12)
26.kaleid()
27)
28.scrollX(10)
29.colorama()
30.luma()
31.repeatX(4)
32.repeatY(4)
33.modulate(
34osc(1, -0.9, 300)
35)
36.scale(2)
37.out()
38
39note("[a,c,e,<a4 ab4 g4 gb4>,b4]/2")
40.s("sawtooth").vib(2)
41.lpf(600).lpa(2).lpenv(6)
42`}
43/>
44
45## H patterns
46
47There is a special function `H` that allows you to use a pattern as an input to hydra:
48
49<MiniRepl
50  client:only="react"
51  tune={`await initHydra()
52let pattern = "3 4 5 [6 7]*2"
53shape(H(pattern)).out(o0)
54n(pattern).scale("A:minor").piano().room(1)
55`}
56/>
57
58## detectAudio
59
60To use hydra audio capture, call `initHydra` with `{detectAudio:true}` configuration param:
61
62<MiniRepl
63  client:only="react"
64  tune={`await initHydra({detectAudio:true})
65let pattern = "<3 4 5 [6 7]*2>"
66shape(H(pattern)).repeat()
67  .scrollY(
68    ()=> a.fft[0]*.25
69  )
70  .add(src(o0).color(.71 ).scrollX(.005),.95)
71.out(o0)
72n(pattern).scale("A:minor").piano().room(1)
73`}
74/>
75
76You might now be able to see this properly here: [open in REPL](/#YXdhaXQgaW5pdEh5ZHJhKCkKbGV0IHBhdHRlcm4gPSAiMyA0IDUgWzYgN10qMiIKc2hhcGUoSChwYXR0ZXJuKSkub3V0KG8wKQpuKHBhdHRlcm4pLnNjYWxlKCJBOm1pbm9yIikucGlhbm8oKS5yb29tKDEpIA%3D%3D)
77
78Similar to `detectAudio`, all the [available hydra options](https://github.com/hydra-synth/hydra-synth#api) can be passed to `initHydra`.
79
80## feedStrudel
81
82Using the `feedStrudel` option, you can transform strudel visualizations with hydra:
83
84<MiniRepl
85  client:only="react"
86  tune={`await initHydra({feedStrudel:1})
87//
88src(s0).kaleid(H("<4 5 6>"))
89  .diff(osc(1,0.5,5))
90  .modulateScale(osc(2,-0.25,1))
91  .out()
92//
93
94$: s("bd*4,[hh:0:<.5 1>]*8,~ rim").bank("RolandTR909").speed(.9)
95
96$: note("[<g1!3 <bb1 <f1 d1>>>]\*3").s("sawtooth")
97
98.room(.75).sometimes(add(note(12))).clip(.3)
99.lpa(.05).lpenv(-4).lpf(2000).lpq(8).ftype('24db')
100
101all(x=>x.fft(4).scope({pos:0,smear:.95}))`}
102/>