1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#[macro_export]
macro_rules! make_message_handler(
    (
        $(
            $node:ident: $handler:ident
         ),+
    ) => (
        fn message_specific(&mut self, msg: ::node::AudioNodeMessage, sample_rate: f32) {
            match msg {
                $(::node::AudioNodeMessage::$node(m) => self.$handler(m, sample_rate)),+,
                _ => (),
            }
        }
    );
);

#[macro_export]
macro_rules! make_state_change(
    ($fn_name:ident, $state:ident, $render_msg:ident) => (
        pub fn $fn_name(&self) -> StateChangeResult {
            self.state.set(ProcessingState::$state);
            let (tx, rx) = mpsc::channel();
            let _ = self.sender.send(AudioRenderThreadMsg::$render_msg(tx));
            rx.recv().unwrap()
        }
    );
);

#[macro_export]
macro_rules! make_render_thread_state_change(
    ($fn_name:ident, $state:ident, $sink_method:ident) => (
        fn $fn_name(&mut self) -> StateChangeResult {
            if self.state == ProcessingState::$state {
                return Ok(());
            }
            self.state = ProcessingState::$state;
            self.sink.$sink_method().map_err(|_| ())
        }
    );
);