[msh] metronome

Tech-Archive recommends: Fix windows errors by optimizing your registry



Reposting with the appropriate subject

some of you may not know that I started out life as a musician (I am still
active performing and conducting the Microsoft Orchestra). Anyway, I often
want to determine the tempo of a piece that I'm listening to, so I wrote
this script to help out. Note that it's not absolutely accurate, but it's
close enough for me.

MSH> cat get-metronome.msh
#
# A metronome - you tap, it reports the tempo
#

"Press 'q' to quit"
$getchar = { $host.ui.rawui.readkey("IncludeKeyDown,NoEcho").Character }
$a = 0,0,0,0
$i = 0
$now = [datetime]::now
while("q" -ne ($var = &$getchar) )
{
$new = [datetime]::now
[int]$r = (1000/[int]($new - $now).totalmilliseconds)*60
if( ++$i -ge 4 ) { $i = 0 }
$a[$i] = $r
[int]$av = ($a[0] + $a[1] + $a[2] + $a[3])/4
write-host -nonew ("Tempo {0,4} : Current {1,4}`r" -f $av,$r)
$now = $new
}
""

and then we need set-metronome - again, these are approximates. If I get
within a couple of beats per minute, I'm happy.
MSH> cat set-metronome.msh

param ( $tempo )
"Press any key to quit"
while ( $true )
{
$x = (1000/($tempo/60)) - 50 # 50 for the beep
start-sleep -m $x
[console]::Beep(440,50)
if ( [console]::KeyAvailable ) { break }
}



--
James W. Truher [MSFT]
Monad Program Management
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


--
James W. Truher [MSFT]
Monad Program Management
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


.



Relevant Pages

  • Re: Install Windows Patch via GPO
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.windows.group_policy)
  • Re: Trust windows 2k to windows 2k3
    ... This posting is provided "AS-IS" with no warranties or guarantees and ... confers no rights. ... only reply to Newsgroups ...
    (microsoft.public.windows.server.active_directory)
  • Re: Trust windows 2k to windows 2k3
    ... This posting is provided "AS-IS" with no warranties or guarantees and confers no rights. ... only reply to Newsgroups ...
    (microsoft.public.windows.server.active_directory)
  • Re: Installing a 360 Media Center Extender
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.windows.mediacenter)
  • Re: Trust windows 2k to windows 2k3
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... only reply to Newsgroups ...
    (microsoft.public.windows.server.active_directory)