rill-core 0.5.0-beta.5

Core foundation for the Rill ecosystem — traits, math, buffers, queues, time, macros
Documentation
//! # Helper macros for working with ports

/// General macro for creating any type of node
#[macro_export]
macro_rules! node {
    (
        $(#[$meta:meta])*
        source $name:ident<$T:ident: $crate::math::Transcendental, const $BUF:ident: usize>
        $(where $($bounds:tt)*)?
        { $($tt:tt)* }
    ) => {
        $crate::source_node! {
            $(#[$meta])*
            pub $name<$T, $BUF>
            $(where $($bounds)*)?
            { $($tt)* }
        }
    };

    (
        $(#[$meta:meta])*
        processor $name:ident<$T:ident: $crate::math::Transcendental, const $BUF:ident: usize>
        $(where $($bounds:tt)*)?
        { $($tt:tt)* }
    ) => {
        $crate::processor_node! {
            $(#[$meta])*
            pub $name<$T, $BUF>
            $(where $($bounds)*)?
            { $($tt)* }
        }
    };

    (
        $(#[$meta:meta])*
        sink $name:ident<$T:ident: $crate::math::Transcendental, const $BUF:ident: usize>
        $(where $($bounds:tt)*)?
        { $($tt:tt)* }
    ) => {
        $crate::sink_node! {
            $(#[$meta])*
            pub $name<$T, $BUF>
            $(where $($bounds)*)?
            { $($tt)* }
        }
    };
}

/// Adding parameters to an existing node
#[macro_export]
macro_rules! with_parameters {
    (
        $node:expr,
        $($name:ident: $value:expr),* $(,)?
    ) => {
        {
            let mut node = $node;
            $(
                // Create ParameterId from string
                let param_id = match $crate::ParameterId::new(stringify!($name)) {
                    Ok(id) => id,
                    Err(e) => panic!("Invalid parameter name '{}': {:?}", stringify!($name), e),
                };
                // Convert value to ParamValue
                let param_value: $crate::ParamValue = $value.into();
                match node.set_parameter(&param_id, param_value) {
                    Ok(()) => {},
                    Err(e) => panic!("Failed to set parameter '{}': {:?}", stringify!($name), e),
                }
            )*
            node
        }
    };
}