Skip to content

Instantly share code, notes, and snippets.

@orange-in-space
Last active November 30, 2021 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orange-in-space/a9ee246e10747a97bfa401c8e72e564e to your computer and use it in GitHub Desktop.
Save orange-in-space/a9ee246e10747a97bfa401c8e72e564e to your computer and use it in GitHub Desktop.
PowerShellで音楽鍵盤第2弾><
# 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