[msh] metronome
- From: "James Truher [MSFT]" <jimtru@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Feb 2006 13:10:44 -0800
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.
.
- Prev by Date: Re: [MSH] Process AliasProperty VS
- Next by Date: Re: need to modify local group membership via VBscript
- Previous by thread: Listing mapped drives on remote computers
- Next by thread: [msh]wait for program exit
- Index(es):
Relevant Pages
|