Language Guide / DSP and Analysis
Graph
klang::Graph
Plots data series and functions in Studio.
Use the model’s graph to display points, a function’s response, or a stream of audio samples.
Example · Add points
Pass a y value to add() to use the point index as x. Supply a pair for explicit coordinates. Here the second series starts with three points at specified x positions.
graph.add(0.4);
graph.add(0.7);
graph[1].add({0, 0});
graph[1].add({0.5, 1});
graph[1].add({2, 0});
Example · Plot a function
Feed a single-argument function such as hardclip straight into the graph.
hardclip >> graph;
For Function<float, float> shaper, the graph sweeps the first argument along x. Supply the second argument inline.
shaper(4) >> graph;
Use with() to express the same binding explicitly.
shaper.with(4) >> graph;
Example · Capture audio
Route the input to the graph to append a sample to series zero. Each point uses the sample index as x.
in >> graph;
See Function for more on wrapping and configuring callables.
Example · Set both axes
The first pair sets the x range and the second pair sets the y range. Two arguments set only the x range.
graph(-2, 2, -1, 1);
A line graph plotter.
More...
#include <klang.h>
Definition at line 3749 of file klang.h.
◆ add() [1/2]
◆ add() [2/2]
◆ capacity()
◆ clear()
Definition at line 3453 of file klang.h.
3453 {
3456 for (int s = 0; s < GRAPH_SERIES; s++)
3459 }
◆ getAxes() [1/2]
◆ getAxes() [2/2]
Definition at line 3598 of file klang.h.
3598 {
3599 if (!
axes.x.valid()) {
3601 for (int s = 0; s < GRAPH_SERIES; s++)
3603 if (!
axes.y.valid() &&
axes.y.max != 0)
3605 }
3606 if (!
axes.y.valid()) {
3608 for (int s = 0; s < GRAPH_SERIES; s++)
3610 if (!
axes.y.valid() &&
axes.y.max != 0)
3612 }
3613 }
◆ getData()
◆ isDirty()
◆ operator Series &()
◆ operator()() [1/2]
Definition at line 3484 of file klang.h.
3484 {
3486 axes.x.min = min;
axes.x.max = max;
3487 return *this;
3488 }
◆ operator()() [2/2]
Definition at line 3499 of file klang.h.
3499 {
3501 axes.x.min = x_min;
axes.x.max = x_max;
3502 axes.y.min = y_min;
axes.y.max = y_max;
3503 return *this;
3504 }
◆ operator+=() [1/3]
Definition at line 3564 of file klang.h.
3564{
add(pt);
return *
this; }
◆ operator+=() [2/3]
Definition at line 3579 of file klang.h.
3579 {
3580 for (const auto& value : values)
3582 return *this;
3583 }
◆ operator+=() [3/3]
Definition at line 3562 of file klang.h.
3562{
add(y);
return *
this; }
◆ operator<<() [1/4]
Definition at line 3592 of file klang.h.
3592{
add(in);
return *
this; }
◆ operator<<() [2/4]
Definition at line 3586 of file klang.h.
3586 {
3587 plot(
function.with());
3588 return *this;
3589 }
void plot(Generic::Function< SIGNAL, Args... > &function)
◆ operator<<() [3/4]
Definition at line 3591 of file klang.h.
3591{
add(in);
return *
this; }
◆ operator<<() [4/4]
template<typename... Args>
| Graph & klang::Graph::operator<< |
( |
Function< Args... > & | function | ) |
|
|
inline |
◆ operator[]() [1/2]
◆ operator[]() [2/2]
◆ plot() [1/3]
Definition at line 3541 of file klang.h.
3541 {
3542 thread_local static Function fun(f);
3544 if (!series)
3546 if (series) {
3548 if (!
axes.x.valid())
3550 series->plot(fun.with(values...),
axes.x);
3551 }
3552 }
Function() -> Function< signal, Args... >
void add(const TYPE &item)
Add the specified item to the end of the array.
Series * find(void *function)
◆ plot() [2/3]
Definition at line 3513 of file klang.h.
3513 {
3515 if (!series)
3517 if (series) {
3519 if (!
axes.x.valid())
3521 series->plot(
function,
axes.x);
3522 }
3523 }
◆ plot() [3/3]
Definition at line 3527 of file klang.h.
3527 {
3529 if (!series)
3531 if (series) {
3533 if (!
axes.x.valid())
3535 series->plot(
function,
axes.x);
3536 }
3537 }
◆ setDirty()
◆ truncate()
Definition at line 3619 of file klang.h.
3619 {
3620 if (count <
data.count)
3622
3623 for (int s = 0; s < GRAPH_SERIES; s++)
3624 if (count <
data[s].count)
3625 data[s].count = count;
3626 }
◆ axes
◆ data
◆ dirty