public void AudioState() { var ctx = new TestAudioContext(); AudioLayer layer = ctx.CreateLayer("test"); var pepsi = Engine.AssetLoader.Get <AudioAsset>("Sounds/pepsi.wav"); var money = Engine.AssetLoader.Get <AudioAsset>("Sounds/money.wav"); Assert.True(layer.Status == PlaybackStatus.NotPlaying); layer.PlayNext(pepsi); Assert.True(layer.Status == PlaybackStatus.Playing); layer.Stop(); Assert.True(layer.Status == PlaybackStatus.NotPlaying); layer.Pause(); Assert.True(layer.Status == PlaybackStatus.Paused); layer.PlayNext(money); Assert.True(layer.Status == PlaybackStatus.Paused); layer.Resume(); Assert.True(layer.Status == PlaybackStatus.Playing); layer.Stop(); Assert.True(layer.Status == PlaybackStatus.NotPlaying); ctx.RemoveLayer("test"); }
protected override void RenderContent(RenderComposer composer) { if (_explorer != null && _explorer.Open) { ImGui.Text("Waiting for file..."); return; } void ExecuteOnFile(Action <AudioTrack> func) { _explorer = new FileExplorer <AudioAsset>(asset => { var modifyModal = new AudioTrackModifyModal(asset, func); Parent.AddWindow(modifyModal); }, true); Parent.AddWindow(_explorer); } float masterVol = Engine.Configuration.MasterVolume; if (ImGui.DragFloat("Global Volume", ref masterVol, 0.01f, 0f, 1f)) { Engine.Configuration.MasterVolume = masterVol; foreach (KeyValuePair <AudioLayer, WaveformVisualization> cache in _waveFormCache) { cache.Value.Recreate(); } } bool mono = Engine.Configuration.ForceMono; if (ImGui.Checkbox("Force Mono", ref mono)) { Engine.Configuration.ForceMono = mono; } // Push waveforms down. composer.PushModelMatrix(Matrix4x4.CreateTranslation(new Vector3(0, 50, 0))); // Render ImGui section of layers. string[] layers = Engine.Audio.GetLayers(); for (var i = 0; i < layers.Length; i++) { AudioLayer layer = Engine.Audio.GetLayer(layers[i]); _waveFormCache.TryGetValue(layer, out WaveformVisualization cache); ImGui.PushID(i); ImGui.Text($"Layer: {layers[i]} [{layer.Status}] {(layer.CurrentTrack != null ? $" {MathF.Truncate(layer.Playback * 100f) / 100f:0}/{layer.CurrentTrack.File.Duration:0.0}s" : "")}"); float volume = layer.Volume; if (ImGui.DragFloat("Volume", ref volume, 0.01f, 0f, 1f)) { cache?.Recreate(); layer.Volume = volume; } if (ImGui.Button("Add To Queue")) { ExecuteOnFile(layer.AddToQueue); } ImGui.SameLine(); if (ImGui.Button("Add To Play Next")) { ExecuteOnFile(layer.PlayNext); } ImGui.SameLine(); if (ImGui.Button("Quick Play")) { ExecuteOnFile(layer.QuickPlay); } if (layer.Status == PlaybackStatus.Paused) { if (ImGui.Button("Resume")) { layer.Resume(); } } else { if (ImGui.Button("Pause")) { layer.Pause(); } } ImGui.SameLine(); ImGui.SameLine(); if (ImGui.Button("Stop")) { layer.Stop(); } ImGui.SameLine(); if (ImGui.Button("Toggle Loop")) { layer.LoopingCurrent = !layer.LoopingCurrent; } ImGui.SameLine(); ImGui.Text($"Looping: {layer.LoopingCurrent}"); string[] items = layer.Playlist.Select(x => x.Name).ToArray(); if (ImGui.TreeNode($"Playlist, Currently Playing: {(items.Length > 0 ? items[0] : "None")}")) { var r = 0; ImGui.ListBox("", ref r, items, items.Length); ImGui.TreePop(); } ImGui.Text($"Missed: {layer.MetricBackendMissedFrames}\nAhead: {layer.MetricDataStoredInBlocks}ms"); ImGui.PopID(); ImGui.NewLine(); composer.PushModelMatrix(Matrix4x4.CreateTranslation(new Vector3(10, i * (_waveFormHeight + 10), 0))); cache?.Render(composer); composer.PopModelMatrix(); } composer.PopModelMatrix(); ImGui.InputText("", ref _newLayerName, 50); ImGui.SameLine(); if (ImGui.Button("Create Layer") && !string.IsNullOrEmpty(_newLayerName)) { Engine.Audio.CreateLayer(_newLayerName); _newLayerName = "New Layer" + Engine.Audio.GetLayers().Length; } }
protected override void RenderContent(RenderComposer composer) { if (_explorer != null && _explorer.Open) { ImGui.Text("Waiting for file..."); return; } void ExecuteOnFile(Action <AudioTrack> func) { _explorer = new FileExplorer <AudioAsset>(asset => { var modifyModal = new AudioTrackModifyModal(asset, func); Parent.AddWindow(modifyModal); }); Parent.AddWindow(_explorer); } float masterVol = Engine.Configuration.MasterVolume; if (ImGui.DragFloat("Global Volume", ref masterVol, 0.01f, 0f, 1f)) { Engine.Configuration.MasterVolume = masterVol; foreach (KeyValuePair <AudioLayer, WaveformCache> cache in _waveFormCache) { cache.Value.Recreate(); } } // Push waveforms down. composer.PushModelMatrix(Matrix4x4.CreateTranslation(new Vector3(0, _waveFormHeight, 0))); // Render ImGui section of layers. string[] layers = Engine.Host.Audio.GetLayers(); for (var i = 0; i < layers.Length; i++) { AudioLayer layer = Engine.Host.Audio.GetLayer(layers[i]); _waveFormCache.TryGetValue(layer, out WaveformCache cache); ImGui.Text($"Layer {layers[i]}"); ImGui.PushID(i); ImGui.Text($"Status: {layer.Status}" + (layer.CurrentTrack != null ? $" {MathF.Truncate(layer.CurrentTrack.Playback * 100f) / 100f:0}/{layer.CurrentTrack.File.Duration}" : "")); float volume = layer.Volume; if (ImGui.DragFloat("Volume", ref volume, 0.01f, 0f, 1f)) { cache?.Recreate(); layer.Volume = volume; } if (ImGui.Button("Add To Queue")) { ExecuteOnFile(layer.AddToQueue); } ImGui.SameLine(); if (ImGui.Button("Play Next")) { ExecuteOnFile(layer.PlayNext); } ImGui.SameLine(); if (ImGui.Button("Quick Play")) { ExecuteOnFile(layer.QuickPlay); } if (ImGui.Button("Resume")) { layer.Resume(); } ImGui.SameLine(); if (ImGui.Button("Pause")) { layer.Pause(); } ImGui.SameLine(); if (ImGui.Button("Stop")) { layer.Stop(); } if (ImGui.Button("Loop Current")) { layer.LoopingCurrent = !layer.LoopingCurrent; } ImGui.SameLine(); ImGui.Text(layer.LoopingCurrent.ToString()); var r = 0; string[] items = layer.Playlist.Select(x => x.Name).ToArray(); ImGui.ListBox("Playlist", ref r, items, items.Length); ImGui.PopID(); ImGui.NewLine(); composer.PushModelMatrix(Matrix4x4.CreateTranslation(new Vector3(0, i * _waveFormHeight, 0))); cache?.Render(composer); composer.PopModelMatrix(); } composer.PopModelMatrix(); if (ImGui.Button("Create Layer") && !string.IsNullOrEmpty(_newLayerName)) { Engine.Host.Audio.CreateLayer(_newLayerName); _newLayerName = ""; } ImGui.InputText("", ref _newLayerName, 50); }