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); }
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); }
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); }
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); } }
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); }
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); }
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); }
/// <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"); } }
/// <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"); } }
/// <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); }
/// <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"); }
/// <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"); } }
/// <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"); }
/// <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"); }
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); }
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); }
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); }
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); }
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); }
/// <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); }
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); }
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); }
/// <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); }
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); }
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); }
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); }
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); }
/// <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"); }
/// <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"); }
/// <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"); }