Skip to main content

rill_core/macros/
params.rs

1//! # Вспомогательные макросы для работы с параметрами
2
3// Эти макросы больше не нужны, но можно оставить для совместимости или удалить.
4// Оставляем только __init_ports, который используется.
5
6/// Инициализация портов (оставляем)
7#[macro_export]
8#[doc(hidden)]
9macro_rules! __init_ports {
10    // Для Source (только выходы)
11    (ports { audio_out: $out:expr $(,)? }, $node:expr, $outputs:ident) => {
12        for i in 0..$out {
13            let port = $crate::Port::output($node.id, i as u16, &format!("out_{}", i));
14            $node.$outputs.push(port);
15        }
16    };
17
18    // Для Sink (только входы)
19    (ports { audio_in: $in:expr $(,)? }, $node:expr, $inputs:ident) => {
20        for i in 0..$in {
21            let port = $crate::Port::input($node.id, i as u16, &format!("in_{}", i));
22            $node.$inputs.push(port);
23        }
24    };
25
26    // Для Processor (входы и выходы)
27    (ports { audio_in: $in:expr, audio_out: $out:expr $(,)? }, $node:expr, $inputs:ident, $outputs:ident, $controls:ident) => {
28        for i in 0..$in {
29            let port = $crate::Port::input($node.id, i as u16, &format!("in_{}", i));
30            $node.$inputs.push(port);
31        }
32
33        for i in 0..$out {
34            let port = $crate::Port::output($node.id, i as u16, &format!("out_{}", i));
35            $node.$outputs.push(port);
36        }
37    };
38
39    // С управляющими портами
40    (ports { audio_in: $in:expr, audio_out: $out:expr, control: $ctrl:expr }, $node:expr, $inputs:ident, $outputs:ident, $controls:ident) => {
41        $crate::__init_ports!(
42            ports {
43                audio_in: $in,
44                audio_out: $out
45            },
46            $node,
47            $inputs,
48            $outputs,
49            $controls
50        );
51
52        for i in 0..$ctrl {
53            let port = $crate::Port::control_in($node.id, i as u16, &format!("ctrl_{}", i));
54            $node.$controls.push(port);
55        }
56    };
57}
58
59// ============================================================================
60// Conversions from primitive types to ParamValue
61// ============================================================================
62use crate::ParamValue;
63
64impl From<f32> for ParamValue {
65    fn from(value: f32) -> Self {
66        ParamValue::Float(value)
67    }
68}
69
70impl From<i32> for ParamValue {
71    fn from(value: i32) -> Self {
72        ParamValue::Int(value)
73    }
74}
75
76impl From<bool> for ParamValue {
77    fn from(value: bool) -> Self {
78        ParamValue::Bool(value)
79    }
80}
81
82impl From<String> for ParamValue {
83    fn from(value: String) -> Self {
84        ParamValue::String(value)
85    }
86}
87
88impl From<&str> for ParamValue {
89    fn from(value: &str) -> Self {
90        ParamValue::String(value.to_string())
91    }
92}