Exemple #1
0
        public static byte[] encode_node_u(MMap mm, INode node)
        {
            var stream = new MemoryStream();
            var bw     = new BinaryWriter(stream);
            var nu     = ((NodeU)node);
            var len1   = nu.inputs.l.Count;
            var len2   = nu.outputs.Count;

            bw.Write(Osc.str_pstr(nu.name));
            bw.Write(Osc.encode_i8((int)nu.rate));
            bw.Write(Osc.encode_i16(len1));
            bw.Write(Osc.encode_i16(len2));
            for (var ind = 0; ind < len1; ind = ind + 1)
            {
                bw.Write(encode_input(mk_input(mm, nu.inputs.l[ind])));
            }
            for (var ind = 0; ind < len2; ind = ind + 1)
            {
                bw.Write(Osc.encode_i8((int)nu.outputs[ind]));
            }
            return(stream.ToArray());
        }
Exemple #2
0
        public static byte[] encode_graphdef(String name, Graph graph)
        {
            var stream = new MemoryStream();
            var bw     = new BinaryWriter(stream);
            var mm     = mk_map(graph);

            bw.Write(Osc.encode_str("SCgf"));
            bw.Write(Osc.encode_i32(0));
            bw.Write(Osc.encode_i32(1));
            bw.Write(Osc.str_pstr(name));
            bw.Write(Osc.encode_i16(graph.constants.Count));
            var l1 = graph.constants.Select(x => node_c_value(x));

            foreach (var elem in l1)
            {
                bw.Write(Osc.encode_f32(elem));
            }
            bw.Write(Osc.encode_i16(graph.controls.Count));
            var l2 = graph.controls.Select(x => node_k_default(x));

            foreach (var elem in l2)
            {
                bw.Write(Osc.encode_f32(elem));
            }
            bw.Write(Osc.encode_i16(graph.controls.Count));
            foreach (var elem in graph.controls)
            {
                bw.Write(encode_node_k(mm, elem));
            }
            bw.Write(Osc.encode_i16(graph.ugens.Count));

            foreach (var elem in graph.ugens)
            {
                bw.Write(encode_node_u(mm, elem));
            }

            return(stream.ToArray());
        }