void PlayAudioFromPercentage(float p) { XLSoundUtils.StopAllClips(); var samples = XLSoundUtils.GetSampleCount(source.clip); var playFrom = Mathf.FloorToInt(samples * p); XLSoundUtils.PlayClip(source.clip, playFrom, false); }
void SetupWaveformProperties() { areaWidth = EditorGUIUtility.currentViewWidth; waveRect.x = 20.0f; waveRect.xMax = areaWidth - waveRect.x; waveRect.yMax = 100; tex = new Texture2D((int)areaWidth, 100, TextureFormat.RGBA32, false); if (waveFormTex == null && source != null) { waveFormTex = XLSoundUtils.PaintWaveformSpectrum(source.clip, (int)areaWidth, 100, Color.green); } }
public void OnEnable() { RefreshProperties(); voImages = new Dictionary <VOPositions, Texture>(); foreach (VOPositions p in Enum.GetValues(typeof(VOPositions))) { Texture texture = Resources.Load <Texture>($"vo/images/{p.ToString()}"); voImages.Add(p, texture); } // set initial frame nextTexture = voImages[VOPositions.SilentMB]; XLSoundUtils.StopAllClips(); }
async void ShowPreview(List <VORecorderFrame> list, bool playClip = true) { isPreviewing = true; Queue <VORecorderFrame> frames = GetVOQue(list); VORecorderFrame frame; if (playClip) { nextTexture = voImages[VOPositions.SilentMB]; await Task.Delay(250); } else { frame = frames.Dequeue(); nextTexture = voImages[frame.position]; } var playTime = DateTime.Now; bool didStartAudio = false; while (frames.Count > 0) { frame = frames.Dequeue(); if (!didStartAudio && playClip) { XLSoundUtils.PlayClip(source.clip); didStartAudio = true; } await Task.Delay(frame.span); nextTexture = frame.texture; Repaint(); } await Task.Delay(recorder.finalFrameDelay); isPreviewing = false; nextTexture = voImages[VOPositions.SilentMB]; }
void DrawWaveForm(Event e) { //Event e = Event.current; GUILayout.Space(10f); Graphics.CopyTexture(waveFormTex, tex); if (frames != null) { foreach (VORecorderFrame frame in frames) { var perc = (frame.frameTime * 0.001f) / source.clip.length; var thisLine = GetLineVector(perc); XLSoundUtils.DrawTimeMarkerLine(tex, new Vector2(thisLine.x, thisLine.y), new Vector2(thisLine.z, thisLine.w), Color.gray); } } if (lastLine != null) { XLSoundUtils.DrawTimeMarkerLine(tex, new Vector2(lastLine.x, lastLine.y), new Vector2(lastLine.z, lastLine.w), Color.red); } var centeredStyle = GUI.skin.GetStyle("Label"); centeredStyle.alignment = TextAnchor.MiddleCenter; GUILayout.Label(tex, centeredStyle); bool isOnBox = false; waveRect.y = GUILayoutUtility.GetLastRect().y; if (waveRect.Contains(Event.current.mousePosition)) { isOnBox = true; } else { isOnBox = false; } if (isOnBox && (e.type == EventType.MouseDrag || e.type == EventType.MouseUp)) { var point = e.mousePosition.x - waveRect.x; UpdateFrameTimePoint(point); if (e.type == EventType.MouseUp) { if (IsEditingFrame) { var list = frames.Where(x => x.frameTime >= editedFrame.frameTime).ToList(); ShowPreview(list, false); } PlayAudioFromPercentage(p); } else { XLSoundUtils.StopAllClips(); } Repaint(); //EditorGUILayout.LabelField("Condition:", $"{isOnBox.ToString()}, type: {e.type}"); } //dots = dots > 20 ? 0 : dots + 1; //var str = $"{isOnBox}"; //for (int i = 0; i < dots; i++) str += "."; //EditorGUILayout.LabelField("Condition:", $"{str}"); if (IsEditingFrame) { editedFrame.frameTime = EditorGUILayout.IntField("Time Stamp:", currentTimeStamp); editedFrame.position = (VOPositions)EditorGUILayout.EnumPopup("Primitive to create:", editedFrame.position); if (GUILayout.Button("Done")) { L.Log(LogEventType.BOOL, $"finished editing frame"); SavePrefab(); editFrameToken.Cancel(); } if (GUILayout.Button("Delete")) { bool confirm = EditorUtility.DisplayDialog( "Delete?", "Are you sure you want to remove this animation position?", "Yes", "No"); if (confirm) { editFrameToken.Cancel(); frames.Remove(editedFrame); } } } else { EditorGUILayout.FloatField("Time Stamp:", currentTimeStamp); if (GUILayout.Button("Add New")) { int lastFrame = currentTimeStamp; if (currentTimeStamp <= 0) { lastFrame = frames[frames.Count - 1].frameTime + 10; var p = (lastFrame * 0.001f) / source.clip.length; UpdateTimeStampsAndLine(p); } L.Log(LogEventType.BOOL, $"add new frame. lastFrame: {lastFrame}"); editedFrame = new VORecorderFrame { frameTime = lastFrame }; frames.Add(editedFrame); editFrameToken = new CancellationTokenSource(); } } GUILayout.Space(10f); }