Beispiel #1
0
 public static Tuple <INode, Graph> mk_node_u(IUgen ugen, Graph gr)
 {
     if (ugen is Primitive pr1)
     {
         var ng      = acc(pr1.inputs.l, new List <INode>(), gr);
         var gnew    = ng.Item2;
         var ng1     = ng.Item1;
         var inputs2 = new UgenL();
         foreach (var nd in ng1)
         {
             inputs2.l.Add(as_from_port(nd));
         }
         var rate  = pr1.rate;
         var name  = pr1.name;
         var index = pr1.index;
         foreach (var nd2 in gnew.ugens)
         {
             if (find_u_p(rate, name, index, nd2))
             {
                 return(new Tuple <INode, Graph>(nd2, gnew));
             }
         }
         var pr = new Primitive {
             name = name, inputs = inputs2, outputs = pr1.outputs, special = pr1.special, rate = rate
         };
         return(push_u(pr, gnew));
     }
     throw new Exception("mk_node_u");
 }
Beispiel #2
0
        public static IUgen mk_unary_operator(int sp, Func <double, double> fun, object op)
        {
            if (op is Constant <int> ci)
            {
                var val = fun((double)ci.value);
                return(new Constant <double> {
                    value = val
                });
            }
            if (op is Constant <double> cd)
            {
                var val = fun(cd.value);
                return(new Constant <double> {
                    value = val
                });
            }
            var ops = new UgenL {
            };

            if (op is int opi)
            {
                ops.l.Add(new Constant <int> {
                    value = opi
                });
            }
            if (op is double opd)
            {
                ops.l.Add(new Constant <double> {
                    value = opd
                });
            }
            return(mk_operator("UnaryOpUGen", ops, sp));
        }
Beispiel #3
0
        public static IUgen mk_ugen(string name, UgenL inputs, RateList outputs,
                                    int ind = 0, int sp = 0, Rate rate = Rate.RateKr)
        {
            var pr1 = new Primitive {
                name = name, inputs = inputs, outputs = outputs, index = ind, special = sp, rate = rate
            };

            return(proxify(mce_expand(pr1)));
        }
Beispiel #4
0
        public static void printUgens(UgenL ugenl)
        {
            var ugens = ugenl.l;

            foreach (var ugen in ugens)
            {
                Console.Write(" - ");
                printUgen(ugen);
            }
        }
Beispiel #5
0
        public static IUgen mk_oscillator(Rate rate, string name, UgenL inputs, IUgen ugen, int ou)
        {
            var rl = new RateList {
            };

            for (var ind = 0; ind < ou; ind++)
            {
                rl.Add(rate);
            }
            return(mk_ugen(name, inputs, rl, 0, 0, rate));
        }
