-
-
Save orange-in-space/a9ee246e10747a97bfa401c8e72e564e to your computer and use it in GitHub Desktop.
PowerShellで音楽鍵盤第2弾><
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Power Shell Cheapest Musical Keyboard mk2 | |
# (C) orange_in_space 2021 | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type -AssemblyName System.Drawing | |
$form = New-Object System.Windows.Forms.Form | |
$form.Text = "PowerShell音楽鍵盤!><; その2" | |
$form.Size = New-Object System.Drawing.Size(640,180) | |
$HzArray = @(262,277,294,311,330,349,370,392,415,440,466,494) | |
$musickeylayoutX =@(0, 0.5, 1, 1.5, 2, 3, 3.5, 4, 4.5, 5, 5.5, 6) | |
$musickeylayoutY =@(0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0) | |
$musickeyCaption =@("&A", "&W", "&S", "&E", "&D", "&F", "&T", "&G", "&Y", "&H", "&U", "&J", ` | |
"&K", "&O", "&L", "&P", "", "", "", "", "", "", "", "" ) | |
for ($octave=0; $octave -lt 2; $octave++) | |
{ | |
for ($i=0; $i -lt 12; $i++) | |
{ | |
$NewToneButton = New-Object System.Windows.Forms.Button | |
$px = [int]( ($octave * 7 + $musickeylayoutX[$i]) * 40 + 20) | |
$py = [int]( $musickeylayoutY[$i] * -40 + 60) | |
$NewToneButton.Location = New-Object System.Drawing.Point($px,$py) | |
$NewToneButton.Size = New-Object System.Drawing.Size(32,32) | |
$NewToneButton.Text = $musickeyCaption[$i + $octave * 12] | |
$NewToneButton.Tag = [int]($HzArray[$i]*($octave+1)) | |
if ($musickeylayoutY[$i] -gt 0) | |
{ | |
$NewToneButton.Backcolor = "ControlDark" | |
} | |
$NewToneButton.Add_Click({ | |
[Console]::Beep([int]$this.Tag, 160) | |
}) | |
$form.Controls.Add($NewToneButton) | |
} | |
} | |
# キャンセルボタンの設定 | |
$CancelButton = New-Object System.Windows.Forms.Button | |
$CancelButton.Location = New-Object System.Drawing.Point(580,8) | |
$CancelButton.Size = New-Object System.Drawing.Size(40,20) | |
$CancelButton.Text = "Exit" | |
$CancelButton.DialogResult = "Cancel" | |
# 列挙子名:None, OK, Cancel, Abort, Retry, Ignore, Yes, No | |
$label = New-Object System.Windows.Forms.Label | |
$label.Location = New-Object System.Drawing.Point(10,4) | |
$label.Size = New-Object System.Drawing.Size(480,40) | |
$label.Text = "超ゆっくり弾いてね!><;" | |
# $form.AcceptButton = $OKButton | |
$form.CancelButton = $CancelButton | |
$form.Controls.Add($CancelButton) | |
$form.Controls.Add($label) | |
while ($true) | |
{ | |
$result = $form.ShowDialog() | |
if ($result -eq "Cancel") | |
{ | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment