Jump to content

MIDI UDF


eynstyne
 Share

Recommended Posts

@CyberZeroCool:

$dec = Dec("FFFF")  ;returns the number 65536
$result = Hex(1033, 4)  ;returns "0409"
so if I want to setup a for loop from 0x00401590 to 0x00406C90 how would I go about that. I'm terrible at hex, dec and bin is easy.

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Thanks for the help but I'm still not getting it to work, here's my code. I basically want to set one instrument and have it loop threw all the notes.

#include <midiudf.au3>
$open = _midiOutOpen()
$insturment = 70
_MidiOutShortMsg($open,256 * $insturment + 192)
For $i = 0x00401590 To 0x00406C90 Step 100
    _MidiOutShortMsg ($open, $i)
    Sleep(400)
Next
_MidiOutClose($open)

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

This works better for me:

#include <midiudf.au3>
$open = _midiOutOpen()
$instrument = 70
_MidiOutShortMsg ($open, 256 * $instrument + 192)
For $i = 0x00401590 To 0x00406C90 Step 256
   _MidiOutShortMsg ($open, $i)
   Sleep(200)
    _MidiOutShortMsg ($open, $i - 0x00400000)
Next
_MidiOutClose($open)

Edited by GMK
Link to comment
Share on other sites

This works better for me:

#include <midiudf.au3>
$open = _midiOutOpen()
$instrument = 70
_MidiOutShortMsg ($open, 256 * $instrument + 192)
For $i = 0x00401590 To 0x00406C90 Step 256
   _MidiOutShortMsg ($open, $i)
   Sleep(200)
    _MidiOutShortMsg ($open, $i - 0x00400000)
Next
_MidiOutClose($open)
Thanks, that did it.

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

How do you use the constants with the instruments?

I think each func should be called

PlayNote($midi,$Note,$instrument,$Duration=0)

and then have it so that if the duration is zero, then it will play the note until the "off" variable is called, otherwise, it only plays for the value set by duration.

and i refined the constants even more to make them easier:

;Midi Notes
;==========
Const $A0_ON                    =   0x00401590  ;1
Const $A0SHARP_ON           =   0x00401690  ;2
Const $B0_ON                    =   0x00401790  ;3
Const $C1_ON                    =   0x00401890  ;4
Const $C1SHARP_ON           =   0x00401990  ;5
Const $D1_ON                    =   0x00401A90  ;6
Const $D1SHARP_ON           =   0x00401B90  ;7
Const $E1_ON                    =   0x00401C90  ;8
Const $F1_ON                    =   0x00401D90  ;9
Const $F1SHARP_ON           =   0x00401E90  ;10
Const $G1_ON                    =   0x00401F90  ;11
Const $G1SHARP_ON           =   0x00402090  ;12
Const $A1_ON                    =   0x00402190  ;13
Const $A1SHARP_ON           =   0x00402290  ;14
Const $B1_ON                    =   0x00402390  ;15
Const $C2_ON                    =   0x00402490  ;16
Const $C2SHARP_ON           =   0x00402590  ;17
Const $D2_ON                    =   0x00402690  ;18
Const $D2SHARP_ON           =   0x00402790  ;19
Const $E2_ON                    =   0x00402890  ;20
Const $F2_ON                    =   0x00402990  ;21
Const $F2SHARP_ON           =   0x00402A90  ;22
Const $G2_ON                    =   0x00402B90  ;23
Const $G2SHARP_ON           =   0x00402C90  ;24
Const $A2_ON                    =   0x00402D90  ;25
Const $A2SHARP_ON           =   0x00402E90  ;26
Const $B2_ON                    =   0x00402F90  ;27
Const $C3_ON                    =   0x00403090  ;28
Const $C3SHARP_ON           =   0x00403190  ;29
Const $D3_ON                    =   0x00403290  ;30
Const $D3SHARP_ON           =   0x00403390  ;31
Const $E3_ON                    =   0x00403490  ;32
Const $F3_ON                    =   0x00403590  ;33
Const $F3SHARP_ON           =   0x00403690  ;34
Const $G3_ON                    =   0x00403790  ;35
Const $G3SHARP_ON           =   0x00403890  ;36
Const $A3_ON                    =   0x00403990  ;37
Const $A3SHARP_ON           =   0x00403A90  ;38
Const $B3_ON                    =   0x00403B90  ;39
Const $C4_ON                    =   0x00403C90  ;40 - Middle C
Const $C4SHARP_ON           =   0x00403D90  ;41
Const $D4_ON                    =   0x00403E90  ;42
Const $D4SHARP_ON           =   0x00403F90  ;43
Const $E4_ON                    =   0x00404090  ;44
Const $F4_ON                    =   0x00404190  ;45
Const $F4SHARP_ON           =   0x00404290  ;46
Const $G4_ON                    =   0x00404390  ;47
Const $G4SHARP_ON           =   0x00404490  ;48
Const $A4_ON                    =   0x00404590  ;49
Const $A4SHARP_ON           =   0x00404690  ;50
Const $B4_ON                    =   0x00404790  ;51
Const $C5_ON                    =   0x00404890  ;52
Const $C5SHARP_ON           =   0x00404990  ;53
Const $D5_ON                    =   0x00404A90  ;54
Const $D5SHARP_ON           =   0x00404B90  ;55
Const $E5_ON                    =   0x00404C90  ;56
Const $F5_ON                    =   0x00404D90  ;57
Const $F5SHARP_ON           =   0x00404E90  ;58
Const $G5_ON                    =   0x00404F90  ;59
Const $G5SHARP_ON           =   0x00405090  ;60
Const $A5_ON                    =   0x00405190  ;61
Const $A5SHARP_ON           =   0x00405290  ;62
Const $B5_ON                    =   0x00405390  ;63
Const $C6_ON                    =   0x00405490  ;64
Const $C6SHARP_ON           =   0x00405590  ;65
Const $D6_ON                    =   0x00405690  ;66
Const $D6SHARP_ON           =   0x00405790  ;67
Const $E6_ON                    =   0x00405890  ;68
Const $F6_ON                    =   0x00405990  ;69
Const $F6SHARP_ON           =   0x00405A90  ;70
Const $G6_ON                    =   0x00405B90  ;71
Const $G6SHARP_ON           =   0x00405C90  ;72
Const $A6_ON                    =   0x00405D90  ;73
Const $A6SHARP_ON           =   0x00405E90  ;74
Const $B6_ON                    =   0x00405F90  ;75
Const $C7_ON                    =   0x00406090  ;76
Const $C7SHARP_ON           =   0x00406190  ;77
Const $D7_ON                    =   0x00406290  ;78
Const $D7SHARP_ON           =   0x00406390  ;79
Const $E7_ON                    =   0x00406490  ;80
Const $F7_ON                    =   0x00406590  ;81
Const $F7SHARP_ON           =   0x00406690  ;82
Const $G7_ON                    =   0x00406790  ;83
Const $G7SHARP_ON           =   0x00406890  ;84
Const $A7_ON                    =   0x00406990  ;85
Const $A7SHARP_ON           =   0x00406A90  ;86
Const $B7_ON                    =   0x00406B90  ;87
Const $C8_ON                    =   0x00406C90  ;88

;Turn Off
Const $A0_OFF                   =   0x00001590  ;1
Const $A0SHARP_OFF          =   0x00001690  ;2
Const $B0_OFF                   =   0x00001790  ;3
Const $C1_OFF                   =   0x00001890  ;4
Const $C1SHARP_OFF          =   0x00001990  ;5
Const $D1_OFF                   =   0x00001A90  ;6
Const $D1SHARP_OFF          =   0x00001B90  ;7
Const $E1_OFF                   =   0x00001C90  ;8
Const $F1_OFF                   =   0x00001D90  ;9
Const $F1SHARP_OFF          =   0x00001E90  ;10
Const $G1_OFF                   =   0x00001F90  ;11
Const $G1SHARP_OFF          =   0x00002090  ;12
Const $A1_OFF                   =   0x00002190  ;13
Const $A1SHARP_OFF          =   0x00002290  ;14
Const $B1_OFF                   =   0x00002390  ;15
Const $C2_OFF                   =   0x00002490  ;16
Const $C2SHARP_OFF          =   0x00002590  ;17
Const $D2_OFF                   =   0x00002690  ;18
Const $D2SHARP_OFF          =   0x00002790  ;19
Const $E2_OFF                   =   0x00002890  ;20
Const $F2_OFF                   =   0x00002990  ;21
Const $F2SHARP_OFF          =   0x00002A90  ;22
Const $G2_OFF                   =   0x00002B90  ;23
Const $G2SHARP_OFF          =   0x00002C90  ;24
Const $A2_OFF                   =   0x00002D90  ;25
Const $A2SHARP_OFF          =   0x00002E90  ;26
Const $B2_OFF                   =   0x00002F90  ;27
Const $C3_OFF                   =   0x00003090  ;28
Const $C3SHARP_OFF          =   0x00003190  ;29
Const $D3_OFF                   =   0x00003290  ;30
Const $D3SHARP_OFF          =   0x00003390  ;31
Const $E3_OFF                   =   0x00003490  ;32
Const $F3_OFF                   =   0x00003590  ;33
Const $F3SHARP_OFF          =   0x00003690  ;34
Const $G3_OFF                   =   0x00003790  ;35
Const $G3SHARP_OFF          =   0x00003890  ;36
Const $A3_OFF                   =   0x00003990  ;37
Const $A3SHARP_OFF          =   0x00003A90  ;38
Const $B3_OFF                   =   0x00003B90  ;39
Const $C4_OFF                   =   0x00003C90  ;40 - Middle C
Const $C4SHARP_OFF          =   0x00003D90  ;41
Const $D4_OFF                   =   0x00003E90  ;42
Const $D4SHARP_OFF          =   0x00003F90  ;43
Const $E4_OFF                   =   0x00000090  ;44
Const $F4_OFF                   =   0x00004190  ;45
Const $F4SHARP_OFF          =   0x00004290  ;46
Const $G4_OFF                   =   0x00004390  ;47
Const $G4SHARP_OFF          =   0x00004490  ;48
Const $A4_OFF                   =   0x00004590  ;49
Const $A4SHARP_OFF          =   0x00004690  ;50
Const $B4_OFF                   =   0x00004790  ;51
Const $C5_OFF                   =   0x00004890  ;52
Const $C5SHARP_OFF          =   0x00004990  ;53
Const $D5_OFF                   =   0x00004A90  ;54
Const $D5SHARP_OFF          =   0x00004B90  ;55
Const $E5_OFF                   =   0x00004C90  ;56
Const $F5_OFF                   =   0x00004D90  ;57
Const $F5SHARP_OFF          =   0x00004E90  ;58
Const $G5_OFF                   =   0x00004F90  ;59
Const $G5SHARP_OFF          =   0x00005090  ;60
Const $A5_OFF                   =   0x00005190  ;61
Const $A5SHARP_OFF          =   0x00005290  ;62
Const $B5_OFF                   =   0x00005390  ;63
Const $C6_OFF                   =   0x00005490  ;64
Const $C6SHARP_OFF          =   0x00005590  ;65
Const $D6_OFF                   =   0x00005690  ;66
Const $D6SHARP_OFF          =   0x00005790  ;67
Const $E6_OFF                   =   0x00005890  ;68
Const $F6_OFF                   =   0x00005990  ;69
Const $F6SHARP_OFF          =   0x00005A90  ;70
Const $G6_OFF                   =   0x00005B90  ;71
Const $G6SHARP_OFF          =   0x00005C90  ;72
Const $A6_OFF                   =   0x00005D90  ;73
Const $A6SHARP_OFF          =   0x00005E90  ;74
Const $B6_OFF                   =   0x00005F90  ;75
Const $C7_OFF                   =   0x00006090  ;76
Const $C7SHARP_OFF          =   0x00006190  ;77
Const $D7_OFF                   =   0x00006290  ;78
Const $D7SHARP_OFF          =   0x00006390  ;79
Const $E7_OFF                   =   0x00006490  ;80
Const $F7_OFF                   =   0x00006590  ;81
Const $F7SHARP_OFF          =   0x00006690  ;82
Const $G7_OFF                   =   0x00006790  ;83
Const $G7SHARP_OFF          =   0x00006890  ;84
Const $A7_OFF                   =   0x00006990  ;85
Const $A7SHARP_OFF          =   0x00006A90  ;86
Const $B7_OFF                   =   0x00006B90  ;87
Const $C8_OFF                   =   0x00006C90  ;88
Link to comment
Share on other sites