Beispiel #6
0
        public static IUgen mce_expand(IUgen ugen)
        {
            if (ugen is Mce)
            {
                var lst   = new List <IUgen>();
                var ugens = ((Mce)(object)ugen).ugens.l;
                foreach (var elem in ugens)
                {
                    lst.Add(mce_expand(elem));
                }
                var outv = new UgenL();
                outv.l = lst;
                return(new Mce {
                    ugens = outv
                });
            }
            else if (ugen is Mrg)
            {
                var left  = ((Mrg)(object)ugen).left;
                var right = ((Mrg)(object)ugen).right;
                var ug1   = mce_expand(left);
                return(new Mrg {
                    left = ug1, right = right
                });
            }
            else
            {
                bool rec <V>(V ug)
                {
                    if (ugen is Primitive)
                    {
                        var inputs = ((Primitive)(object)ug).inputs;
                        var ins    = inputs.l.Where(is_mce);
                        return(ins.ToList().Count > 0);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (rec(ugen))
                {
                    return(mce_expand(mce_transform(ugen)));
                }
                else
                {
                    return(ugen);
                }
            }
        }
Beispiel #7
0
        public static IUgen mk_osc_id(Rate rate, string name, UgenL inputs, IUgen ugen, int ou)
        {
            var rl = new RateList {
            };

            for (var ind = 0; ind < ou; ind++)
            {
                rl.Add(rate);
            }
            var inps = new UgenL {
            };

            inps.l.AddRange(mce_channels(ugen).l);
            return(mk_ugen(name, inps, rl, UID.nextUID(), 0, rate));
        }
Beispiel #8
0
 public static Mce mce_transform(IUgen ugen)
 {
     if (ugen is Primitive prim)
     {
         var inputs = prim.inputs;
         var ins    = inputs.l.Where(x => is_mce(x));
         var degs   = new List <int>();
         foreach (var elem in ins)
         {
             degs.Add(mce_degree(elem));
         }
         var upr = max_num(degs, 0);
         var ext = new List <List <IUgen> >();
         foreach (var elem in inputs.l)
         {
             ext.Add(mce_extend(upr, elem));
         }
         var iet  = transposer <IUgen>(ext);
         var outv = new List <IUgen>();
         //var outv = new UgenL();
         foreach (var elem2 in iet)
         {
             var newInps = new UgenL();
             newInps.l = elem2;
             var p = new Primitive
             {
                 name    = prim.name,
                 inputs  = newInps,
                 outputs = prim.outputs,
                 rate    = prim.rate,
                 special = prim.special,
                 index   = prim.index
             };
             //outv.l.Add(p);
             outv.Add(p);
         }
         var newOut = new UgenL();
         newOut.l = outv;
         //return new Mce(ugens: outv);
         return(new Mce {
             ugens = newOut
         });
     }
     else
     {
         throw new Exception("Error: mce_transform");
     }
 }
Beispiel #9
0
        public static IUgen mk_operator(string name, UgenL inputs, int sp)
        {
            var rates = new RateList {
            };

            foreach (var elem in inputs.l)
            {
                rates.Add(rate_of(elem));
            }
            var maxrate = max_rate(rates, Rate.RateIr);
            var outs    = new RateList {
                maxrate
            };

            return(mk_ugen(name, inputs, outs, 0, sp, maxrate));
        }
Beispiel #10
0
 public static IUgen proxify(IUgen ugen)
 {
     if (ugen is Mce mc)
     {
         var lst = new UgenL();
         foreach (var elem in mc.ugens.l)
         {
             lst.l.Add(proxify(elem));
         }
         return(new Mce {
             ugens = lst
         });
     }
     else if (ugen is Mrg)
     {
         var prx = proxify(((Mrg)ugen).left);
         return(new Mrg {
             left = prx, right = ((Mrg)ugen).right
         });
     }
     else if (ugen is Primitive)
     {
         var ln = ((Primitive)ugen).outputs.Count;
         if (ln < 2)
         {
             return(ugen);
         }
         else
         {
             var lst1 = iota(ln, 0, 1);
             var lst2 = new UgenL();
             foreach (var ind in lst1)
             {
                 lst2.l.Add(proxify(new Proxy {
                     primitive = (Primitive)ugen, index = ind
                 }));
             }
             return(new Mce {
                 ugens = lst2
             });
         }
     }
     else
     {
         throw new Exception("proxify");
     }
 }
Beispiel #11
0
 public static IUgen mrg_n(UgenL lst)
 {
     if (lst.l.Count == 1)
     {
         return(lst.l[0]);
     }
     else if (lst.l.Count == 2)
     {
         return(new Mrg {
             left = lst.l[0], right = lst.l[1]
         });
     }
     else
     {
         var newLst = new UgenL();
         newLst.l.AddRange(lst.l.GetRange(1, lst.l.Count));
         return(new Mrg {
             left = lst.l[0], right = mrg_n(newLst)
         });
     }
 }
Beispiel #12
0
 public static UgenL mce_channels(IUgen ugen)
 {
     if (ugen is Mce mc)
     {
         var ugens = mc.ugens;
         return(ugens);
     }
     else if (ugen is Mrg mg)
     {
         var left  = mg.left;
         var right = mg.right;
         var lst   = mce_channels(left);
         var len   = lst.l.Count;
         if (len > 1)
         {
             var mrg1 = new Mrg {
                 left = lst.l[0], right = right
             };
             var outv = new List <IUgen> {
                 mrg1
             };
             outv.AddRange(lst.l.GetRange(1, len - 1));
             var newOut = new UgenL();
             newOut.l = outv;
             return(newOut);
         }
         else
         {
             throw new Exception("Error: mce_channels");
         }
     }
     else
     {
         var outv = new List <IUgen>();
         outv.Add(ugen);
         var newOut = new UgenL();
         newOut.l = outv;
         return(newOut);
     }
 }
Beispiel #13
0
        public void TestMethod1()
        {
            var c1 = new Constant <int> {
                value = 1
            };
            var c2 = new Constant <double> {
                value = 3.3
            };
            var k1 = new Control {
                name = "K1"
            };
            var p1 = new Primitive
            {
                name    = "P1",
                inputs  = new UgenL(c1, c2),
                rate    = Rate.RateKr,
                outputs = new RateList {
                    Rate.RateKr, Rate.RateIr
                }
            };
            var p2 = new Primitive {
                name = "P2", rate = Rate.RateAr
            };

            var mc1 = new Mce {
                ugens = new UgenL(p1, p1)
            };
            var mc2 = new Mce {
                ugens = new UgenL(p1, p2)
            };
            var mc3 = new Mce {
                ugens = new UgenL(p1, p2, mc1)
            };
            var p3 = new Primitive
            {
                name    = "P3",
                inputs  = new UgenL(mc1, mc3),
                rate    = Rate.RateKr,
                outputs = new RateList {
                    Rate.RateIr
                }
            };
            var il1 = new UgenL(c1, p2);
            var il2 = new UgenL(c1, p2, c1, p2, c1);
            var mg1 = new Mrg {
                left = p1, right = mc1
            };
            var mg2 = new Mrg {
                left = p2, right = p1
            };
            var mg3 = new Mrg {
                left = mc1, right = p2
            };
            //var ill1 = new List<List<int>>{new List<int>{1,2,3}, new List<int>{4, 5, 6}};
            var ill1 = new List <List <int> > {
                new List <int> {
                    1, 2, 3
                }, new List <int> {
                    4, 5, 6
                }
            };
            var ill2  = transposer <int>(ill1);
            var exmg1 = mce_extend(3, mg1);
            var mc10  = mce_transform(p3);
            var mc11  = mce_channels(mg3);

            var nc1 = new NodeC {
                nid = 10, value = 3
            };
            var nk1 = new NodeK {
                name = "nk1", nid = 11, deflt = 5
            };
            var fpc1 = new FromPortC {
                port_nid = 100
            };
            var fpk1 = new FromPortK {
                port_nid = 101
            };
            var fpku1 = new FromPortU {
                port_nid = 102, port_idx = 13
            };
            NodeC ndc1 = new NodeC {
                nid = 20, value = 320
            };
            NodeC ndc2 = new NodeC {
                nid = 21, value = 321
            };
            NodeK ndk1 = new NodeK {
                nid = 30, name = "ndk1"
            };
            NodeK ndk2 = new NodeK {
                nid = 31, name = "ndk2"
            };
            NodeU ndu1 = new NodeU
            {
                nid     = 40,
                name    = "ndu1",
                inputs  = new UgenL(mg1, mg2),
                outputs = new List <Rate> {
                    Rate.RateAr, Rate.RateKr, Rate.RateIr
                },
                ugenId = 2,
                rate   = Rate.RateAr
            };
            NodeU ndu2 = new NodeU
            {
                nid     = 41,
                name    = "ndu2",
                inputs  = new UgenL(),
                outputs = new List <Rate> {
                },
                ugenId  = 3,
                rate    = Rate.RateAr
            };
            Graph gr1 = new Graph
            {
                nextId    = 11,
                constants = new List <NodeC> {
                    ndc1, ndc2
                },
                controls = new List <NodeK> {
                    ndk1, ndk2
                },
                ugens = new List <NodeU> {
                    ndu1, ndu2
                }
            };
            var m1   = mk_map(gr1);
            var mcs1 = m1.cs;
            var n1   = mk_node_c(new Constant <int> {
                value = 320
            }, gr1);
            var nn  = (NodeC)n1.Item1;
            var ck1 = new Control {
                name = "ndk1", rate = Rate.RateKr, index = 3
            };
            var n2  = mk_node_k(ck1, gr1);
            var nn2 = (NodeK)n2.Item1;
            var n3  = mk_node(new Constant <int> {
                value = 320
            }, gr1);
            var nn3 = (NodeC)n3.Item1;
            var cs1 = new Constant <int> {
                value = 11
            };



            Assert.IsTrue(p1.name == "P1", "Primitive Name");
            Assert.IsTrue(p2.name == "P2", "Primitive Name 2");
            Assert.IsTrue(p1 is Primitive, "Primitive type");
            Assert.IsTrue(mc2 is Mce, "Mce type");
            Assert.IsTrue(mce_degree(mc1) == 2, "mce_degree");
            Assert.IsTrue(extend(il1.l, 7).Count == 7, "extend");
            Assert.IsTrue(mce_extend(3, mc1).Count == 3, "mce_extend");
            Assert.IsTrue(((Primitive)(object)(mce_extend(3, mc1)[2])).name == "P1", "mce_extend 2");
            Assert.IsTrue(((Primitive)(object)(mce_extend(3, mg2)[2])).name == "P2", "mce_extend 3");
            Assert.IsTrue(is_mce(mc1), "is_mce 1");
            Assert.IsFalse(is_mce(mg1), "is_mce 2");
            Assert.IsTrue(ill2.Count == 3, "transposer");
            Assert.IsTrue(exmg1.Count == 3, "mce_extend");
            Assert.IsTrue(mc10 is Mce, "mce_transform 1");
            Assert.IsTrue(((Primitive)(object)mc10.ugens.l[2]).name == "P3", "mce_transform 2");
            Assert.IsTrue(mc11.l.Count == 2, "mce_channels 1");
            Assert.IsTrue(mc11.l[0] is Mrg, "mce_channels 2");
            Assert.IsTrue(mc11.l[1] is Primitive, "mce_channels 3");
            Assert.IsTrue(node_c_value(nc1) == 3, "node_c_value");
            Assert.IsTrue(node_k_default(nk1) == 5, "node_k_default");
            Assert.IsTrue(m1.cs.SequenceEqual(new List <int> {
                20, 21
            }), "mmap cs");
            Assert.IsTrue(find_c_p(3, nc1), "find_c_p");
            Assert.IsTrue(find_k_p("ndk1", ndk1), "find_k_p");
            Assert.IsTrue(nn.nid == 20, "mk_node_c 1");
            Assert.IsTrue(nn2.nid == 30, "mk_node_c 2");
            Assert.IsTrue(nn3.nid == 20, "mk_node_c 3");
            Assert.IsTrue(fetch(31, mk_map(gr1).ks) == 1, "fetch");
        }