Idera nSoftware Compellent

Merry Christmas


posted by Sylvain LESIRE
12-15-2008

Downloads: 474
File size: 2.2kB
Views: 1,694

Embed
Merry Christmas
  1. # script link  
  2.     # http://forums.microsoft.com/TechNet-FR/ShowPost.aspx?PostID=2555221&SiteID=45 
  3. $notes = write-output
  4.   4A4 4A4 2A4        4A4 4A4 2A4        4A4 4C4 4F3 8G3             1A4 ` 
  5.   4Bb4 4Bb4 4Bb4 8Bb4     4Bb4 4A4 4A4 8A4 8A4    4A4 4G3 4G3 4A4    2G3 2C4 ` 
  6.   4A4 4A4 2A4       4A4 4A4 2A4    4A4 4C4 4F3 4G3     1A4        4Bb4 4Bb4 4Bb4 4Bb4 ` 
  7.   4Bb4 4A4 4A4 8A4 8A4    4C4 4C4 4Bb4 4G3     1F3     4C3 4A4 4G3 4F3     2C3 8C3 8C3  
  8.   4C3 4A4 4G3 4F3       1D3      4D3 4Bb4 4A4 4G3     '1E3'    4C4 4C4 4Bb4 4G3 ` 
  9.   1A4     4C3 4A4 4G3 4F3    1C3     4C3 4A4 4G3 4F3     1D3 ` 
  10.   4D3 4Bb3 4A4 4G3         4C4 4C4 4C4 8C4 8C4    4D4 4C4 4Bb4 4G3    4F3 2C4   4A4 4A4 2A4 ` 
  11.   4A4 4A4 2A4      4A4 4C4 4C3 8G3      1A4     4Bb4 4Bb4 4Bb4 8Bb4      4Bb4 4A4 4A4 8A4 8A4 ` 
  12.   4A4 4G3 4G3 4A4       2G3 2C4     4A4 4A4 2A4     4A4 4A4 2A4    4A4 4C4 4F3 8G3 ` 
  13.   1A4       4Bb4 4Bb4 4Bb4 4Bb4      4Bb4 4A4 4A4 8A4 8A4      4C4 4C4 4Bb4 4G3     1F3 
  14.  
  15. function Play([int] $freq, [int] $duration
  16.   [console]::Beep($freq, $duration); 
  17.  
  18.  
  19.  
  20. # 
  21. # Note is given by fn=f0 * (a)^n 
  22. # a is the twelth root of 2 
  23. # n is the number of half steps from f0, positive or negative. 
  24. # f0 used here is A4 at 440 Hz 
  25. # 
  26. $f0 = 440; 
  27. $a = [math]::pow(2,(1/12)); # Twelth root of 2 
  28. function GetNoteFreq([string]$note
  29.   # n is the number of half steps from the fixed note. 
  30.   $note -match '([A-G#]{1,2})(\d+)' | out-null 
  31.   $octave = ([int] $matches[2]) - 4; 
  32.   $n = $octave * 12 + ( GetHalfStepsFromA $matches[1] ); 
  33.   $freq = $f0 * [math]::Pow($a, $n); 
  34.  
  35.   return $freq
  36.  
  37.  
  38.  
  39. function GetHalfStepsFromA([string] $note
  40.   switch($note
  41.   
  42.     'A'  { 0 } 
  43.     'A#' { 1 } 
  44.     'Bb' { 1 } 
  45.     'B'  { 2 } 
  46.     'C'  { 3 } 
  47.     'C#' { 4 } 
  48.     'Db' { 4 } 
  49.     'D'  { 5 } 
  50.     'D#' { 6 } 
  51.     'Eb' { 6 } 
  52.     'E'  { 7 } 
  53.     'F'  { 8 } 
  54.     'F#' { 9 } 
  55.     'Gb' { 9 } 
  56.     'G'  { 10 } 
  57.     'G#' { 11 } 
  58.     'Ab' { 11 } 
  59.   
  60.  
  61.  
  62.  
  63. $StandardDuration = 1000; 
  64. foreach($note in $notes
  65.  
  66.   $note -match '(\d)(.+)' | out-null 
  67.   $duration = $StandardDuration / ([int] $matches[1]); 
  68.   $playNote = $matches[2]; 
  69.   $freq = GetNoteFreq $playNote
  70.  
  71.   write-host $playNote
  72.   Play $freq $duration 
  73.   start-sleep -milli 50 
Filed under: , ,

A fun script for Christmas holidays

 

Copyright 2010 PowerShell.com. All rights reserved.