In addition, I believe there is an error with at least one constant.

It seems the $E4_OFF constant doesn't actually turn off the note.

Example script showing the problem:

$open = _MidiOutOpen()
_midiOutShortMsg($open,256 * 22 + 192) ; 22 plays Harmonica
_midioutshortmsg($open,$E4_ON)
sleep(1000) 
_midioutshortmsg($open,$E4_OFF);Note should end after 1 second
sleep(10000) ; Note plays for full script duration.
_midiOutclose($open)

Anyone want to help me make this easier to understand?

Link to comment
Share on other sites

  • 4 weeks later...

I made some modifications to clean up the code and make some of the constants easier to work with (IMO), plus added some items to the instruments section--categorized the instruments and added a partial drum note map.

Have you used MidiOutLongMsg?

I'm curious how one would pack midi bytes for use with this function and how to allocate large buffers for use as the $data argument.

Mac

Link to comment
Share on other sites

  • 3 weeks later...
  • 7 months later...

Finally got around to figuring out how to use this thing :) Turns out, it is actually really cool.

(I made some UDFs to make my life easier, I was getting about sick of typing "_midiOutShortMsg" )

Guess the song :(

Dim $Note[88][2] = [ _
[$A0_ON,$A0_OFF],[$A0SHARP_ON,$A0SHARP_OFF],[$B0_ON,$B0_OFF], _
[$C1_ON,$C1_OFF],[$C1SHARP_ON,$C1SHARP_OFF],[$D1_ON,$D1_OFF],[$D1SHARP_ON,$D1SHARP_OFF],[$E1_ON,$E1_OFF],[$F1_ON,$F1_OFF],[$F1SHARP_ON,$F1SHARP_OFF],[$G1_ON,$G1_OFF],[$G1SHARP_ON,$G1SHARP_OFF],[$A1_ON,$A1_OFF],[$A1SHARP_ON,$A1SHARP_OFF],[$B1_ON,$B1_OFF], _
[$C2_ON,$C2_OFF],[$C2SHARP_ON,$C2SHARP_OFF],[$D2_ON,$D2_OFF],[$D2SHARP_ON,$D2SHARP_OFF],[$E2_ON,$E2_OFF],[$F2_ON,$F2_OFF],[$F2SHARP_ON,$F2SHARP_OFF],[$G2_ON,$G2_OFF],[$G2SHARP_ON,$G2SHARP_OFF],[$A2_ON,$A2_OFF],[$A2SHARP_ON,$A2SHARP_OFF],[$B2_ON,$B2_OFF], _
[$C3_ON,$C3_OFF],[$C3SHARP_ON,$C3SHARP_OFF],[$D3_ON,$D3_OFF],[$D3SHARP_ON,$D3SHARP_OFF],[$E3_ON,$E3_OFF],[$F3_ON,$F3_OFF],[$F3SHARP_ON,$F3SHARP_OFF],[$G3_ON,$G3_OFF],[$G3SHARP_ON,$G3SHARP_OFF],[$A3_ON,$A3_OFF],[$A3SHARP_ON,$A3SHARP_OFF],[$B3_ON,$B3_OFF], _
[$C4_ON,$C4_OFF],[$C4SHARP_ON,$C4SHARP_OFF],[$D4_ON,$D4_OFF],[$D4SHARP_ON,$D4SHARP_OFF],[$E4_ON,$E4_OFF],[$F4_ON,$F4_OFF],[$F4SHARP_ON,$F4SHARP_OFF],[$G4_ON,$G4_OFF],[$G4SHARP_ON,$G4SHARP_OFF],[$A4_ON,$A4_OFF],[$A4SHARP_ON,$A4SHARP_OFF],[$B4_ON,$B4_OFF], _
[$C5_ON,$C5_OFF],[$C5SHARP_ON,$C5SHARP_OFF],[$D5_ON,$D5_OFF],[$D5SHARP_ON,$D5SHARP_OFF],[$E5_ON,$E5_OFF],[$F5_ON,$F5_OFF],[$F5SHARP_ON,$F5SHARP_OFF],[$G5_ON,$G5_OFF],[$G5SHARP_ON,$G5SHARP_OFF],[$A5_ON,$A5_OFF],[$A5SHARP_ON,$A5SHARP_OFF],[$B5_ON,$B5_OFF], _
[$C6_ON,$C6_OFF],[$C6SHARP_ON,$C6SHARP_OFF],[$D6_ON,$D6_OFF],[$D6SHARP_ON,$D6SHARP_OFF],[$E6_ON,$E6_OFF],[$F6_ON,$F6_OFF],[$F6SHARP_ON,$F6SHARP_OFF],[$G6_ON,$G6_OFF],[$G6SHARP_ON,$G6SHARP_OFF],[$A6_ON,$A6_OFF],[$A6SHARP_ON,$A6SHARP_OFF],[$B6_ON,$B6_OFF], _
[$C7_ON,$C7_OFF],[$C7SHARP_ON,$C7SHARP_OFF],[$D7_ON,$D7_OFF],[$D7SHARP_ON,$D7SHARP_OFF],[$E7_ON,$E7_OFF],[$F7_ON,$F7_OFF],[$F7SHARP_ON,$F7SHARP_OFF],[$G7_ON,$G7_OFF],[$G7SHARP_ON,$G7SHARP_OFF],[$A7_ON,$A7_OFF],[$A7SHARP_ON,$A7SHARP_OFF],[$B7_ON,$B7_OFF], _
[$C8_ON,$C8_OFF]]


;Song
$Open = _MidiOutOpen()
SetInstrument($Open,42);Chello


NoteOn($Open, 25)
Play($Open, 41, 400)
NoteOn($Open,32)
Play($Open, 44, 400)
NoteOff($Open,32)
NoteOn($Open,37)
Play($Open, 49, 400)
Play($Open, 44, 400)
Play($Open, 53, 400)
Play($Open, 44, 400)
Play($Open, 49, 400)
Play($Open, 44, 400)
NoteOff($Open, 25)
NoteOff($Open,37)
;===
NoteOn($Open, 25)
Play($Open, 41, 400)
NoteOn($Open,36)
Play($Open, 44, 400)
Noteoff($Open,36)
NoteOn($Open,41)
Play($Open, 48, 400)
Play($Open, 44, 400)
Play($Open, 53, 400)
Play($Open, 44, 400)
Play($Open, 48, 400)
Play($Open, 44, 400)
NoteOff($Open, 25)
NoteOff($Open,41)
;===
NoteOn($Open,25)
Play($Open, 41, 400)
NoteOn($Open,32)
Play($Open, 44, 400)
NoteOff($Open,32)
NoteOn($Open, 37)
Play($Open, 49, 400)
Play($Open, 44, 400)
NoteOFF($Open, 37)
NoteOn($Open, 37)
Play($Open, 53, 400)
Play($Open, 44, 400)
NoteOff($Open, 37)
NoteOn($Open, 37)
Play($Open, 49, 400)
Play($Open, 44, 400)
NoteOff($Open, 37)
NoteOff($Open, 25)
;===
NoteOn($Open, 29)
Play($Open, 41, 400)
NoteOn($Open, 36)
Play($Open, 44, 400)
Noteoff($Open, 36)
NoteOn($Open,41)
Play($Open, 48, 400)
NoteOff($Open, 41)
NoteOn($Open, 36)
Play($Open, 44, 400)
NoteOff($Open, 36)
NoteOn($Open,41)
Play($Open, 53, 800)
NoteOff($Open, 29)
NoteOff($Open,41)
_MidiOutClose($Open)
;end song


Func NoteOn($Handle, $NoteIdx)
    $Noteidx-=1
    _MidiOutShortMsg($Handle, $Note[$NoteIdx][0])
EndFunc

Func NoteOff($Handle, $NoteIdx)
    $NoteIdx-=1
    _MidiOutShortMsg($Handle, $Note[$NoteIdx][1])
Endfunc


Func Play($Handle, $Notes, $Duration); Can play Single notes or use arrays for chords
If Isarray($Notes) Then
    For $i in $Notes
    If $i > 87 then Return 0
    $i-=1
    _MidiOutShortMsg($Handle, $Note[$i][0])
    Next
    Sleep($Duration)
    For $i in $Notes
    $i-=1
    _MidiOutShortMsg($Handle, $Note[$i][1])
    Next
Else
    $Notes-=1
    _MidiOutShortMsg($Handle, $Note[$Notes][0])
    Sleep($Duration)
    _MidiOutShortMsg($Handle, $Note[$Notes][1])
EndIf
EndFunc

Func SetInstrument($Handle, $Instrument)
    _MidiOutShortMsg($Handle,256 * $Instrument + 192)
EndFunc
Edited by Paulie
Link to comment
Share on other sites

For this to work, goto the Midi udf and search and replace all the NOTEON with ON and all the NOTEOFF with OFF save as Midiudf.au3 in the autoit includes.

Then at the top Paulie`s script you can add

#include <midiudf.au3> :)

Good Job Paulie! :(

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Figure i'd show the chords :)

Dim $array1[6] = [45,47,51,57,59,63]
Dim $array2[6] = [44,47,52,56,59,64]
Play($Open, 52, 200)
Sleep(100)
Play($Open, 47, 100)
Play($Open, 46, 100)
Play($Open, 47, 100)
Play($Open, 48, 300)
Play($Open, 47, 300)
Sleep(100)
Play($Open, $array1, 600)
Play($Open, $array2, 1200)
Edited by Paulie
Link to comment
Share on other sites

  • 4 months later...

I've been trying to make a drummachine script that I can use my Rock Band Drumkit with. I'm having issues playing multiple drums/instruments at the same time. Anyone figured out how to do that?

for $i = 27 to 86
    _MidiOutShortMsg($open,0x99 + ($i * 256) + (127 * 0x10000)) ; Drums Bitch!
    _MidiOutShortMsg($open,0x99 + ($i+1 * 256) + (127 * 0x10000)) ; Drums Bitch!
    sleep(200)
    Next
Link to comment
Share on other sites

  • 6 months later...

I have a question... i am using this function to level up the volumen of my midis _MidiOutSetVolume (65535), 65535 is the highest value for that fuction. But if i compare my midi volumen with other software that play midi the volume of my script is lower.

Why is this happening?

Link to comment
Share on other sites

  • 3 weeks later...

I have a question... i am using this function to level up the volumen of my midis _MidiOutSetVolume (65535), 65535 is the highest value for that fuction. But if i compare my midi volumen with other software that play midi the volume of my script is lower.

Why is this happening?

help plz!!

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...