; eynstyne
; http://www.autoitscript.com/forum/topic/37072-midi-udf/page__view__findpost__p__810725
#include <Midiudf.au3>
$openmidi = _MidiOutopen()
If @error Then
	MsgBox(0, "Ошибка", "MIDI-устройство занято другим приложением")
	Exit
EndIf

Global $nTempo = 1
Global $iTone = 12
Global $iVolume = 127

_Set_Instrument($openmidi, 21) ; выбор музыкального инструмента 1-128

_PlayNote(8, 4, 100)
_PlayNote(7, 4, 100)
_PlayNote(8, 4, 100)
_PlayNote(9, 4, 100)
_PlayNote(8, 4, 100, 100)
_PlayNote(1, 5, 100, 100)

_PlayNote(8, 4, 100)
_PlayNote(7, 4, 100)
_PlayNote(8, 4, 100)
_PlayNote(9, 4, 100)
_PlayNote(8, 4, 100, 100)
_PlayNote(12, 4, 100, 100)

_PlayNote(8, 4, 100)
_PlayNote(7, 4, 100)
_PlayNote(8, 4, 100)
_PlayNote(9, 4, 100)
_PlayNote(8, 4, 100)

_PlayNote(6, 5, 100)
_PlayNote(3, 5, 100)
_PlayNote(12, 4, 100)
_PlayNote(8, 4, 100)
_PlayNote(6, 4, 100)
_PlayNote(5, 4, 100)
_PlayNote(4, 4, 200, 300)

_MidiOutClose($openmidi)

Func _PlayNote($iNote, $iOctave = 4, $iDuration = 200, $iPause = 0)
	$iNote = $iNote + $iTone + 12 * $iOctave
	_MidiOutShortMsg($openmidi, 0x90 + ($iNote * 256) + ($iVolume * 0x10000))
	Sleep($iDuration / $nTempo)
	_MidiOutShortMsg($openmidi, 0x90 + ($iNote * 256) + (0 * 0x10000))
	If $iPause <> 0 Then Sleep($iPause / $nTempo)
EndFunc

Func _Set_Instrument($openmidi, $inct)
	_MidiOutShortMsg($openmidi, 256 * $inct + 192)
EndFunc