示例#1
0
 public bool ReadCallback(float[] data)
 {
     currentDataIndex = 0;
     while (currentDataIndex < data.Length)
     {
         if (bufferedLength > 0)
         {
             int length = Math.Min(data.Length - currentDataIndex, bufferedLength);
             Array.Copy(dataBuffer, 0, data, currentDataIndex, length);
             currentDataIndex += length;
             bufferedLength   -= length;
             if (bufferedLength > 0)
             {
                 Array.Copy(dataBuffer, length, dataBuffer, 0, bufferedLength);
             }
         }
         else
         {
             EliasWrapper.elias_result_codes r = EliasWrapper.elias_read_samples(elias.Handle, Marshal.UnsafeAddrOfPinnedArrayElement(dataBuffer, 0));
             bufferedLength = elias.FramesPerBuffer * elias.ChannelCount;
             EliasHelper.LogResult(r, "Failed to render");
             if (r != EliasWrapper.elias_result_codes.elias_result_success)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#2
0
    public int GetStingerIndex(string themeName, string stingerName)
    {
        if (Handle == IntPtr.Zero)
        {
            return(0);
        }

        int  stingerIndex;
        uint tmp;

        if (IsValidName(stingerName))
        {
            if (themeName == "")
            {
                themeName = GetActiveTheme();
            }
            EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_track_index(Handle, themeName, stingerName, out tmp);
            stingerIndex = (int)tmp;
            LogResult(r, "Failed to get stinger index");
        }
        else
        {
            stingerIndex = -1;
        }
        return(stingerIndex);
    }
示例#3
0
    public void DerserializeString(string meproContent)
    {
        var bytes = System.Text.Encoding.UTF8.GetBytes(meproContent);

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_deserialize(Handle, bytes, (uint)bytes.Length + 1, 0);
        LogResult(r, meproContent);
    }
示例#4
0
 public static void LogResult(EliasWrapper.elias_result_codes result, string errorMessage = "")
 {
     if (result != EliasWrapper.elias_result_codes.elias_result_success)
     {
         Debug.LogError(result + "\n" + errorMessage);
     }
 }
示例#5
0
    public EliasBasicInfo GetBasicInfo(string theme)
    {
        EliasBasicInfo info;

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_theme_basic_info(Handle, theme, out info.initial_bpm, out info.initial_timesig_numerator, out info.initial_timesig_denominator, out info.bars);
        LogResult(r, theme);
        return(info);
    }
示例#6
0
    public uint GetBusIndex(string busName)
    {
        uint busIndex;

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_bus_index(Handle, busName, out busIndex);
        LogResult(r, "Failed to get bus index for " + busName);
        return(busIndex);
    }
示例#7
0
    public uint GetThemeIndex(string themeName)
    {
        uint themeIndex;

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_theme_index(Handle, themeName, out themeIndex);
        LogResult(r, themeName);
        return(themeIndex);
    }
示例#8
0
 /// <summary>
 /// Run an action preset.
 /// </summary>
 public void RunActionPreset(string preset, bool ignoreRequiredThemeMissmatch = false)
 {
     EliasWrapper.elias_result_codes r = EliasWrapper.elias_run_action_preset(elias.Handle, preset);
     if (ignoreRequiredThemeMissmatch == false || r != EliasWrapper.elias_result_codes.elias_error_requiredthememismatch)
     {
         EliasHelper.LogResult(r, "Problems running an action preset");
     }
 }
示例#9
0
 /// <summary>
 /// Stop the rendering of the theme. This function must not be called while any other Elias calls are in progress with the same handle in another thread.
 /// The exception is if the engine has its own background threads; these will automatically be shut down.
 /// IMPORTANT: This function must never use thread unsafe calls, as it can be called from either the audio thread in case of failure to render, or the main thread, (game).
 /// </summary>
 public void Stop()
 {
     isEliasStarted = false;
     if (elias != null)
     {
         EliasWrapper.elias_result_codes r = EliasWrapper.elias_stop(elias.Handle);
         EliasHelper.LogResult(r, "Problems stopping");
     }
 }
示例#10
0
    /// <summary>
    /// Get the current theme.
    /// </summary>
    public string GetActiveTheme()
    {
        uint   id = (uint)EliasWrapper.elias_get_active_theme_index(Handle, new double[0]);
        string name;

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_theme_name_wrapped(Handle, id, out name);
        EliasHelper.LogResult(r, "Failed to get active theme");
        return(name);
    }
示例#11
0
    /// <summary>
    /// Lock and unlock the mixer in order to allow many changes to be made without the risk of running one or more buffers ahead in between your changes.
    /// Note that multiple calls to elias_lock_mixer may be made in succession, as long as the same number of calls to elias_unlock_mixer are made (a recursive mutex, in other words).
    /// If you forget to unlock the mixer, the music will stop and you will get deadlocks.
    /// </summary>
    public void LockMixer()
    {
        if (elias.Handle == IntPtr.Zero)
        {
            return;
        }

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_lock_mixer(elias.Handle);
        EliasHelper.LogResult(r, "Problems locking the mixer");
    }
示例#12
0
 /// <summary>
 /// Stop the rendering of the theme. This function must not be called while any other Elias calls are in progress with the same handle in another thread.
 /// The exception is if the engine has its own background threads; these will automatically be shut down.
 /// IMPORTANT: This function must never use thread unsafe calls, as it can be called from either the audio thread in case of failure to render, or the main thread, (game).
 /// </summary>
 public void Stop()
 {
     shouldStop     = false;
     isEliasStarted = false;
     if (elias.Handle != IntPtr.Zero)
     {
         EliasWrapper.elias_result_codes r = EliasWrapper.elias_stop(elias.Handle);
         EliasHelper.LogResult(r, "Problems stopping");
     }
 }
示例#13
0
    /// <summary>
    /// Queue an elias_event.
    /// </summary>
    public void QueueEvent(elias_event @event)
    {
        if (elias.Handle == IntPtr.Zero)
        {
            return;
        }

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_queue_event_wrapped(elias.Handle, @event);
        EliasHelper.LogResult(r, "Problems queing an event");
    }
示例#14
0
    /// <summary>
    /// Clear all queued events.
    /// </summary>
    public void ClearEvents()
    {
        if (elias.Handle == IntPtr.Zero)
        {
            return;
        }

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_clear_events(elias.Handle);
        EliasHelper.LogResult(r, "Problems clearing events");
    }
示例#15
0
    public uint GetTransitionPresetIndex(string transitionPresetName)
    {
        uint transitionPresetIndex;

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_transition_preset_index(Handle, transitionPresetName, out transitionPresetIndex);
        LogResult(r, "Failed to get transition preset index for " + transitionPresetName);
        if (r != EliasWrapper.elias_result_codes.elias_result_success)
        {
            transitionPresetIndex = 0;
        }
        return(transitionPresetIndex);
    }
示例#16
0
    public uint GetTrackIndex(string themeName, string trackName)
    {
        if (Handle == IntPtr.Zero)
        {
            return(0);
        }

        uint trackIndex;

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_track_index(Handle, themeName, trackName, out trackIndex);
        LogResult(r, trackName);
        return(trackIndex);
    }
示例#17
0
    public IList <string> GetTransitionPresets()
    {
        List <string> presets = new List <string>();

        for (uint i = 0; i < EliasWrapper.elias_get_transition_preset_count(Handle); i++)
        {
            string name;
            EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_transition_preset_name_wrapped(Handle, i, out name);
            LogResult(r, i.ToString());
            presets.Add(name);
        }
        return(presets);
    }
示例#18
0
    public IList <string> GetTracksGroups()
    {
        List <string> tracks = new List <string>();

        for (uint i = 0; i < EliasWrapper.elias_get_track_group_count(Handle); i++)
        {
            string name;
            EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_track_group_name_wrapped(Handle, i, out name);
            LogResult(r, name + " " + i);
            tracks.Add(name);
        }
        return(tracks);
    }
示例#19
0
    public IList <string> GetThemes()
    {
        List <string> themes = new List <string>();

        for (uint i = 0; i < EliasWrapper.elias_get_theme_count(Handle); i++)
        {
            string name;
            EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_theme_name_wrapped(Handle, i, out name);
            LogResult(r, i.ToString());
            themes.Add(name);
        }
        return(themes);
    }
示例#20
0
    /// <summary>
    /// Get the current theme.
    /// </summary>
    public string GetActiveTheme()
    {
        if (Handle == IntPtr.Zero)
        {
            return("");
        }

        uint   id = (uint)EliasWrapper.elias_get_active_theme_index(Handle, null);
        string name;

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_theme_name_wrapped(Handle, id, out name);
        EliasHelper.LogResult(r, "Failed to get active theme");
        return(name);
    }
示例#21
0
    private bool StartWithActionPreset()
    {
        bool   success;
        string name;

        EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_action_preset_name_wrapped(elias.Handle, (uint)actionPreset, out name);
        EliasHelper.LogResult(r, "Problems getting an action preset name");
        string theme;

        r = EliasWrapper.elias_get_action_preset_required_initial_theme_wrapped(elias.Handle, name, out theme);
        EliasHelper.LogResult(r, "Problems with getting the required initial theme for an action preset");
        success = StartWithActionPreset(name);
        return(success);
    }
示例#22
0
    private void Deserialize(string file)
    {
        // TODO: CAREFUL here, for safety reasons you shouldn't let this while loop unattended,
        //		place a timer and error check or find a different better way of waiting for the file to be done reading!
#if UNITY_ANDROID && !UNITY_EDITOR
        WWW themeDataWWW = new WWW(file);
        while (!themeDataWWW.isDone)
        {
        }
        byte[] mepro = themeDataWWW.bytes;
#else
        byte[] mepro = File.ReadAllBytes(file);
#endif
        EliasWrapper.elias_result_codes r = EliasWrapper.elias_deserialize(Handle, mepro, (uint)mepro.Length + 1, 0);
        LogResult(r, file);
    }
示例#23
0
    /// <summary>
    /// Start ELIAS with a elias_event_set_level event. This function must not be called from more than one thread at the same time.
    /// </summary>
    public bool StartTheme(elias_event_set_level setLevel)
    {
        if (elias.Handle == IntPtr.Zero)
        {
            return(false);
        }

        if (AudioSettings.outputSampleRate == 0)
        {
            Debug.LogError("Unity's AudioSettings.outputSampleRate is reporting 0, so the Elias Plugin is unable to determine what sample rate would be correct to use! " +
                           "This may cause the speed of the audio to play at the wrong rate. Please set a sample rate for Unity in the Project settings.");
        }
        EliasWrapper.elias_result_codes r = EliasWrapper.elias_start_background_wrapped(elias.Handle, setLevel, AudioSettings.outputSampleRate != 0 ? (uint)AudioSettings.outputSampleRate : (uint)eliasSampleRate, (uint)eliasFramesPerBuffer);
        EliasHelper.LogResult(r, setLevel.ToString());
        return(r == EliasWrapper.elias_result_codes.elias_result_success);
    }
示例#24
0
    public int GetGroupIndex(string trackGroupName)
    {
        uint tmp;
        int  affectedTracksGroupIndex;

        if (IsValidName(trackGroupName))
        {
            EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_track_group_index(Handle, trackGroupName, out tmp);
            affectedTracksGroupIndex = (int)tmp;
            LogResult(r, trackGroupName);
        }
        else
        {
            affectedTracksGroupIndex = -1;
        }
        return(affectedTracksGroupIndex);
    }
示例#25
0
    public IList <string> GetActionPresets()
    {
        if (Handle == IntPtr.Zero)
        {
            return(new List <string>());
        }

        string        name;
        List <string> presets = new List <string>();

        for (uint i = 0; i < EliasWrapper.elias_get_action_preset_count(Handle); i++)
        {
            EliasWrapper.elias_result_codes result = EliasWrapper.elias_get_action_preset_name_wrapped(Handle, i, out name);
            LogResult(result, i.ToString());
            presets.Add(name);
        }
        return(presets);
    }
示例#26
0
    public IList <string> GetTracks(string theme)
    {
        if (Handle == IntPtr.Zero)
        {
            return(new List <string>());
        }

        List <string> tracks = new List <string>();

        for (uint i = 0; i < EliasWrapper.elias_get_track_count(Handle, theme); i++)
        {
            string name;
            EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_track_name_wrapped(Handle, theme, i, out name);
            LogResult(r, theme);
            tracks.Add(name);
        }
        return(tracks);
    }
示例#27
0
    public IList <string> GetStingers(string theme)
    {
        List <string> tracks = new List <string>();

        for (uint i = 0; i < EliasWrapper.elias_get_track_count(Handle, theme); i++)
        {
            string name;
            EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_track_name_wrapped(Handle, theme, i, out name);
            LogResult(r, theme);
            uint type;
            r = EliasWrapper.elias_get_track_type(Handle, theme, name, out type);
            LogResult(r, theme);
            if (type == (int)elias_track_types.elias_track_audio_stinger)
            {
                tracks.Add(name);
            }
        }
        return(tracks);
    }
示例#28
0
 /// <summary>
 /// Clear all queued events.
 /// </summary>
 public void ClearEvents()
 {
     EliasWrapper.elias_result_codes r = EliasWrapper.elias_clear_events(elias.Handle);
     EliasHelper.LogResult(r, "Problems clearing events");
 }
示例#29
0
 /// <summary>
 /// Queue an elias_event.
 /// </summary>
 public void QueueEvent(elias_event @event)
 {
     EliasWrapper.elias_result_codes r = EliasWrapper.elias_queue_event_wrapped(elias.Handle, @event);
     EliasHelper.LogResult(r, "Problems queing an event");
 }
示例#30
0
 /// <summary>
 /// Lock and unlock the mixer in order to allow many changes to be made without the risk of running one or more buffers ahead in between your changes.
 /// Note that multiple calls to elias_lock_mixer may be made in succession, as long as the same number of calls to elias_unlock_mixer are made (a recursive mutex, in other words).
 /// If you forget to unlock the mixer, the music will stop and you will get deadlocks.
 /// </summary>
 public void UnlockMixer()
 {
     EliasWrapper.elias_result_codes r = EliasWrapper.elias_unlock_mixer(elias.Handle);
     EliasHelper.LogResult(r, "Problems unlocking the mixer");
 }