Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move to the optionsrecord screen
  • Loading branch information
dgruss committed Sep 21, 2025
commit 3dd5a66ad5d23b4f3753ca92e4a4a374c6d3e17d
15 changes: 0 additions & 15 deletions src/menu/UDisplay.pas
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ TDisplay = class

procedure SaveScreenShot;

procedure DrawDelay(Delay: Integer);

function Draw: boolean;

// TODO rewrite ParseInput to include handling/suppressing input as return, use KeepGoing as by-reference
Expand Down Expand Up @@ -891,19 +889,6 @@ function TDisplay.ConsoleParseMouse(MouseButton: integer; BtnDown: boolean; X, Y
end;
end;

procedure TDisplay.DrawDelay(Delay: Integer);
begin
// set font specs using UDisplay methods
SetFontFamily(0);
SetFontStyle(ftRegular);
SetFontSize(21);
SetFontItalic(false);
glColor4f(0, 0, 0, 1);
SetFontPos(605, 0);
glPrint('Delay measured: ' + IntToStr(Delay) + ' ms');
glColor4f(1, 1, 1, 1);
end;

//------------
// DrawDebugInformation - procedure draw fps and some other informations on screen
//------------
Expand Down
46 changes: 0 additions & 46 deletions src/screens/UScreenMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ interface
UFiles,
UMenu,
UMusic,
URecord,
UScreenSong,
USong,
UThemes,
MidiOut,
MidiCons,
Math,
MD5,
sdl2,
SysUtils;
Expand All @@ -56,10 +52,6 @@ TScreenMain = class(TMenu)
public
TextDescription: integer;
TextDescriptionLong: integer;
PingTime: integer;
PingResponse: integer;
CurrentSound: TCaptureBuffer;
MidiOut: TMidiOutput;

constructor Create; override;
function ParseInput(PressedKey: Cardinal; CharCode: UCS4Char;
Expand Down Expand Up @@ -119,24 +111,6 @@ function TScreenMain.ParseInput(PressedKey: Cardinal; CharCode: UCS4Char;
end;
end;

SDLK_W: begin
SoundLib.Ping.Volume := 1.0;
PingResponse := 0;
PingTime := SDL_GetTicks;
SoundLib.Ping.Play;
Exit;
end;

SDLK_M: begin
SoundLib.Ping.Volume := 1.0;
PingResponse := 0;
PingTime := SDL_GetTicks;
MidiOut.PutShort($B1, $7, 127);
MidiOut.PutShort($81, 24 + 60, 127);
MidiOut.PutShort($91, 24 + 60, 127);
Exit;
end;

SDLK_J: begin
FadeTo(@ScreenJukeboxPlaylist, SoundLib.Start);
Exit;
Expand Down Expand Up @@ -330,12 +304,6 @@ constructor TScreenMain.Create;
Interaction := 0;

WantSoftwareRenderingMsg := SoftwareRendering;

PingTime := 0;
PingResponse := 0;

MidiOut := TMidiOutput.Create(nil);
MidiOut.Open;
end;

procedure TScreenMain.OnShow;
Expand All @@ -354,8 +322,6 @@ procedure TScreenMain.OnShow;
* at the moment there is no better place for this
*}
Party.Clear;

AudioInput.CaptureStart;
end;

function TScreenMain.Draw: boolean;
Expand All @@ -370,18 +336,6 @@ function TScreenMain.Draw: boolean;
ScreenPopupError.ShowPopup(Language.Translate('ERROR_SOFTWARE_RENDERING'));
end;
end;

CurrentSound := AudioInputProcessor.Sound[0];
CurrentSound.AnalyzeBuffer;

if (CurrentSound.ToneAbs = 48) and (PingResponse = 0) then
begin
PingResponse := SDL_GetTicks - PingTime;
MidiOut.PutShort($B1, $7, 127);
MidiOut.PutShort($81, 24 + 60, 127);
MidiOut.PutShort(MIDI_STOP, 0, 0);
end;
Display.DrawDelay(PingResponse);
end;

procedure TScreenMain.SetInteraction(Num: integer);
Expand Down
43 changes: 43 additions & 0 deletions src/screens/UScreenOptionsRecord.pas
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ TScreenOptionsRecord = class(TMenu)
SourceVolume: single;
NextVolumePollTime: cardinal;

// Mic Delay measurement
PingTime: integer;
PingResponse: integer;

procedure StartPreview;
procedure StopPreview;
procedure UpdateInputDevice;
Expand All @@ -91,6 +95,7 @@ TScreenOptionsRecord = class(TMenu)
procedure DrawVolume(x, y, Width, Height: single);
procedure DrawVUMeter(const State: TDrawState; x, y, Width, Height: single);
procedure DrawPitch(const State: TDrawState; x, y, Width, Height: single);
procedure DrawDelay(const State: TDrawState; x, y, Width, Height: single);
public
constructor Create; override;
function Draw: boolean; override;
Expand Down Expand Up @@ -169,6 +174,14 @@ function TScreenOptionsRecord.ParseInput(PressedKey: cardinal; CharCode: UCS4Cha

// check special keys
case PressedKey of
SDLK_W:
begin
SoundLib.Ping.Volume := 1.0;
PingResponse := 0;
PingTime := SDL_GetTicks;
SoundLib.Ping.Play;
Exit;
end;
SDLK_ESCAPE,
SDLK_BACKSPACE:
begin
Expand Down Expand Up @@ -251,6 +264,9 @@ constructor TScreenOptionsRecord.Create;
begin
inherited Create;

PingTime := 0;
PingResponse := 0;

LoadFromTheme(Theme.OptionsRecord);

// set CurrentDeviceIndex to a valid device
Expand Down Expand Up @@ -775,6 +791,30 @@ procedure TScreenOptionsRecord.DrawPitch(const State: TDrawState; x, y, Width, H
glPrint(ToneString);
end;

procedure TScreenOptionsRecord.DrawDelay(const State: TDrawState; x, y, Width, Height: single);
var
DelayString: string;
DelayStringWidth, DelayStringMaxWidth, DelayStringCenterXOffset: real;
begin
PreviewChannel.AnalyzeBuffer();

if (PreviewChannel.ToneAbs = 48) and (PingResponse = 0) then
PingResponse := SDL_GetTicks - PingTime - 5; // 5 ms delay in the wav file
DelayString := 'Delay: ' + IntToStr(PingResponse) + ' ms';

SetFontSize(Height*2);

// center
DelayStringWidth := glTextWidth(DelayString);
DelayStringMaxWidth := glTextWidth('Delay: 999999 ms');
DelayStringCenterXOffset := (DelayStringMaxWidth-DelayStringWidth) / 2;

// draw
SetFontPos(x-DelayStringWidth-DelayStringCenterXOffset, y-Height/2);
glColor3f(0, 0, 0);
glPrint(DelayString);
end;

function TScreenOptionsRecord.Draw: boolean;
var
Device: TAudioInputDevice;
Expand All @@ -783,6 +823,7 @@ function TScreenOptionsRecord.Draw: boolean;
BarXOffset, BarYOffset, BarWidth: real;
ChannelIndex: integer;
State: TDrawState;
ToneStringMaxWidth: real;
begin
DrawBG;
DrawFG;
Expand Down Expand Up @@ -837,6 +878,8 @@ function TScreenOptionsRecord.Draw: boolean;

DrawVUMeter(State, BarXOffset, BarYOffset, BarWidth, BarHeight);
DrawPitch(State, BarXOffset, BarYOffset+BarHeight, BarWidth, BarHeight);
ToneStringMaxWidth := glTextWidth('G#4');
DrawDelay(State, BarXOffset - 2 * ToneStringMaxWidth, BarYOffset+BarHeight, BarWidth, BarHeight);
end;

Result := true;
Expand Down