Exemplo n.º 1
0
    public void Toggle_Enable()
    {
        if (Repeated || dragging)
        {
            return;
        }

        Update_Volume(1);
        Enabled       = !Enabled;
        image.enabled = Enabled;
        Toggling?.Invoke(this, null);
        Rhythm_Player.Singleton.Reset_Events();

        List <Sound_Data.Instance> instances = Rhythm_Player.Singleton.Rhythms[0].Sounds_Data.Find(a => a.Type == sound.Sound_Type).Instances;

        if (!Enabled)
        {
            instances.Remove(Instance);
            Instance = null;
        }
        else if (!instances.Exists(a => a == Instance))
        {
            Instance = new Sound_Data.Instance()
            {
                Fire_Time = fire_time, Volume = volume, Note = note
            };
            instances.Add(Instance);
        }
    }
Exemplo n.º 2
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);
    }