Skip to content

Commit

Permalink
feat: OBS.Beat.TapBPM ( Fixes #191 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Feb 14, 2024
1 parent f2cfea7 commit f8708d1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Types/OBS.Beat/TapBPM.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<#
.SYNOPSIS
Tap BPM
.DESCRIPTION
Tap out a BPM by pressing ENTER on N beats.
The BPM will be set to the average time between taps, and the beat will be started.
#>
param(
# The number of taps.
[int]
$TapCount = 8
)

Write-Host "Press ENTER on the next..."
$beatTimes = @()
$beatTimeStart = [datetime]::Now
$lastBeatTime = [timespan]::FromMilliseconds(0)
$beatTimes = do {
Write-Host "$($TapCount -$beatTimes.Length) beats:" -NoNewline
$readNothing = Read-Host
$beatTimes += [datetime]::Now
$lastBeatTime = $beatTimes[-1] - $beatTimeStart
$beatTimeStart = [datetime]::Now
$lastBeatTime
} while ($beatTimes.Length -lt $TapCount)

$averageTimeBetweenBeats =
$beatTimes.TotalMilliseconds | Measure-Object -Average | Select-Object -ExpandProperty Average

$TappedBpm = (60 * 1000) / $averageTimeBetweenBeats
$this.BPM = $TappedBpm
$this.BeatStart = $beatTimes[-1]
$TappedBpm


0 comments on commit f8708d1

Please sign in to comment.