Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[PS] Piano mécanique

7 réponses
Avatar
Jean
* gadget-piano.ps1 *

est un script qui joue des notes de musiques sur le haut paleur du pc.

.\gadget-piano
°joue un petit air de musique
.\gadget-piano "2A" 5000
°joue un La 5 secondes
.\gadget-piano (("1F# Z ")*5) 300
°joue un Fa dièse et un silence 5 fois
.\gadget-piano "1A 1B 1C 3A 3B 3C" 150 50
°joue une séquence de notes, chacune jouée 150 ms avec un interval de
50 ms

* gadget-morse.ps1 *

est un script de démo utilisant gadget-piano.ps1.
Il joue des chaînes en Morse.

.\gadget-morse
°joue une démo
.\gadget-morse -verbose
°joue une démo et retourne les mots et le code Morse
.\gadget-morse "Hello world" -verbose
°joue "Hello world" en Morse et retourne les mots et le code Morse
.\gadget-morse "Hello world" 70 "1G"
°joue "Hello world" avec un Ti d'unee longeur de 70 ms et un Si
pour jouer les Ti et Ta

Voir les commentaires dans les scripts pour plus de précisions.

Je poste les 2 scripts en réponse à ce message.

Amicalement,

--
Jean - JMST
Belgium

7 réponses

Avatar
Jean
#---8<---gadget-piano.ps1---Jean-JMST-Belgium---8<---

#=9/2006===================================Version 0==========#
#=========== "human hearable" string music notes ============#
#
# To use :
#
# -music paremeter is a string containing music notes separated
# by a space.
#
# A simplified abc notation is used.
# A music note begins with the keyboard's ocatve used (1, 2 or 3)
# followed by a character music note (from C to B) + eventually
# a # character indicating an half tone higher (sharp), so :
#
# 2F# is music note F sharp played on the second piano
# keyboard's octave.
#
# Values allowed for notes :
# C,C#,D,D#,E,F,F#,G,G#,A,A# and B
# preceded by 1,2 or 3
#
# A silence is marked with a Z.
#
# -black is the duration in millisecond a note is played
# default 0
#
# -tempo is the duration between notes in milliseconds
# default0
#
# To test :
#
# .gadget-piano
# °plays a little music
# .gadget-piano "2A" 5000
# °plays a A note 5 seconds ... to tune your Stradivarius
# .gadget-piano (("1F# Z ")*5) 300
# °plays a F sharp and a silence 5 times
# .gadget-piano "1A 1B 1C 3A 3B 3C" 150 50
# °plays a sequence of notes, each one played 150 ms with
# an interval of 50 ms
#
# NOTE :
#
# You must have a pc speaker present and enabled
# to hear something :-)
#
#========Tested on PowerShell 1 RC2===========================#

param(
[string]$music='2C 2D 2E 2G 2F 2F 2A 2G 2G 3C 2B 3C 2G 2E 2C',
[int]$black 0,
[int]$tempo0
)

filter play-sound{
[console]::Beep([math]::Pow([math]::Pow(2,1/12),$_)*440,$black)
}

$notes=('C','C#','D','D#','E','F','F#','G','G#','A','A#','B')
$sounds=(-21..14)
$keyboards=(($sounds[0..11]),($sounds[12..23]),($sounds[24..35]))
$h=@{}

for($i=1;$i -lt 4;$i++)
{(0..11)|%{$h.Add("$i"+$notes[$_],$keyboards[$i-1][$_])}}

$music.Split(' ',[StringSplitOptions]::RemoveEmptyEntries)|%`
{
if($_ -eq 'Z'){Start-Sleep -m $black}
else{$h[$_]|play-sound $black}
Start-Sleep -m $tempo
}

#---8<---gadget-piano.ps1---Jean-JMST-Belgium---8<---

# Amicalement,

--
Jean - JMST
Belgium
Avatar
Jean
#---8<---gadget-morse.ps1---Jean-JMST-Belgium---8<---

#/2006==================================Version 0==========#
#================ plays a string in Morse ==================#
#
# *This script needs script gadget-piano.ps1 in its directory
# to work properly*
#
# To use :
#
# -text paremeter is a string containing the string to play.
#
# -dit paremeter is the duration in milliseconds of a "dit"
# default`
#
# -note paremeter is the (string) note used to play "dit" and
# "dah" Morse sounds
# default:
#
# -verbose switch writes words and Morse code in console.
#
# To test :
#
# .gadget-morse
# °plays a demo string
# .gadget-morse -verbose
# °plays a demo string and outputs words and Morse code
# .gadget-morse "Hello world" -verbose
# °plays "Hello world" in Morse and outputs words and code
# .gadget-morse "Hello world" 70 "1G"
# °plays "Hello world" with a Dit length of 70 ms and a G
# note to play Dit and Dah
#
# gadget-morse.ps1 is a demo script reusing this one
#
# NOTE :
#
# You must have a pc speaker present and enabled
# to hear something :-)
#
#========Tested on PowerShell 1 RC2===========================#

