Let me introduce you to the AutoIt Hirajoshi Wind Chime. There are
Latest Version is in Post 11
#include 'MidiOutLite.au3' Global $open = _MidiOutOpen() ; $iChime - values range from 0 to 14 ; 0 .... Gong (CN) ..................... C D E G A C ; 1 .... Okinawa (JP) .................. C E F G B C ; 2 .... Insen (JP) .................... C Db F G Bb C ; 3 .... Nando-kyemyonjo (KR) .......... C D Eb F G C ; 4 .... Kata-kumoi (JP) ............... C D Eb F Ab C ; 5 .... Hirajoshi (JP) ................ C D Eb G Ab C ; 6 .... Chaio (CN) .................... C D F Ab Bb C ; 7 .... Ritsu (JP) .................... C Db Eb F Ab Bb C ; 8 .... Niagari (JP) .................. C Db F G Ab Bb C ; 9 .... Takemitsu Tree Line Mode 1 (JP) C D Eb Gb Ab B C ; 10 ... Takemitsu Tree Line Mode 2 (JP) C D Eb Gb Ab Bb C ; 11 ... P'yongio (KR) ................. C D F G A Bb C ; 12 ... Eskimo (1) .................... C D Eb F G Bb C ; 13 ... Eskimo (2) .................... C D E Gb Ab B C ; 14 ... Stravinsky .................... C Db Eb E F# G A Bb C HotKeySet("{ESC}", "_Quit") _AddLightBreeze(Random(0,14,1), 1) ; First param - Chime number 0 to 14 - see list. ; Second param - Randomise chimes 0 or 1. ; Third param Maximum calm in miliseconds. Func _AddLightBreeze($iChime, $iRandomise = 0, $iMaxCalm = 30000) Local $aChime = _LoadChime($iChime) Local $iRandomCalm, $iRandomNote, $iVolume = 65535, $iTranspose = 12 _MidiOutShortMsg($open,256 * 14 + 192) _MidiOutSetVolume() While 1 $iRandomNote = Random(0,7,1) _MidiOutshortmsg($open,$MIDINOTE[ $aChime[ $iRandomNote ] + $iTranspose ][0]) _MidiOutshortmsg($open,$MIDINOTE[ $aChime[ $iRandomNote ] + $iTranspose + 12 ][0]) ; Octave added. $iRandomCalm = Random(20,1000,1) If $iRandomCalm > 950 Then Sleep(Random(0,$iMaxCalm,1)) $iVolume = 65535 _MidiOutSetVolume() ElseIf $iRandomCalm > 750 Then Sleep(Int($iRandomCalm*Random(0.5,5))) $iVolume = Int($iVolume*1.2) If ($iVolume < 32768) Or ($iVolume > 65535) Then $iVolume = 65535 _MidiOutSetVolume($iVolume) Else Sleep(Random(50,500,1)) $iVolume = Int($iVolume*.9) If $iVolume < 6554 Then $iVolume = 32768 _MidiOutSetVolume($iVolume) EndIf If $iRandomise And Not Random(0, 10, 1) Then $aChime = _LoadChime(Random(0, 14, 1)) ; $iTranspose = Random(7, 18, 1) ; Optional - transposes the notes. EndIf WEnd EndFunc Func _LoadChime($iChime = 3) Local $aScale[15][8] = _ [[39,41,43,46,48,51,53,55], _ ; Gong [39,43,44,46,50,51,55,56], _ ; Okinawa [37,39,40,44,46,49,51,53], _ ; Insen [39,41,42,44,46,51,53,54], _ ; Nando-kyemyonjo [39,41,42,44,47,51,53,54], _ ; Kata-kumoi [39,41,42,46,47,51,53,54], _ ; Hirajoshi [37,39,41,44,46,49,51,53], _ ; Chaio [37,39,40,42,44,47,49,51], _ ; Ritsu [37,39,40,43,44,46,49,51], _ ; Niagari [39,41,42,45,47,50,51,53], _ ; Takemitsu Tree Line Mode 1 [37,39,41,42,45,47,49,51], _ ; Takemitsu Tree Line Mode 2 [39,41,44,46,48,49,51,53], _ ; P'yongio [37,39,41,42,44,46,49,51], _ ; Eskimo (1) [39,41,43,45,47,50,51,53], _ ; Eskimo (2) [40,41,43,44,46,47,49,50]] ; Stravinsky Local $aTemp[8] For $i = 0 To 7 $aTemp[$i] = $aScale[$iChime][$i] Next Return $aTemp EndFunc Func _Quit() Sleep(1000) ; Allow the volume to fade a little before closing. _MidiOutSetVolume() _MidiOutclose($open) Exit EndFunc
Credit must go to Eynstyne and Ascend4nt for the functions in the following script.
MidiOutLite.au3
; This code is a minimalistic version of Ascend4nt's adaptation of the original midi UDF by Eynstyne. ; For the original source and a full description of all midi constants (including instruments): see => ; http://www.autoitscript.com/forum/topic/37072-midi-udf/page__view__findpost__p__810725 ; The selected functions are for midi output only, so any musical input needs to be hard coded. ; The midi note values are now stored in a 2D array, as opposed to using individual constants. ; One line of code has been added to _MidiOutSetVolume to ensure equal output on both speakers. ; Default midi volume has been set to maximum. Const $MIDINOTE[88][2] = [ _ ; [?][0] = Play, [?][1] = Stop [0x00401590,0x00001590], _ ; [0][?] .... A [0x00401690,0x00001690], _ ; [1][?] .... Bb [0x00401790,0x00001790], _ ; [2][?] .... B [0x00401890,0x00001890], _ ; [3][?] .... C First Octave [0x00401990,0x00001990], _ ; [4][?] .... Db [0x00401A90,0x00001A90], _ ; [5][?] .... D [0x00401B90,0x00001B90], _ ; [6][?] .... Eb [0x00401C90,0x00001C90], _ ; [7][?] .... E [0x00401D90,0x00001D90], _ ; [8][?] .... F [0x00401E90,0x00001E90], _ ; [9][?] .... Gb [0x00401F90,0x00001F90], _ ; [10][?] ... G [0x00402090,0x00002090], _ ; [11][?] ... Ab [0x00402190,0x00002190], _ ; [12][?] ... A [0x00402290,0x00002290], _ ; [13][?] ... Bb [0x00402390,0x00002390], _ ; [14][?] ... B [0x00402490,0x00002490], _ ; [15][?] ... C Second Octave [0x00402590,0x00002590], _ ; [16][?] ... Db [0x00402690,0x00002690], _ ; [17][?] ... D [0x00402790,0x00002790], _ ; [18][?] ... Eb [0x00402890,0x00002890], _ ; [19][?] ... E [0x00402990,0x00002990], _ ; [20][?] ... F [0x00402A90,0x00002A90], _ ; [21][?] ... Gb [0x00402B90,0x00002B90], _ ; [22][?] ... G [0x00402C90,0x00002C90], _ ; [23][?] ... Ab [0x00402D90,0x00002D90], _ ; [24][?] ... A [0x00402E90,0x00002E90], _ ; [25][?] ... Bb [0x00402F90,0x00002F90], _ ; [26][?] ... B [0x00403090,0x00003090], _ ; [27][?] ... C Third Octave [0x00403190,0x00003190], _ ; [28][?] ... Db [0x00403290,0x00003290], _ ; [29][?] ... D [0x00403390,0x00003390], _ ; [30][?] ... Eb [0x00403490,0x00003490], _ ; [31][?] ... E [0x00403590,0x00003590], _ ; [32][?] ... F [0x00403690,0x00003690], _ ; [33][?] ... Gb [0x00403790,0x00003790], _ ; [34][?] ... G [0x00403890,0x00003890], _ ; [35][?] ... Ab [0x00403990,0x00003990], _ ; [36][?] ... A [0x00403A90,0x00003A90], _ ; [37][?] ... Bb [0x00403B90,0x00003B90], _ ; [38][?] ... B [0x00403C90,0x00003C90], _ ; [39][?] ... C Fourth Octave - Middle C [0x00403D90,0x00003D90], _ ; [40][?] ... Db [0x00403E90,0x00003E90], _ ; [41][?] ... D [0x00403F90,0x00003F90], _ ; [42][?] ... Eb [0x00404090,0x00004090], _ ; [43][?] ... E [0x00404190,0x00004190], _ ; [44][?] ... F [0x00404290,0x00004290], _ ; [45][?] ... Gb [0x00404390,0x00004390], _ ; [46][?] ... G [0x00404490,0x00004490], _ ; [47][?] ... Ab [0x00404590,0x00004590], _ ; [48][?] ... A [0x00404690,0x00004690], _ ; [49][?] ... Bb [0x00404790,0x00004790], _ ; [50][?] ... B [0x00404890,0x00004890], _ ; [51][?] ... C Fifth Octave [0x00404990,0x00004990], _ ; [52][?] ... Db [0x00404A90,0x00004A90], _ ; [53][?] ... D [0x00404B90,0x00004B90], _ ; [54][?] ... Eb [0x00404C90,0x00004C90], _ ; [55][?] ... E [0x00404D90,0x00004D90], _ ; [56][?] ... F [0x00404E90,0x00004E90], _ ; [57][?] ... Gb [0x00404F90,0x00004F90], _ ; [58][?] ... G [0x00405090,0x00005090], _ ; [59][?] ... Ab [0x00405190,0x00005190], _ ; [60][?] ... A [0x00405290,0x00005290], _ ; [61][?] ... Bb [0x00405390,0x00005390], _ ; [62][?] ... B [0x00405490,0x00005490], _ ; [63][?] ... C Sixth Octave [0x00405590,0x00005590], _ ; [64][?] ... Db [0x00405690,0x00005690], _ ; [65][?] ... D [0x00405790,0x00005790], _ ; [66][?] ... Eb [0x00405890,0x00005890], _ ; [67][?] ... E [0x00405990,0x00005990], _ ; [68][?] ... F [0x00405A90,0x00005A90], _ ; [69][?] ... Gb [0x00405B90,0x00005B90], _ ; [70][?] ... G [0x00405C90,0x00005C90], _ ; [71][?] ... Ab [0x00405D90,0x00005D90], _ ; [72][?] ... A [0x00405E90,0x00005E90], _ ; [73][?] ... Bb [0x00405F90,0x00005F90], _ ; [74][?] ... B [0x00406090,0x00006090], _ ; [75][?] ... C Seventh Octave [0x00406190,0x00006190], _ ; [76][?] ... Db [0x00406290,0x00006290], _ ; [77][?] ... D [0x00406390,0x00006390], _ ; [78][?] ... Eb [0x00406490,0x00006490], _ ; [79][?] ... E [0x00406590,0x00006590], _ ; [80][?] ... F [0x00406690,0x00006690], _ ; [81][?] ... Gb [0x00406790,0x00006790], _ ; [82][?] ... G [0x00406890,0x00006890], _ ; [83][?] ... Ab [0x00406990,0x00006990], _ ; [84][?] ... A [0x00406A90,0x00006A90], _ ; [85][?] ... Bb [0x00406B90,0x00006B90], _ ; [86][?] ... B [0x00406C90,0x00006C90]] ; [87][?] ... C Eighth Octave ;======================================================= ;Retrieves a MIDI handle and Opens the Device ;Parameters(Optional) - Device ID, Window Callback, ; instance, flags ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutOpen($devid = 0, $callback = 0, $instance = 0, $flags = 0) Local $ret = DllCall("winmm.dll", "long", "midiOutOpen", "handle*", 0, "int", $devid, "dword_ptr", $callback, "dword_ptr", $instance, "long", $flags) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[1] EndFunc ;==>_MidiOutOpen ;======================================================= ;======================================================= ;Closes Midi Output/Input devices ;Parameters - MidiHandle ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutClose ($hmidiout) Local $ret = DllCall("winmm.dll", "long", "midiOutClose", "handle", $hmidiout) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==>_MidiOutClose ;======================================================= ;Gets the Mixer Volume for MIDI ;Parameters - None ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutGetVolume ($devid = 0) Local $ret = DllCall("winmm.dll", "long", "midiOutGetVolume", "handle", $devid, "dword*",0) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[2] EndFunc ;==>_MidiOutGetVolume ;======================================================= ;Sets the Mixer Volume for MIDI ;Parameters - Volume (0 - 65535) ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutSetVolume($iVolume = 65535, $devid = 0) Local $iMixVolume=BitAND($iVolume,0xFFFF)+BitShift(BitAND($iVolume,0xFFFF),-16) ; From Ascend4nt Local $ret = DllCall("winmm.dll", "long", "midiOutSetVolume", "handle", $devid, "int", $iMixVolume) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==> _MidiOutSetVolume ;======================================================= ;MIDI Message Send Function ;Parameters - Message as Hexcode or Constant ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutShortMsg($hmidiout, $msg) Local $ret = DllCall("winmm.dll", "long", "midiOutShortMsg", "handle", $hmidiout, "long", $msg) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==>_MidiOutShortMsg
Edited by czardas, 14 June 2012 - 08:19 PM.








