示例#1
0
    /// <summary>
    /// Parses JSON data to a Sound_Data class instance.
    /// </summary>
    Sound_Data Parse_Sound(Sound_Data.Sound_Type sound_type, string raw_sound_data)
    {
        SimpleJSON.JSONNode raw       = SimpleJSON.JSON.Parse(raw_sound_data);
        Sound_Data          new_sound = new Sound_Data {
            Type = sound_type
        };

        // Add Sound instances
        foreach (SimpleJSON.JSONNode element in raw[sound_type.ToString()][0])
        {
            string[] tokens = Utils.Split(element, '*');
            string   notes  = "";

            if (tokens.Length >= 3)
            {
                notes = tokens[2];
            }

            Sound_Data.Instance instance = new Sound_Data.Instance
            {
                Fire_Time = float.Parse(tokens[0], CultureInfo.InvariantCulture),
                Volume    = float.Parse(tokens[1], CultureInfo.InvariantCulture),
                Note      = notes
            };

            if (!new_sound.Instances.Exists(a => a.Fire_Time == instance.Fire_Time))
            {
                new_sound.Instances.Add(instance);
            }
        }

        // Add Loop instances
        foreach (SimpleJSON.JSONNode element in raw[sound_type.ToString()][1])
        {
            string[] tokens = Utils.Split(element, '*');

            Sound_Data.Loop loop = new Sound_Data.Loop
            {
                Start_Time  = float.Parse(tokens[0], CultureInfo.InvariantCulture),
                End_Time    = float.Parse(tokens[1], CultureInfo.InvariantCulture),
                Repetitions = uint.Parse(tokens[2])
            };

            if (!new_sound.Loops.Exists(a => a.Start_Time == loop.Start_Time || a.End_Time == loop.End_Time))
            {
                new_sound.Loops.Add(loop);
            }
        }

        return(new_sound);
    }
示例#2
0
    public string Get_Sounds_Json()
    {
        string result = "{";

        foreach (Sound_Data.Sound_Type sound_type in (Sound_Data.Sound_Type[])Enum.GetValues(typeof(Sound_Data.Sound_Type)))
        {
            if (sound_type == Sound_Data.Sound_Type.None)
            {
                continue;
            }

            Sound_Data sound = Sounds_Data.Find(a => a.Type == sound_type);
            result += "\"" + sound_type.ToString() + "\":[[";

            foreach (Sound_Data.Instance instance in sound.Instances)
            {
                result += "\"" + Utils.ToString(instance.Fire_Time) + "*" + Utils.ToString(instance.Volume) + "*" + instance.Note + "\",";
            }

            if (sound.Instances.Count > 0)
            {
                result = result.Substring(0, result.Length - 1);
            }

            result += "],[";

            foreach (Sound_Data.Loop loop in sound.Loops)
            {
                result += "\"" + Utils.ToString(loop.Start_Time) + "*" + Utils.ToString(loop.End_Time) + "*" + loop.Repetitions + "\",";
            }

            if (sound.Loops.Count > 0)
            {
                result = result.Substring(0, result.Length - 1);
            }

            result += "]],";
        }

        return(result.Substring(0, result.Length - 1) + "}");
    }
示例#3
0
    void Handle_Data_Response(string response, Handler_Type type)
    {
        string data = Utils.Split(response, '~')[1];

        foreach (string rhythm in Utils.Split(data, "%"))
        {
            Rhythm_Data new_rhythm  = new Rhythm_Data();
            string[]    rhythm_data = Utils.Split(rhythm, '#');

            new_rhythm.Id             = uint.Parse(rhythm_data[0]);
            new_rhythm.Name           = rhythm_data[1];
            new_rhythm.Description    = rhythm_data[2];
            new_rhythm.PPM            = uint.Parse(rhythm_data[3]);
            new_rhythm.Time_Signature = (Rhythm_Data.Time_Signature_Type)Enum.Parse(typeof(Rhythm_Data.Time_Signature_Type), rhythm_data[4]);
            new_rhythm.Creation       = Utils.Get_DateTime(rhythm_data[5]);
            new_rhythm.Last_Update    = Utils.Get_DateTime(rhythm_data[6]);
            new_rhythm.Author_id      = uint.Parse(rhythm_data[7]);

            foreach (Sound_Data.Sound_Type sound_type in (Sound_Data.Sound_Type[])Enum.GetValues(typeof(Sound_Data.Sound_Type)))
            {
                if (sound_type == Sound_Data.Sound_Type.None)
                {
                    continue;
                }

                Sound_Data new_sound = Parse_Sound(sound_type, rhythm_data[8]);
                new_rhythm.Sounds_Data.Add(new_sound);

                if (!Sound_Type_Mono.Sounds.Exists(a => a.Sound_Type == new_sound.Type))
                {
                    continue;
                }

                Sound_Type_Mono sound_mono = Sound_Type_Mono.Sounds.Find(a => a.Sound_Type == new_sound.Type);

                foreach (Sound_Data.Instance instance in new_sound.Instances)
                {
                    sound_mono.Instances[instance.Fire_Time].Set_Enabled(true);
                    sound_mono.Instances[instance.Fire_Time].Instance = instance;
                }

                foreach (Sound_Data.Loop loop in new_sound.Loops)
                {
                    int sibling_index = sound_mono.Instances[loop.Start_Time].transform.GetSiblingIndex();

                    Rhythm_Loop rhythm_loop = Instantiate(loop_prefab, sound_mono.transform).GetComponent <Rhythm_Loop>();
                    rhythm_loop.Data  = loop;
                    rhythm_loop.Sound = sound_mono;
                    rhythm_loop.Sound.Loops.Add(rhythm_loop);
                    rhythm_loop.Update_Core();
                    rhythm_loop.Update_Periphery();
                }
            }

            Rhythms.Add(new_rhythm);
        }

        rhythm_title.text = Rhythms[0].Name.ToString();
        PPM = Rhythms[0].PPM;
        rhythm_speed.text    = PPM.ToString();
        rhythm_length.text   = Song_Length.ToString();
        time_signature.value = (int)Rhythms[0].Time_Signature;
        time_signature.onValueChanged.AddListener((int value) =>
        {
            Rhythms[0].Time_Signature = (Rhythm_Data.Time_Signature_Type)value;
            Update_Separators();
        });

        Update_Numerators();
        Update_Separators();

        Reset_Events();
        Utils.Update_UI = true;
    }