Skip to content

Commit

Permalink
test: show audio type in audio scene
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinWilkinson committed Sep 6, 2024
1 parent e3e8f74 commit b045331
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions Testing/VelaptorTesting/Scenes/AudioScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace VelaptorTesting.Scenes;
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Numerics;
using KdGui;
using KdGui.Factories;
Expand All @@ -26,10 +27,12 @@ public class AudioScene : SceneBase
private ILoader<IAudio>? loader;
private IAudio? audio;
private ISlider? sldPosition;
private string? lblCurrentTimeName;
private string? lblStateName;
private string? lblRepeatsName;
private string? lblLengthName;
private string? lblCurrentTimeName;
private string? lblStateName;
private string? lblAudioTypeName;
private string? currentAudioType = "OGG";

/// <summary>
/// Initializes a new instance of the <see cref="AudioScene"/> class.
Expand All @@ -56,6 +59,9 @@ public override void Update(FrameTime frameTime)
{
var currentTime = GetFormattedTime(this.audio.Position.Minutes, this.audio.Position.Seconds);

var lblAudioType = this.grpInfoCtrls.GetControl<ILabel>(this.lblAudioTypeName);
lblAudioType.Text = $"Audio Type: {this.currentAudioType}";

var lblLengthCtrl = this.grpInfoCtrls.GetControl<ILabel>(this.lblLengthName);
lblLengthCtrl.Text = $"Audio Length: {GetFormattedTime(this.audio.Length.Minutes, this.audio.Length.Seconds)}";

Expand All @@ -69,6 +75,9 @@ public override void Update(FrameTime frameTime)
base.Update(frameTime);
}

/// <summary>
/// <inheritdoc cref="IDrawable.Render"/>
/// </summary>
public override void Render()
{
this.backgroundManager?.Render();
Expand Down Expand Up @@ -131,32 +140,38 @@ private void CreateInfoCtrls()
lblDesc.Name = nameof(lblDesc);
lblDesc.Text = "Use the audio controls to manipulate the audio.";

var lblState = this.ctrlFactory.CreateLabel();
lblState.Name = nameof(lblState);
this.lblStateName = nameof(lblState);
lblState.Text = "Audio State: Stopped";
var lblRepeats = this.ctrlFactory.CreateLabel();
lblRepeats.Name = nameof(lblRepeats);
this.lblRepeatsName = nameof(lblRepeats);
lblRepeats.Text = "Repeat Enabled: no";

var lblCurrentTime = this.ctrlFactory.CreateLabel();
this.lblCurrentTimeName = nameof(lblCurrentTime);
lblCurrentTime.Name = nameof(lblCurrentTime);
lblCurrentTime.Text = "Current Time: 00:00";
var lblAudioType = this.ctrlFactory.CreateLabel();
lblAudioType.Name = nameof(lblAudioType);
this.lblAudioTypeName = nameof(lblAudioType);
lblAudioType.Text = $"Audio Type: {this.currentAudioType ?? string.Empty}";

var lblLength = this.ctrlFactory.CreateLabel();
this.lblLengthName = nameof(lblLength);
lblLength.Name = nameof(lblLength);
lblLength.Text = "Audio Length: 00:00";

var lblRepeats = this.ctrlFactory.CreateLabel();
lblRepeats.Name = nameof(lblRepeats);
this.lblRepeatsName = nameof(lblRepeats);
lblRepeats.Text = "Repeat Enabled: no";
var lblCurrentTime = this.ctrlFactory.CreateLabel();
this.lblCurrentTimeName = nameof(lblCurrentTime);
lblCurrentTime.Name = nameof(lblCurrentTime);
lblCurrentTime.Text = "Current Time: 00:00";

var lblState = this.ctrlFactory.CreateLabel();
lblState.Name = nameof(lblState);
this.lblStateName = nameof(lblState);
lblState.Text = "Audio State: Stopped";

this.grpInfoCtrls = this.ctrlFactory.CreateControlGroup();
this.grpInfoCtrls.Title = "Audio Info";
this.grpInfoCtrls.AutoSizeToFitContent = true;
this.grpInfoCtrls.TitleBarVisible = false;

this.grpInfoCtrls.Add(lblRepeats);
this.grpInfoCtrls.Add(lblAudioType);
this.grpInfoCtrls.Add(lblLength);
this.grpInfoCtrls.Add(lblCurrentTime);
this.grpInfoCtrls.Add(lblState);
Expand Down Expand Up @@ -186,6 +201,8 @@ private void CreateAudioCtrls()
};

this.audio = this.loader.Load(audioName, AudioBuffer.Stream);

this.currentAudioType = Path.GetExtension(this.audio.FilePath).ToUpper().TrimStart('.');
};

var sldVolume = this.ctrlFactory.CreateSlider();
Expand Down

0 comments on commit b045331

Please sign in to comment.