param(
[string]$text='PowerShell is powerful',
[int32]$dit`,
[string]$note='3A',
[switch]$verbose
)

filter play-morse{
[char[]]$_|%{
switch([string]$_){
- {
.gadget-piano $note ($dit*3) $dit
break
}
° {
.gadget-piano $note $dit $dit
break
}
}
}
}#end filter play-morse

$chars="abcdefghijklmnopqrstuvwxyz0123456789"+
".,?-äàéèöü`"!'/ñþç@`$:;=()"
$morse='°-','-°°°','-°-°','-°°','°','°°-°','--°',
'°°°°','°°','°---','-°-','°-°°','--','-°',
'---','°--°','--°-','°-°','°°°','-','°°-',
'°°°-','°--','-°°-','-°--','--°°','-----',
'°----','°°---','°°°--','°°°°-','°°°°°',
'-°°°°','--°°°','---°°','----°','°-°-°-',
'--°°--','°°--°°','-°°°°-','°-°-','°--°-',
'°°-°°','°-°°-','---°','°°--','°-°°-°',
'°°--°','°----°','-°°-°','--°--','°--°°',
'-°-°°','°--°-°','°°°-°°-','---°°°','-°-°-°',
'-°°°-','-°--°-','-°--°-'
$h=@{}
if($chars.Length -ne $morse.Length){'LIST ERROR';exit}
for($i=0;$i -lt $chars.Length;$i++)
{$h.Add([string]$chars[$i],$morse[$i])}

$text.split()|%{
if($verbose){"<$_>"}
[char[]]$_|%{
if($verbose){$h[[string]$_]}
$h[[string]$_]|play-morse
.gadget-piano 'Z' ($dit*2) 0
}
if($verbose){"</$_>"}
.gadget-piano 'Z' ($dit*4) 0
}
#---8<---gadget-morse.ps1---Jean-JMST-Belgium---8<---

# Amicalement,

--
Jean - JMST
Belgium
Avatar
Méta-MCI
Gaffe ! Si on te pique ta chaise, tu seras obligé de scripter du piano
debout...
Avatar
Jean
Gaffe ! Si on te pique ta chaise, tu seras obligé de scripter du piano
debout...


Merci pour le retour d'info.
J'ai demandé à quelques valets de boulonner mon trône :O)

Amicalement,

--
Jean - JMST
Belgium

Avatar
Jean
* gadget-piano.ps1 * : version 1 : possibilité de jouer des croches,
blanches, etc ...


#---8<---gadget-piano.ps1---Jean-JMST-Belgium---8<---

#=9/2006===================================Version 1==========#
#=========== "human hearable" string music notes ============#
#
# To use :
#
# -music paremeter is a string containing music notes separated
# by a space.
#
# A simplified abc notation is used.
# A music note begins with the keyboard's ocatve used (1, 2 or 3)
# followed by a character music note (from C to B) + eventually
# a # character indicating an half tone higher (sharp), so :
#
# 2F# is music note F sharp played on the second piano
# keyboard's octave.
#
# Values allowed for notes :
# C,C#,D,D#,E,F,F#,G,G#,A,A# and B
# preceded by 1,2 or 3
#
# A silence is marked with a Z.
#
# To multiply a note duration, ie $black*2 : 3C2
# To divide a note duration, ie $black/4 : 3C/4
#
# -black is the duration in millisecond a note is played
# default 0
#
# -tempo is the duration between notes in milliseconds
# default0
#
# To test :
#
# .gadget-piano
# °plays a little music
# .gadget-piano "2A" 5000
# °plays a A note 5 seconds ... to tune your Stradivarius
# .gadget-piano (("1F# Z ")*5) 300
# °plays a F sharp and a silence 5 times
# .gadget-piano "1A 1B 1C 3A 3B 3C" 150 50
# °plays a sequence of notes, each one played 150 ms with
# an interval of 50 ms
#
# NOTE :
#
# You must have a pc internal speaker present and enabled
# to hear something :-)
#
#========Tested on PowerShell 1 RC2===========================#

param(
[string]$music='2C 2D 2E 2G 2F 2F 2A 2G 2G 3C 2B 3C 2G 2E 2C',
[int]$black 0,
[int]$tempo0
)

filter play-sound{
[console]::Beep(
[math]::Pow([math]::Pow(2,1/12),$_)*440,
$black*$ratio
)
}

$oldOFS=$OFS
$OFS=''

$notes=('C','C#','D','D#','E','F','F#','G','G#','A','A#','B')
$sounds=-21..14
$keyboards=(($sounds[0..11]),($sounds[12..23]),($sounds[24..35]))
$h=@{}

for($i=1;$i -lt 4;$i++)
{0..11|%{$h.Add("$i"+$notes[$_],$keyboards[$i-1][$_])}}
[regex]$r='(d)?([A-GZ])(#)?(/)?(d)?(-)?'
$music.Split(' ',[StringSplitOptions]::RemoveEmptyEntries)|%`
{
if($_ -match $r){
$ratio=1
if($matches[4] -and $matches[5])
{$ratio=invoke-expression ('1'+[string]$matches[4..5])}
elseif($matches[5])
{$ratio=invoke-expression ('1*'+[string]$matches[5])}
if($matches[2] -eq 'Z'){Start-Sleep -m ($black*$ratio)}
else{
$note=$h[[string]($matches[1..3])]
$note|play-sound
}
if(!$matches[6]){Start-Sleep -m $tempo}
}
}
$OFS=$oldOFS
#---8<---gadget-piano.ps1---Jean-JMST-Belgium---8<---

#Amicalement,

--
Jean - JMST
Belgium

Avatar
Jean
* gadget-piano.ps1 * : version 1


pour tester : Karaoke-Windows-PowerShell-Fight-Song.PS1

Je poste le script en réponse à ce message

Amicalement,

--
Jean - JMST
Belgium

Avatar
Jean
Je poste le script en réponse à ce message


#---8<---Karaoke-Windows-PowerShell-Fight-Song.PS1---
#---Jean-JMST-Belgium---

#=9/2006===================================Version 1==========#
#
# This file needs gadget-piano.ps1 version 1
#
#========Tested on PowerShell 1 RC2===========================#

$s='2B2 2A# 2B',
'3C/2 3C 2B/2 3C2',
'3C/2 3C 3C/2 2B 3C',
'3D/2 3D 3C#/2 3D2',
'3E 3G 3F 3E',
'3D 2B 2G2',
'2B/2 2A 2G#/2 2B/2 2A',
'2G# 2A 3D2'

$s=$s*3

$t="Cheer,cher for",
"new Powershell",
"Command-line tools and",
"scripting as well",
"Pipe your objects",
"in and out",
"that's what this shell is",
"all about",
"Pipe, pipe, pipe",
"cmdlets",
"Pipe, pipe, pipe",
"cmdlets",
"DotNetFramework and",
"WMI",
"handles them",
"on the fly",
"Goodbye DOS",
"it's sure been swell",
"but I'm moving",
"to Powershell",
"C-M-D-dot",
"E-X-E,",
"PowerShell will make",
"you his-to-ry"

$end='2B/2 2B 2B/2 2A# 2B',
'3C/2 3C 2B/2 3C2',
'3C/2 3C 3C/2 2B 3C',
'3D/2 3D 3C#/2 3D2',
'3E 3G 3F 3E',
'3D 2B 2G 2A',
'2B/2 3D 3C/2 2B 2A',
'2G3 Z'

for($i=0;$i -lt $s.Length;$i++){
$t[$i]
.gadget-piano $s[$i]
}
$end|%{.gadget-piano $_}
#---8<---Karaoke-Windows-PowerShell-Fight-Song.PS1---

#Amicalement,

--
Jean - JMST
Belgium