@@ -29,9 +29,9 @@ plug-in user interfaces with ease. It uses various custom data structures for
2929real-time visualizers, allowing you to easily build beautiful, performant
3030plug-in UIs.
3131
32- Here's a demo ([ YouTube mirror] ( https://www.youtube.com/watch?v=DQ-9XRBLpB4 ) )
32+ Here's a demo ([ YouTube mirror] ( https://www.youtube.com/watch?v=He70jwvdjFU ) )
3333
34- https://github.com/223230/cyma/ assets/68156346/dea8ee3e-7162-4752-a569-6dc4218b0745
34+ https://github.com/user-attachments/ assets/456a6705-5936-4118-a527-fb8999a91041
3535
3636Wanna see the code behind this? It's [ this example!] ( ./examples/visualizers )
3737
@@ -61,80 +61,137 @@ feature request so it can be added!
6161
6262## ❓ Example
6363
64- Here's how to create a basic oscilloscope with a grid background .
64+ Here's how to create a basic oscilloscope.
6565
6666![ Oscilloscope] ( doc/example.png )
6767
68+ Visualizers communicate with your plugin via busses. One bus can feed multiple
69+ visualizers. Just add it to your plugin like so:
70+
6871``` rust
69- Oscilloscope :: new (
70- cx ,
71- Data :: oscilloscope_buffer ,
72- (- 1.2 , 1.2 ),
73- ValueScaling :: Linear ,
74- )
75- . background_color (Color :: rgba (120 , 120 , 120 ));
72+ pub struct OscopePlugin {
73+ params : Arc <OscopeParams >,
74+ bus : Arc <MonoBus >,
75+ }
76+
77+ impl Plugin for OscopePlugin {
78+ fn initialize (
79+ & mut self ,
80+ _ : & AudioIOLayout ,
81+ buffer_config : & BufferConfig ,
82+ _ : & mut impl InitContext <Self >,
83+ ) -> bool {
84+ self . bus. set_sample_rate (buffer_config . sample_rate);
85+ true
86+ }
87+
88+ fn process (
89+ & mut self ,
90+ buffer : & mut Buffer ,
91+ _ : & mut AuxiliaryBuffers ,
92+ _ : & mut impl ProcessContext <Self >,
93+ ) -> ProcessStatus {
94+ if self . params. editor_state. is_open () {
95+ self . bus. send_buffer_summing (buffer );
96+ }
97+ ProcessStatus :: Normal
98+ }
99+
100+ fn editor (& mut self , _async_executor : AsyncExecutor <Self >) -> Option <Box <dyn Editor >> {
101+ editor :: create (
102+ self . bus. clone (),
103+ self . params. editor_state. clone (),
104+ )
105+ }
106+
107+ ...
108+ }
76109```
77110
78- Here, ` Data::oscilloscope_buffer ` is an ` Arc<Mutex<WaveformBuffer>> ` , a buffer
79- that allows for your audio to be sent to the ` Oscilloscope ` in a much smaller
80- package, while retaining peak information. Here, it's configured to be 512
81- samples long, and it represents 10 seconds of audio at 44.1 kHz.
111+ Now, in your editor code, you just need to subscribe to the bus. Then, you can
112+ use it for visualizers like this oscilloscope:
113+
114+ ``` rust
115+ pub fn create (
116+ bus : Arc <MonoBus >,
117+ editor_state : Arc <ViziaState >,
118+ ) -> Option <Box <dyn Editor >> {
119+ create_vizia_editor (editor_state , ViziaTheming :: default (), move | cx , _ | {
120+ bus . subscribe (cx );
121+ Oscilloscope :: new (cx , bus . clone (), 4.0 , (- 1.0 , 1.0 ), ValueScaling :: Linear )
122+ . color (Color :: rgb (120 , 120 , 120 ));
123+ })
124+ }
125+ ```
82126
83- It's very plug-and-play, you only need to call ` enqueue_buffer() ` in your
84- plugin's process function to use it!
85127
86- Check out the book, or the [ examples] ( examples ) to learn how to work with these
87- buffers .
128+ Check out the book or the [ examples] ( examples ) to familiarize yourself with this
129+ system .
88130
89131## 🍔 Composing views
90132
91133A core feature of Cyma is composability.
92134
93- For example, by combining views such as the ` Grid ` , ` UnitRuler ` , and
94- ` PeakGraph ` , you can make this real-time peak analyzer.
135+ For example, by combining views such as the ` Grid ` , ` UnitRuler ` , ` Graph ` , and
136+ ` Histogram ` you can make this real-time peak graph with an RMS plot and a
137+ histogram overlay.
95138
96139![ Peak visualizer] ( doc/composability_demo.png )
97140
98141``` rust
99- fn peak_graph (cx : & mut Context ) {
100- HStack :: new (cx , | cx | {
101- ZStack :: new (cx , | cx | {
102- Grid :: new (
103- cx ,
104- ValueScaling :: Linear ,
105- (- 32 . , 8 . ),
106- vec! [6.0 , 0.0 , - 6.0 , - 12.0 , - 18.0 , - 24.0 , - 30.0 ],
107- Orientation :: Horizontal ,
108- )
109- . color (Color :: rgb (60 , 60 , 60 ));
110-
111- Graph :: new (cx , Data :: peak_buffer , (- 32.0 , 8.0 ), ValueScaling :: Decibels )
112- . color (Color :: rgba (255 , 255 , 255 , 160 ))
113- . background_color (Color :: rgba (255 , 255 , 255 , 60 ));
114- })
115- . background_color (Color :: rgb (16 , 16 , 16 ));
116-
117- UnitRuler :: new (
118- cx ,
119- (- 32.0 , 8.0 ),
120- ValueScaling :: Linear ,
121- vec! [
122- (6.0 , " 6db" ),
123- (0.0 , " 0db" ),
124- (- 6.0 , " -6db" ),
125- (- 12.0 , " -12db" ),
126- (- 18.0 , " -18db" ),
127- (- 24.0 , " -24db" ),
128- (- 30.0 , " -30db" ),
129- ],
130- Orientation :: Vertical ,
131- )
132- . font_size (12 . )
133- . color (Color :: rgb (160 , 160 , 160 ))
134- . width (Pixels (32 . ));
135- })
136- . col_between (Pixels (8 . ));
137- }
142+ ZStack :: new (cx , | cx | {
143+ Grid :: new (
144+ cx ,
145+ ValueScaling :: Linear ,
146+ (- 32 . , 8.0 ),
147+ vec! [6.0 , 0.0 , - 6.0 , - 12.0 , - 18.0 , - 24.0 , - 30.0 ],
148+ Orientation :: Horizontal ,
149+ )
150+ . border_width (Pixels (0.5 ))
151+ . color (Color :: rgb (30 , 30 , 30 ));
152+ Graph :: peak (
153+ cx ,
154+ bus . clone (),
155+ 10.0 ,
156+ 50.0 ,
157+ (- 32.0 , 8.0 ),
158+ ValueScaling :: Decibels ,
159+ )
160+ . color (Color :: rgba (255 , 255 , 255 , 60 ))
161+ . background_color (Color :: rgba (255 , 255 , 255 , 30 ));
162+ Graph :: rms (
163+ cx ,
164+ bus . clone (),
165+ 10.0 ,
166+ 250.0 ,
167+ (- 32.0 , 8.0 ),
168+ ValueScaling :: Decibels ,
169+ )
170+ . color (Color :: rgba (255 , 92 , 92 , 128 ));
171+ Histogram :: new (cx , bus . clone (), 250.0 , (- 32.0 , 8.0 ), ValueScaling :: Decibels )
172+ . width (Pixels (64.0 ))
173+ . color (Color :: rgba (64 , 128 , 255 , 64 ))
174+ . background_color (Color :: rgba (64 , 128 , 255 , 32 ));
175+ UnitRuler :: new (
176+ cx ,
177+ (- 32.0 , 8.0 ),
178+ ValueScaling :: Linear ,
179+ vec! [
180+ (6.0 , " 6 dB" ),
181+ (0.0 , " 0 dB" ),
182+ (- 6.0 , " -6 dB" ),
183+ (- 12.0 , " -12 dB" ),
184+ (- 18.0 , " -18 dB" ),
185+ (- 24.0 , " -24 dB" ),
186+ (- 30.0 , " -30 dB" ),
187+ ],
188+ Orientation :: Vertical ,
189+ )
190+ . font_size (12 . )
191+ . color (Color :: rgb (220 , 220 , 220 ))
192+ . right (Pixels (8.0 ))
193+ . left (Stretch (1.0 ));
194+ });
138195```
139196
140197## 🙋 Contributing
0 commit comments