Windows Vista Forums

[script] gadget-piano.ps1
  1. #1


    Jean Guest

    [script] gadget-piano.ps1

    2 scripts for fun :

    gadget-piano.ps1
    plays string music notes on pc speaker


    http://groups.google.com/group/micro...bebc6750265064



    gadget-morse.ps1
    a demo using gadget-piano.ps1
    plays string in Mose code


    http://groups.google.com/group/micro...8cdadc00084154

    Regards,

    --
    Jean - JMST
    Belgium



      My System SpecsSystem Spec

  2. #2


    Jean Guest

    Re: [script] gadget-piano.ps1

    > 2 scripts for fun :

    inside scripts, replace :

    # You must have a pc speaker present and enabled

    with

    # You must have a pc *internal* speaker present and enabled

    Regards,

    --
    Jean - JMST
    Belgium



      My System SpecsSystem Spec

  3. #3


    James Truher Guest

    Re: [script] gadget-piano.ps1

    here's a little mozart for you:


    $meep = [Console]
    function mybeep { $meep::Beep($args[0], ($args[1] * 1000)) }
    $ae = @{ note = 440 ; duration = 0.15 }
    $as = @{ note = 440 ; duration = 0.15 }
    $es = @{ note = 329.628; duration = 0.15 }
    $b = @{ note = 493.883; duration = 0.15 }
    $cs = @{ note = 554.365; duration = 0.15 }
    $gs = @{ note = 415.305; duration = 0.15 }
    $rest = @{ note = 0; duration = 0.15 }
    function s { @{ note = $args[0]; duration = 0.15 } }

    $tune = $ae,$ae, $rest, $es, $ae,$ae, $rest, $es, $as, $es, $as,
    $cs, @{ note = 659.225 ; duration = 0.45 },
    $rest, @{ note = 587.33 ; duration = 0.30 },
    $rest, $b, @{ note = 587.33 ; duration = 0.30 },
    $rest, $b, @{ note = 587.33 ; duration = 0.15 },
    $b, @{ note = 415.305 ; duration = 0.15 },
    $b, @{ note = 329.628 ; duration = 0.45 },$rest,
    $ae,$rest,$ae,$ae,$rest,$cs,$b,$ae,$ae,$gs,$gs,$gs

    foreach ( $h in $tune ) {
    if ( $h.note -eq 0 ) { start-sleep -mill ( $h.duration * 1000 ) }
    else { mybeep $h.note $h.duration }
    }




    --
    --
    James Truher [MSFT]
    Windows PowerShell Development
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "Jean" <repondre@groupe.svp> wrote in message
    news:mn.0c5e7d6a7a8e072e.56820@windows...
    >2 scripts for fun :
    >
    > gadget-piano.ps1
    > plays string music notes on pc speaker
    >
    >
    > http://groups.google.com/group/micro...bebc6750265064
    >
    > gadget-morse.ps1
    > a demo using gadget-piano.ps1
    > plays string in Mose code
    >
    >
    > http://groups.google.com/group/micro...8cdadc00084154
    >
    > Regards,
    >
    > --
    > Jean - JMST
    > Belgium
    >
    >




      My System SpecsSystem Spec

  4. #4


    Adam Milazzo Guest

    Re: [script] gadget-piano.ps1

    James Truher wrote:
    > here's a little mozart for you:


    Awesome. I'm so reminded of those ancient games I had for the 286. :-)

      My System SpecsSystem Spec

  5. #5


    Jean Guest

    Re: [script] gadget-piano.ps1

    > here's a little mozart for you:

    Thank you James :-)

    A nice piece to start
    (Get-Culture).DateTimeFormat.FirstDayOfWeek
    :-)

    Regards,

    --
    Jean - JMST
    Belgium



      My System SpecsSystem Spec

  6. #6


    Alex K. Angelopoulos [MVP] Guest

    Re: [script] gadget-piano.ps1

    "James Truher" <jimtru@news.microsoft.com> wrote in message
    news:OVVo2aa6GHA.348@TK2MSFTNGP02.phx.gbl...
    > here's a little mozart for you:


    On a tangent from this topic - any thoughts on a good approach to handling
    sound in PowerShell? We can do rather elegant beeping and even play wav
    files easily, but I haven't seen any simple way of playing back MDI or MP3.



      My System SpecsSystem Spec

  7. #7


    Fred J. Guest

    Re: gadget-piano.ps1

    QRZ fb es 73 de KE2QR/WS2SF
    Fred Jacobowitz
    http://www.qrz.com/callsign/ke2qr
    Jean wrote:
    > 2 scripts for fun :
    >
    > gadget-piano.ps1
    > plays string music notes on pc speaker
    >
    >
    > http://groups.google.com/group/micro...bebc6750265064
    >
    > gadget-morse.ps1
    > a demo using gadget-piano.ps1
    > plays string in Mose code
    >
    >
    > http://groups.google.com/group/micro...8cdadc00084154
    >
    > Regards,
    >
    > --
    > Jean - JMST
    > Belgium



      My System SpecsSystem Spec

  8. #8


    James Truher Guest

    Re: [script] gadget-piano.ps1

    I've been using a script to play my media files for a while, it builds from
    here:

    $path = "$env:windir\media\tada.wav"
    $player = new-object -com wmplayer.ocx
    $player.currentplaylist.appenditem(($player.newmedia($path)))
    $player.controls.play()

    --
    --
    James Truher [MSFT]
    Windows PowerShell Development
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
    news:OwxZiLV7GHA.4620@TK2MSFTNGP02.phx.gbl...
    > "James Truher" <jimtru@news.microsoft.com> wrote in message
    > news:OVVo2aa6GHA.348@TK2MSFTNGP02.phx.gbl...
    >> here's a little mozart for you:

    >
    > On a tangent from this topic - any thoughts on a good approach to handling
    > sound in PowerShell? We can do rather elegant beeping and even play wav
    > files easily, but I haven't seen any simple way of playing back MDI or
    > MP3.
    >
    >




      My System SpecsSystem Spec

  9. #9


    Alex K. Angelopoulos [MVP] Guest

    Re: [script] gadget-piano.ps1

    Thanks, Jim. I never worked that out from the WMP docs - although I didn't
    dig as deeply as I should have. :|

    I also didn't realize that it would be possible to play multiple items in
    parallel. Here's a quick wrapper for anyone who just wants to queue up an
    item in PS.

    function Start-Media
    {
    Param([string]$FilePath)
    $player = New-Object -ComObject wmplayer.ocx
    $player.currentplaylist.appenditem(($player.newmedia($FilePath)))
    $player.controls.play()
    }


    "James Truher" <jimtru@news.microsoft.com> wrote in message
    news:u7m8z1V7GHA.2384@TK2MSFTNGP04.phx.gbl...
    > I've been using a script to play my media files for a while, it builds
    > from here:
    >
    > $path = "$env:windir\media\tada.wav"
    > $player = new-object -com wmplayer.ocx
    > $player.currentplaylist.appenditem(($player.newmedia($path)))
    > $player.controls.play()
    >
    > --
    > --
    > James Truher [MSFT]
    > Windows PowerShell Development
    > Microsoft Corporation
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    > "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
    > news:OwxZiLV7GHA.4620@TK2MSFTNGP02.phx.gbl...
    >> "James Truher" <jimtru@news.microsoft.com> wrote in message
    >> news:OVVo2aa6GHA.348@TK2MSFTNGP02.phx.gbl...
    >>> here's a little mozart for you:

    >>
    >> On a tangent from this topic - any thoughts on a good approach to
    >> handling sound in PowerShell? We can do rather elegant beeping and even
    >> play wav files easily, but I haven't seen any simple way of playing back
    >> MDI or MP3.
    >>
    >>

    >
    >




      My System SpecsSystem Spec

  10. #10


    James Truher Guest

    Re: [script] gadget-piano.ps1

    yah - I have an entire script that adjusts volume, etc. I've put it in the
    book I'm writing

    ok - here's the whole thing - it uses my convert-hashtoobject cmdlet, which
    if you don't have, you can replace with this:
    function convert-hashtoobject
    {
    param ( [hashtable]$hashtable, $names )
    $o = new-object psobject
    $o.psobject.typenames[0] = $names
    foreach($key in $hashtable.keys) { $o|add-member noteproperty $key
    $hashtable.$key }
    $o
    }



    jim


    #### Play-Media.ps1
    param ( [switch]$Next, [switch]$Prev,
    [switch]$Pause, [switch]$Stop, [switch]$Start, [int]$Number,
    [switch]$Louder, [switch]$Softer, [int]$volume,
    [switch]$Playlist, [switch]$list, [string[]]$Add, [switch]$Clear,
    [switch]$Current, [int]$Skip,
    [switch]$raw,
    [switch]$Quit
    )

    if ( $args )
    {
    @"
    USAGE: $( $myinvocation.mycommand.name )
    A COM based media player. It creates a global variable `$player
    which is used to play files without starting media player.

    Options:
    -Next Go to next song in songlist
    -Prev Go to previous song in songlist
    -Pause Pause playback
    -Stop Stop playback
    -Start Start playback
    -Number <num> Go to <number> in playlist
    -Louder Raise the volume
    -Softer Lower the volume
    -Playlist(list) Show the playlist
    -Add <string> Add a file to the playlist
    -Clear Clear the playlist
    -Current Show the current playing file
    -quit Quit and remove `$player
    "@
    exit
    }


    if ( ! (get-command Convert-HashToObject 2> $null) )
    {
    add-pssnapin ConversionCmdlets 2> $null
    if ( ! (get-command Convert-HashToObject 2> $null) )
    {
    ConversionCmdlets not loaded, exiting
    exit;
    }
    }

    if ( ! $globallayer )
    {
    $host.ui.rawui.windowtitle = "PS(P)> $PWD"
    $globallayer = new -com wmplayer.ocx
    }
    $fmt = @{ e = "Artist"; W = 20 },"Name",@{e ="Duration"; W = 6}

    function play-number ( $number )
    {
    $number--
    trap { continue }
    $item = $player.currentplaylist.item($number)
    if ( $item )
    {
    $player.controls.stop()
    $player.controls.currentitem = $item
    $player.controls.play()
    }
    else
    {
    write-host -fore red "No such number $number"
    exit
    }
    }

    if ( $next ) { $player.controls.next() }
    elseif ( $prev ) { $player.controls.previous() }
    elseif ( $stop ) { $player.controls.stop() }
    elseif ( $start ) { $player.controls.play() }
    elseif ( $pause ) { $player.controls.pause() }
    elseif ( $louder ) { $player.settings.volume += 10 }
    elseif ( $softer ) { $player.settings.volume -= 10 }
    elseif ( $volume ) { $player.settings.volume = $volume }
    elseif ( $clear ) { $player.currentplaylist.clear() }
    elseif ( $number ) { play-number $number }
    elseif ( $Skip ) { $player.controls.currentposition += $Skip }
    elseif ( $playlist -or $list )
    {
    $count = $player.currentplaylist.count - 1
    if ( $count -lt 0 )
    {
    "Playlist is empty"
    exit
    }
    $numberInPlaylist = @{
    A = "Right"; L = "Num"; w = 4
    e = { $_.Num }
    }
    $fmt = @( $numberInPlayList ) + $fmt
    $url = $player.currentmedia.sourceurl
    if ( $raw )
    {
    0..$count | foreach { $player.currentplaylist.item($_) }
    return
    }
    0..($count) |
    foreach {
    [timespan]$total = 0 ; [int]$fnumber = 1
    } {
    $iam = $player.currentplaylist.item($_)
    if ( $iam.sourceurl -eq $url )
    {
    $fg = $host.ui.rawui.foregroundcolor
    $host.ui.rawui.foregroundcolor = "red"
    }
    Convert-HashToObject -names Playlist.Entry -hash @{
    Artist = $iam.getiteminfo("Artist")
    Duration = $iam.DurationString
    Name = $iam.Name
    Num = $fnumber
    }
    if ( $iam.sourceurl -eq $url )
    {
    $host.ui.rawui.foregroundcolor = $fg
    }
    $fnumber++
    $total += ("00:" + $iam.durationstring)
    } { write-host " Total time: $total" } | format-table $fmt
    }
    elseif ( $current )
    {
    if ( $raw )
    {
    $player.currentmedia
    return
    }
    $lfmt = $fmt + @{
    W = 5
    L = "Pos"
    E = {
    $ts = new timespan 1,0,$player.controls.currentposition
    "{0}:{1:00}" -f $ts.minutes,$ts.seconds
    }
    }
    $o = Convert-HashToObject -names Playlist.CurrentEntry -hash @{
    Artist = $player.currentmedia.getiteminfo("Artist")
    Duration = $player.currentmedia.DurationString
    Name = $player.currentmedia.Name
    }
    $o | format-table $lfmt
    }
    elseif ( $add )
    {
    foreach($mediapath in $add )
    {
    # make sure we have a real path
    $path = (resolve-path $mediapath).path

    # open a playlist and add the elements to our playlist
    if ( $path -match "m3u$" )
    {
    get-content $path | where { $_ -notmatch "^#" } |
    foreach {
    $player.currentplaylist.appenditem(($player.newmedia($_))) }
    }
    else
    {
    $player.currentplaylist.appenditem(($player.newmedia($path)))
    }
    }
    $player.controls.play()
    }
    elseif ( $quit )
    {
    $player.controls.stop()
    $player.close()
    remove-item variablelayer
    }

    --
    --
    James Truher [MSFT]
    Windows PowerShell Development
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
    news:OfLh0zW7GHA.1188@TK2MSFTNGP05.phx.gbl...
    > Thanks, Jim. I never worked that out from the WMP docs - although I didn't
    > dig as deeply as I should have. :|
    >
    > I also didn't realize that it would be possible to play multiple items in
    > parallel. Here's a quick wrapper for anyone who just wants to queue up an
    > item in PS.
    >
    > function Start-Media
    > {
    > Param([string]$FilePath)
    > $player = New-Object -ComObject wmplayer.ocx
    > $player.currentplaylist.appenditem(($player.newmedia($FilePath)))
    > $player.controls.play()
    > }
    >
    >
    > "James Truher" <jimtru@news.microsoft.com> wrote in message
    > news:u7m8z1V7GHA.2384@TK2MSFTNGP04.phx.gbl...
    >> I've been using a script to play my media files for a while, it builds
    >> from here:
    >>
    >> $path = "$env:windir\media\tada.wav"
    >> $player = new-object -com wmplayer.ocx
    >> $player.currentplaylist.appenditem(($player.newmedia($path)))
    >> $player.controls.play()
    >>
    >> --
    >> --
    >> James Truher [MSFT]
    >> Windows PowerShell Development
    >> Microsoft Corporation
    >> This posting is provided "AS IS" with no warranties, and confers no
    >> rights.
    >>
    >> "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
    >> news:OwxZiLV7GHA.4620@TK2MSFTNGP02.phx.gbl...
    >>> "James Truher" <jimtru@news.microsoft.com> wrote in message
    >>> news:OVVo2aa6GHA.348@TK2MSFTNGP02.phx.gbl...
    >>>> here's a little mozart for you:
    >>>
    >>> On a tangent from this topic - any thoughts on a good approach to
    >>> handling sound in PowerShell? We can do rather elegant beeping and even
    >>> play wav files easily, but I haven't seen any simple way of playing back
    >>> MDI or MP3.
    >>>
    >>>

    >>
    >>

    >
    >




      My System SpecsSystem Spec

Page 1 of 2 12 LastLast
[script] gadget-piano.ps1 problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Explorer & Vista..dragging a piano would be quicker ! JackSpence Network & Sharing 0 25 Apr 2009
Logon Script Causing Laptops To Hang - Problems in script? Ben VB Script 5 07 Feb 2009
problem passing args to script 'There is no script engine for file extenstion' James VB Script 5 31 Oct 2008
Playback Midi files using WMP on Yamaha Piano Sharam Vista music pictures video 0 02 Jan 2008
BUG in Weather gadget: gadget moves from right to left after days! BillD Vista General 3 25 May 2007