Beispiel #1
0
        public static Increments FromJSON(JSONObject j)
        {
            var o = Increments.Prototype();

            try
            {
                j.Assign("hz", ref o.hz);
                j.Assign("base_hz", ref o.base_hz);
                j.Assign("tuned_hz", ref o.tuned_hz);
                j.Assign("fixedFreq", ref o.fixedFreq);

                j.Assign("mult", ref o.mult);
                j.Assign("coarse", ref o.coarse);
                j.Assign("fine", ref o.fine);

                o.Detune = j.GetItem("detune", o.Detune); //Set up real detune values using the setter
                j.Assign("detune_randomness", ref o.detune_randomness);
                j.Assign("increment_offset", ref o.increment_offset);

                o.Recalc();
            } catch (Exception e) {
                System.Diagnostics.Debug.Assert(false, "PG Copy failed:  " + e.Message);
            }

            return(o);
        }
Beispiel #2
0
        public bool FromJSON(JSONObject j)
        {
            try
            {
                if (j.HasItem("intent")) //Probably clipboard data or data from UI.  Check for matching intent.  If not the same, fail operation.
                {
                    var expectedIntent = (RTableIntent)j.GetItem("intent", -1);
                    if (intent != expectedIntent)
                    {
                        throw new Exception("Intent does not match!");
                    }
                }

                j.Assign("floor", ref floor);
                j.Assign("ceiling", ref ceiling);

                if (j.HasItem("tbl"))
                {
                    try
                    {                       //Call the appropriate override for ValuesFromBase64() for the given intent.
                        values = ValuesFromBase64(j.GetItem("tbl", ""));
                    } catch (Exception e) { //Catch any exceptions that ValuesFromBase64() might've thrown trying to parse the table.
                        #if DEBUG
                        System.Diagnostics.Debug.Fail(String.Format("{1}: Value table copy failed: {0}", e.Message, GetType().Name));
                        System.Diagnostics.Debugger.Break();
                        throw e;
                        #endif
                        //FIXME:  Consider printing some shit to output in release mode, otherwise this func will just return false.
                    }
                }
            } catch (Exception e) {
                System.Diagnostics.Debug.Fail(String.Format("{1} copy failed: {0}", e.Message, GetType().Name)); //DEBUG, REMOVE ME?

                return(false);
            }

            return(true);
        }
Beispiel #3
0
        // public bool FromString

        public void FromJSON(JSONObject data, bool fabricateGrid = false, bool reinit = false)
        {
            try
            {
                opCount = (byte)data.GetItem("opCount", opCount);
                Reset(reinit);

                var c = data.GetItem <byte>("connections", null);
                if (c != null)
                {
                    connections = c;           //If no connections are specified then default to behavior specified by the reinit arg
                }
                //Check if the wiring grid exists.  If the grid doesn't exist, fabricate one.
                if (!data.HasItem("grid"))
                {
                    wiringGrid = FabricateGrid();
                }
                else
                {
                    wiringGrid = data.GetItem <byte>("grid", Algorithm.DefaultWiringGrid(opCount));
                }

                processOrder = data.GetItem <byte>("processOrder", Algorithm.DefaultProcessOrder(opCount));

                if (data.HasItem("intent"))
                {
                    string[] new_intents = data.GetItem("intent", new string[opCount]);
                    for (int i = 0; i < opCount; i++)
                    {
                        intent[i] = (OpBase.Intents)Enum.Parse(typeof(OpBase.Intents), new_intents[i]);
                    }
                }
                else
                {
                    //No intents?  Reset all intents to default.  The only reason to omit intents now is to save space for traditional algorithms.
                    for (int i = 0; i < opCount; i++)
                    {
                        intent[i] = OpBase.Intents.FM_OP;
                    }
                }

                compatiblePreset = (sbyte)data.GetItem("compatiblePreset", -1);
                // j.Assign("increment_offset", ref o.increment_offset);
            } catch (Exception e) {
                System.Diagnostics.Debug.Fail("Algorithm.FromJSON failed:  " + e.Message);
            }
        }