Jump to content

MIDI UDF


eynstyne
 Share

Recommended Posts

Example 1

;  @AZJIO
; Europe
#include <Midiudf.au3>
$open = _midiOutOpen ()

Global $t=0.7 ; tempo
Global $Tone=0
Global $volume=127 ; Level 0-127
HotKeySet('{ESC}', "_Quit") ; ESC - Exit


SetInstrument($open, 29) ; Musical instrument choice
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)

_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,200)


_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)

_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,200)


_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)

_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,200)



_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(10,5,100)
_Beep(8,5,100)
_Beep(7,5,100)
_Beep(10,5,100)
_Beep(8,5,100)
_Beep(7,5,100)
_Beep(3,5,100)
_Beep(5,5,600)
_Beep(8,5,90,10)
_Beep(8,5,90,10)
_Beep(8,5,190,10)
_Beep(7,5,50)
_Beep(8,5,50)
_Beep(7,5,100)
_Beep(5,5,200)
_Beep(3,5,190,10)
_Beep(3,5,390,10)
_Beep(2,5,390,10)
_Beep(12,4,390,10)
_Beep(10,4,390,10)

_Beep(12,5,390,10)
_Beep(10,5,100)
_Beep(7,5,100)
_Beep(10,5,100)
_Beep(7,5,200)
_Beep(12,5,100)
_Beep(10,5,100)
_Beep(7,5,100)
_Beep(9,5,100)
_Beep(5,5,100)
_Beep(7,5,190,10)
_Beep(7,5,100)
_Beep(5,5,100)
_Beep(3,5,100)
_Beep(12,4,100)
_Beep(5,5,100)
_Beep(12,4,100)
_Beep(3,5,100)
_Beep(5,5,890,10)



_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,100)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(12,5,50)
_Beep(3,6,50)
_Beep(7,6,200)


_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,100)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(2,6,50)
_Beep(5,6,50)
_Beep(8,6,200)


_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,100)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(3,6,50)
_Beep(7,6,50)
_Beep(10,6,200)


_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(8,5,100)
_Beep(10,5,100)
_Beep(12,5,100)
_Beep(10,5,100)
_Beep(8,5,100)
_Beep(7,5,100)
_Beep(10,5,100)
_Beep(8,5,100)
_Beep(7,5,100)
_Beep(3,5,100)
_Beep(5,5,600)
_Beep(8,5,90,10)
_Beep(8,5,90,10)
_Beep(8,5,190,10)
_Beep(7,5,100)

_Beep(8,5,50)
_Beep(7,5,50)
_Beep(5,5,200)
_Beep(3,5,200)

_Beep(12,5,390,10)
_Beep(10,5,390,10)
_Beep(3,5,390,10)
_Beep(5,5,390,10)
_Beep(7,5,1590,10)
_Beep(9,5,600)
_Beep(12,5,200)
_Beep(9,5,800)


Func _Beep($nota,$octave=4,$Duration=200,$pause=0)
$nota=$nota+$Tone+12*$octave
_MidiOutShortMsg($open, 0x90 + ($nota   * 256) + ($volume * 0x10000)) ; Play
Sleep($Duration/$t)
_MidiOutShortMsg($open, 0x90 + ($nota   * 256) + (0 * 0x10000)) ; Stop (Level=0)
If $pause<>0 Then Sleep($pause/$t)
EndFunc

Func SetInstrument($open, $inct) ; Musical instrument choice
    _MidiOutShortMsg($open,256 * $inct + 192)
EndFunc

Func _Quit()
    Exit
EndFunc

Example 2

;  @AZJIO
; Heavy Asia
#include <Midiudf.au3>
$open = _midiOutOpen ()

Global $t=1 ; tempo
Global $Tone=0
Global $volume=127 ; Level 0-127
HotKeySet('{ESC}', "_Quit") ; ESC - Exit


SetInstrument($open, 90) ; Musical instrument choice

_Beep(5,5,130)
_Beep(7,5,130)
_Beep(11,5,130)
_Beep(7,5,130)
_Beep(11,5,130)
_Beep(12,5,130)
_Beep(11,5,450,70)
_Beep(7,5,130,130)
_Beep(7,5,130)
_Beep(5,5,250,130)
_Beep(7,5,260)
_Beep(5,5,65,65)
_Beep(7,5,260)
_Beep(5,5,65,65)
_Beep(7,5,86,130)
_Beep(7,5,65,65)
_Beep(8,5,65,65)
_Beep(8,5,130,130)
_Beep(8,5,170,350)

_Beep(5,5,130)
_Beep(7,5,130)
_Beep(11,5,130)
_Beep(7,5,130)
_Beep(11,5,130)
_Beep(12,5,130)
_Beep(11,5,390)
_Beep(12,5,86)
_Beep(11,5,43)
_Beep(7,5,130,130)
_Beep(7,5,130)
_Beep(5,5,250,130)
_Beep(7,5,260)
_Beep(5,5,65,65)
_Beep(7,5,260)
_Beep(5,5,65,65)
_Beep(5,5,170,86)
_Beep(7,5,65,65)
_Beep(8,5,65,65)
_Beep(8,5,130,130)
_Beep(8,5,170,350)

SetInstrument($open, 30)
_Beep(7,3,130,130)
_Beep(7,3,170,86)
_Beep(5,3,86,43)
_Beep(7,3,217,43)
_Beep(5,3,86,43)
_Beep(7,3,170,86)
_Beep(7,3,216,434)

_Beep(5,3,86,43)
_Beep(7,3,130,130)
_Beep(7,3,170,86)
_Beep(5,3,86,43)
_Beep(7,3,217,43)
_Beep(5,3,86,43)
_Beep(7,3,170,86)
_Beep(7,3,217,43)

_Beep(8,3,43,86)
_Beep(8,3,43,86)
_Beep(8,3,43,86)
_Beep(8,3,43,86)

_Beep(7,3,130,130)
_Beep(7,3,170,86)
_Beep(5,3,86,43)
_Beep(7,3,217,43)
_Beep(5,3,86,43)
_Beep(7,3,170,86)
_Beep(7,3,216,434)

_Beep(5,3,86,43)
_Beep(7,3,130,130)
_Beep(7,3,170,86)
_Beep(5,3,86,43)
_Beep(7,3,217,43)
_Beep(5,3,86,43)
_Beep(7,3,170,86)
_Beep(7,3,217,43)

_Beep(8,3,520)


_Beep(12,3,390)
_Beep(7,4,390)
_Beep(6,4,520)
_Beep(5,4,450)
_Beep(3,4,330)

_Beep(12,3,390)
_Beep(7,4,390)
_Beep(6,4,520)
_Beep(5,4,450)
_Beep(3,4,330)

_Beep(5,3,390)
_Beep(12,3,390)
_Beep(11,3,520)
_Beep(10,3,450)
_Beep(8,3,330)

_Beep(5,3,390)
_Beep(12,3,390)
_Beep(11,3,520)
_Beep(10,3,450)
_Beep(8,3,330)


Func _Beep($nota,$octave=4,$Duration=200,$pause=0)
$nota=$nota+$Tone+12*$octave
_MidiOutShortMsg($open, 0x90 + ($nota   * 256) + ($volume * 0x10000)) ; Play
Sleep($Duration/$t)
_MidiOutShortMsg($open, 0x90 + ($nota   * 256) + (0 * 0x10000)) ; Stop (Level=0)
If $pause<>0 Then Sleep($pause/$t)
EndFunc

Func SetInstrument($open, $inct) ; Musical instrument choice
    _MidiOutShortMsg($open,256 * $inct + 192)
EndFunc

Func _Quit()
    Exit
EndFunc

netegg

only v3.3.0.0

Edited by AZJIO
Link to comment
Share on other sites

Nothing in WIN7

netegg

only v3.3.0.0

It is true that the midiUDF doesn't work with newer versions of AutoIt without modification, but that modification is very easy to do.

In the midiUDF, udword's are being used, these were removed from AutoIt because a dword is already unsigned. You can either get it working by replacing all the 'udword' with 'UINT64' or getting the attached udf that is corrected and works with newer versions of AutoIt. Get Ascend4nt's modified version of the udf.

MidiExample.au3 ;An example I created that uses the midiudf.

midiMapping.au3 ;Maps keyboard keys to notes that way you can play using your keyboard.

Hopefully this helps,

Disabled Monkey

Edit:

Removed my attached udf, use Ascend4nt's attached below.

Edited my MidiExample to use Ascend4nt's udf

Edited midiMapping to actually have function that maps keyboard automatically. _KeyboardAsMidiOn() to turn on, _KeyboardAsMidiOff() to turn off.

Edited by DisabledMonkey
Link to comment
Share on other sites

Looks like I wasn't the only one interested in working on this.

DisabledMonkey, dword and uint64 aren't the same size (the first is 32-bit, the 2nd is 64-bit).

Now, on to the changes I did, because this project shouldn't die! (from the top of Midiudf.au3):
 

; *Altered by GMK -> cleanup of code, Constants 'cleanup', addition of Drum Map
; *Alterations by Ascend4nt:
;   - Changed '_NOTEON/OFF' to _ON or _OFF per suggestion by Paulie
;   - @error checks/returns fixed (still some consistency needed in the module overall though)
;   - x64 compatibility & Structure fixes
;   - Addition of functions: _MidiOutPrepareHeader, _MidiOutUnprepareHeader, _MidiStreamOut
; (Still unclear as to MIDI buffer setup, and how _MidiStreamProperty should be called)
;   - fixed 'PrepareHeader' and 'UnprepareHeader' functions, and other functions that
; require a 'Prepared' Header (see function definitions for which require it)
; (Note: 'PrepareHeader' returns a structure, which must be passed (by reference) to these functions)
;   - fixed 'PrepareHeader' to make buffer part of structure (otherwise buffer is lost on function exit)
; (all functions updated to calculate size of structure based on this new format)
;   - added short structure definition for MIDI data..
;   - fixed $E4_OFF value (thx czardas)

*tested on v3.3.6.0 in XP, Vista x86 and x64, and Windows 7

*edit: updated 6/25/2010 (further fixes - most calls should work if you follow the 'PrepareHeader' logic (and if you can figure out how to set up buffers and MIDI data!))
*update 5/19/2011 - fixed $E4_OFF constant value (boo copy & paste) - thx czardas

UPDATE 2013-08-16:  >MIDIEx UDF released, with a LOT more functionality, including almost full control of MIDI messages

Prev. Downloads: 292

Midiudf.au3

Edited by Ascend4nt
Link to comment
Share on other sites

  • 1 month later...

Hi, I'm looking for a simple example how to receive a midi message from an external midi device. In my case it is a foot controller...

I'm able to send messages but I cant get the midi in to work... have tried this post "http://www.autoitscript.com/forum/index.php?showtopic=89944&st=0&p=647010&hl=midi%20input&fromsearch=1&#entry647010" but it doesnt work.

So if anyone have an actual au3 example how midi in should work then it would be great if you could share it.

Br.

Johan

Link to comment
Share on other sites

Hi, I'm looking for a simple example how to receive a midi message from an external midi device. In my case it is a foot controller...

I'm able to send messages but I cant get the midi in to work... have tried this post "http://www.autoitscript.com/forum/index.php?showtopic=89944&st=0&p=647010&hl=midi%20input&fromsearch=1&#entry647010" but it doesnt work.

So if anyone have an actual au3 example how midi in should work then it would be great if you could share it.

Br.

Johan

Jesus!! I was still using the old udf... it works perfect with the new one...

for a little while I almost thought that my brain was stupid...

Sorry!!

Link to comment
Share on other sites

  • 1 month later...

That is not Midi ;) , it's just a Beep. i'm searching for some examples of a working midi input, because i cannot make this working (note that there is also a large parte in which the script detects devices and writes informations):

#include <Array.au3>
#include <MidiUDF.au3>

HotKeySet("{ESC}", "ExitProgram")
ConsoleWrite("1-Manufacturer ID; 2-Product ID; 3-Driver Version; 4-Driver Name; 5-Type of Device; 6-Voices; 7-Notes; 8-Channel Mask; 9-Capabilities;")
ConsoleWrite(@CRLF)
    $NumInputDev = _MidiInGetNumDevsUser()
    If $NumInputDev > 0 Then
        ConsoleWrite ("Number of input devices detected = " & $NumInputDev&" :"& @CRLF)
        For $i = 1 to $NumInputDev
            $DevInfo = _MidiInGetDevCaps($i-1)
            ConsoleWrite ($DevInfo[0] & "   " & $DevInfo[1] & "   " & $DevInfo[2] & "   " & $DevInfo[3] & @crlf)
        Next
        $DevInfo = 0
    Else
        ConsoleWrite ("No input devices are detected."& @CRLF & @CRLF)
    EndIf
    ConsoleWrite(@CRLF)
trova il numero di devices input e ne stampa le informazioni
    $NumOutputDev = _MidiOutGetNumDevsUser()
    If $NumOutputDev > 0 Then
        ConsoleWrite ("Number of output devices detected = " & $NumOutputDev&" :"& @CRLF)
        For $i = 1 to $NumOutputDev
            $DevInfo = _MidiOutGetDevCaps($i-1)
            ConsoleWrite ($DevInfo[0]&"   "&$DevInfo[1]&"   "&$DevInfo[2]&"   "&$DevInfo[3]&"   "&$DevInfo[4]&"   "&$DevInfo[5]&"   "&$DevInfo[6]&"   "&$DevInfo[7]&"   "&$DevInfo[8]&@crlf)
        Next
    Else
        ConsoleWrite ("No input devices are detected."& @CRLF & @CRLF)
    EndIf
    ConsoleWrite(@CRLF)

;here is the part which i cant get to work
$DllHandle = DLLCallbackRegister ("MidiInProcess", "long", "ptr;int;dword;dword;dword")
;ConsoleWrite("DllPointer:   "&$DllPointer&@CRLF)
$CallbackPointer = DllCallbackGetPtr($DllHandle)
$MidiInHandle = _MidiInOpen(0, $CallbackPointer, 0, $callback_function)
ConsoleWrite("MidiInHandle: "&$MidiInHandle&@CRLF)
_MidiInReset($MidiInHandle)
_MidiInStart($MidiInHandle)

While 1
WEnd

Func MidiInProcess($midi, $msg,$instance,$Param1,$Param2)
    ConsoleWrite($midi&"  "&$msg&"  "&$instance&"  "&$Param1&"  "&$Param2&@CRLF)
EndFunc

#cs
this is just an example of a MidiOutShortMsg
$MidiInHandle = _MidiOutOpen(4)

$midimsg = 144+BitShift(60, -8)+BitShift(100, -16)
_MidiOutShortMsg($MidiInHandle, $midimsg)

$var = _MidiOutClose($MidiInHandle)
#CE

;::::::::::::::::::::::::::::FUNCTIONS:::::::::::::::::::
Func ExitProgram()
    _MidiInClose($MidiInHandle)
    DllCallbackFree($DllHandle)
        Exit
EndFunc

;=======================================================
;Retrieves the number of Midi Output devices which exist
Func _MidiOutGetNumDevsUser()
   $var = DllCall("winmm.dll", "long", "midiOutGetNumDevs")
   Return $var[0]
EndFunc   ;=============================================


;=======================================================
;Returns the number of Midi Input devices which exist
Func _MidiInGetNumDevsUser()
   $var = DllCall("winmm.dll", "long", "midiInGetNumDevs")
   Return $var[0]
EndFunc ;===============================================
Link to comment
Share on other sites

Hi,

plese correct

$DllHandle = DLLCallbackRegister ("MidiInProcess", "long", "ptr;int;dword;dword;dword")

to

$DllHandle = DLLCallbackRegister ("MIDIInProc", "long", "ptr;int;dword;dword;dword")

I also had some questions some time ago, maybe you can find out more.

Uwe

Link to comment
Share on other sites

Hi,

here's something I wrote, please check and comment.

The script writes received MIDI notes for Lilypond.

lilyput.au3

Here's the lilyput.ini file you need. (Can't upluad ini files)

[setup]

MIDIInPort=0

MIDIOutPort=0

NoteLo=48

NoteHi=96

Key36=L1

Key37=R

Key38=L2

Key39=S

Key40=L4

Key41=L8

Key42=.

Key43=L16

Key44=K^+0

Key45=B

Key46=K{BS}

Key47=K ~

Tick=16

TicksMeasure=16

Send=0

Outfile=lilyout.txt

[NoteNames]

0=c

1=cis

2=d

3=es

4=e

5=f

6=fis

7=g

8=as

9=a

10=b

11=h

Link to comment
Share on other sites

it's working now. thanks a lot for your examples.

here's my code:

#include <MidiUDF.au3>

HotKeySet("{ESC}", "ExitProgram")
$DllHandle = DLLCallbackRegister ("MIDIInProcess", "long", "ptr;int;dword;dword;dword")
$MidiInputDevice = 1               ;change here to select a different device
$MidiInHandle = _MidiInOpen($MidiInputDevice, DllCallbackGetPtr($DllHandle), 0, $callback_function)
_MidiInReset($MidiInHandle)
_MidiInStart($MidiInHandle)

While 1
    Sleep(1000)
WEnd

Func MidiInProcess($midi, $msg, $instance, $MidiMsgIn, $MidiParam2)
    If $MidiMsgIn > 255 Then
        $statusbyte = BitAND($MidiMsgIn, 255)
        $chan = BitAND($statusbyte, 15) + 1
        $MidiType = $statusbyte - $chan
        Switch $MidiType
            Case 127
                $MidiTypeText = "NoteOff"
            Case 143
                $MidiTypeText = "NoteOn "
            Case 159
                $MidiTypeText = "PolyAt "
            Case 175
                $MidiTypeText = "CC     "
            Case 191
                $MidiTypeText = "PChange"
            Case 207
                $MidiTypeText = "ChanAT "
            Case 223
                $MidiTypeText = "Wheel  "
        EndSwitch
        $byte1 = BitAND(BitShift($MidiMsgIn, 8), 255)
        $byte2 = BitAND(BitShift($MidiMsgIn, 16), 255)
        ConsoleWrite($chan & "  " & $MidiTypeText & "  " & $byte1 & "  " & $byte2 & @CR)
    EndIf
EndFunc

Func ExitProgram()
    _MidiInStop($MidiInHandle)
    Sleep(50)
    _MidiInClose($MidiInHandle)
    Sleep(50)
    DllCallbackFree($DllHandle)
    Exit
EndFunc

last question. do you know why after some time running, the script ends? (often with an error)

Link to comment
Share on other sites

Hello gigi1,

thank you for the feedback, I've been waiting half a year for someone to test the script and confirm the errors.

Try getting rid of consolewrite and calculations, you can do this in the main loop.

I think the midi receive event function is too slow, and I have no idea how to improve this for my example.

If you don't use the sleep() in the loop, the script crashes immediately. I hope I can work on this again this weekend.

I have another midi processor script, which tries to do the following:

-you play two notes at a time on your keyboard, on MIDI channel 1

-the lower note will be played on channel 2, the higher on channel 3

-change the program for Ch. 2 and 3, for example to trumpet and clarinet, and you can play duets (instead of layers).

There is only one synth who can do something like this (without using MIDI): Korg Wavestation (so I had to buy one for the band)

What are your plans with the MIDI input?

Uwe

Edited by Uwe
Link to comment
Share on other sites

hi uwe,

i dont this the problem is in the function which can't handle midi because of speed because

1) trying with a keyboard, i can give a lot of midi data to process (using the pitchwheel or chords) at the beginning of the execution without problems, then it could stop while i'm pressing just 1 key per second, or even without playing.

2) there is a script in AutoHotKey which does similar things (http://www.autoitscript.com/forum/index.php?showtopic=119177 at the end), the function that handles midi input is structured like mine, with all the calculations and a GUI data updater, and works without problems

yea, i've noticed that without the sleep in the loop it crashes. this is strange, because the loop is never called, i mean, it does nothing :)

I have another midi processor script, which tries to do the following:

-you play two notes at a time on your keyboard, on MIDI channel 1

-the lower note will be played on channel 2, the higher on channel 3

-change the program for Ch. 2 and 3, for example to trumpet and clarinet, and you can play duets (instead of layers).

i didnt understand this part. Sorry my english is quite poor

My intents for the scripts are more than one:

1) Something like a Midi diagnostic; quite easy.. see and understand midi packets is enough

2) Midi hotkeys; always wanted to throw a granade with C4 in FPSs ;)

3) Midi routing; could be useful for routing determinates midi data from a keyboard to another applying filters, or from/to software (Vst)

4) Hotkeys for Midi output; like the opposite of point 2, if you press something, some data is sent.

and 5) this is difficult, but if i can get experienced enough in graphics, something like MidiLive

Link to comment
Share on other sites

  • 4 weeks later...

Interested to transpose guitar tablature and so far this is what i have, any suggestions to further the file reading function would be nice, so far its a proof of concept by playing the first 6 lines of tablature.

You'll need the attached guitar.au3 which converts tab notation. eg A2 (second fret on the A string) and any tablature file however so far you need to delete any space at the top of the tab txt file because the script is only pulling the top 6 lines of the file for conversion thus far.

btw in yesterdat.txt shows how to handle note duration with the underscore _ character

#include <file.au3>
#include <midiudf.au3>
#include <guitar.au3>

Dim $aRecords
If Not _FileReadToArray("yesterday.TXT",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

Dim $last_e_Note ="-"
Dim $last_b_Note ="-"
Dim $last_g_Note ="-"
Dim $last_d_Note ="-"
Dim $last_a_Note ="-"
Dim $last_E_Note ="-"

$Open = _MidiOutOpen()
SetInstrument($Open,25);Guitar=25

For $n = 1 to StringLen($aRecords[1])
    For $x = 1 to $aRecords[0]

        $z1 = StringMid($aRecords[$x],$n,1)
        $z2 = StringMid($aRecords[$x],$n,2)
        $z3 = StringMid($aRecords[$x],($n-1),1)

            Switch $z1
                case StringIsInt($z1)=1 And StringIsInt($z2) =0 And StringIsInt($z3) =0
                        ConsoleWrite($x & ":" & $z1 & " - noteOn(" & getString($x, $z1) & ")" & @CRLF)
                        noteOn($open,getString($x, $z1) )

                case StringIsInt($z1)=1 And StringIsInt($z2) =1
                        ConsoleWrite("noteOn(" & getString($x, $z2) & ")" & @CRLF)
                        noteOn($open,getString($x, $z2) )

                case "-"
                    If $z3= "_" Or StringIsInt($z3)=1 Then
                        ConsoleWrite(@TAB & "noteOff( " & getNoteOff($x) & " )" & @CRLF)
                        noteOff($open,getNoteOff($x) )
                    EndIf

            EndSwitch

    next

    ;ConsoleWrite("sleep(200)" & @CRLF)
    If $z1 <> "|" Then sleep(180);play music
next

_MidiOutClose($Open)
;end song



Func getString($s=1, $fret=0)
    Local $string
    Switch $s
        case 1
            $string = "e"
            $last_e_Note =$string & $fret

        case 2
            $string = "b"
            $last_b_Note =$string & $fret

        case 3
            $string = "g"
            $last_g_Note =$string & $fret

        case 4
            $string = "d"
            $last_d_Note =$string & $fret

        case 5
            $string = "a"
            $last_a_Note =$string & $fret

        case 6
            $string = "E_"
            $last_E_Note =$string & $fret

    EndSwitch

    return $string & $fret

EndFunc

Func getNoteOff($s=1)
    Switch $s
        case 1
            $string = $last_e_Note
            $last_e_Note ="-"

        case 2
            $string = $last_b_Note
            $last_b_Note ="-"

        case 3
            $string = $last_g_Note
            $last_g_Note ="-"

        case 4
            $string = $last_d_Note
            $last_d_Note ="-"

        case 5
            $string = $last_a_Note
            $last_a_Note ="-"

        case 6
            $string = $last_E_Note
            $last_E_Note ="-"

    EndSwitch

    return $string

EndFunc



;midi functions follow:
Func NoteOn($Handle, $Note)
    $Note = Eval($Note)
    _MidiOutShortMsg($Handle, "0x0040" & $Note)
EndFunc

Func NoteOff($Handle, $Note)
    $Note = Eval($Note)
    _MidiOutShortMsg($Handle, "0x0000" & $Note)
Endfunc

Func SetInstrument($Handle, $Instrument)
    _MidiOutShortMsg($Handle,256 * $Instrument + 192)
EndFunc

GUITAR.AU3

yesterday.TXT

yesterday1.TXT

Edited by Will66
Link to comment
Share on other sites

  • 5 weeks later...
  • 1 month later...

Does anyone have any idea why I'm not getting any sound? I have had the similar problems for several years with 2 different PC's: When I want to create a sound on my computer, I get stuck. Professional music software works fine, but I really want to compose music using my own methods.

I have tried a number of applications from a number of different threads using this UDF. If a file is missing from my computer, or a setting is wrong then I'm sure that problem can be fixed. But I have no idea what presettings are required, or what xp can and can't handle. I'm pretty sure the sounds exist on my system. There are some really nice GUI's out there and stuff, but I really need to access Microsoft Wave Synth, which has been hidden from the user by Microsoft, and get a noise out of it. Aaargh!

I forgot to mention, some of the scripts throw errors, although not all of them. This following script seems as if it's playing back the recording, but I get nisht!

I have just tested a midi file with Windows Media Player and it plays perfectly. I must be missing something obvious.

UPDATE

Ascend4nt's version is working for me now. Thanks to all the authors for this UDF. :)

Edited by czardas
Link to comment
Share on other sites

  • 3 months later...

I haven't had much time to take a proper look at this until now. I was just running playback tests on all instruments when I discovered the following minor bug at line 234 in Ascendants version of this UDF. The sound does not stop, as it should do.

Const $E4_OFF                   =   0x00000090  ;44

I believe the line of code above should be replaced with the following line:

Const $E4_OFF                   =   0x00004090  ;44

I didn't notice it at first, since with many instruments the volume decays naturally anyway (so it's not noticeable when you listen). It's a very minor thing, but I thought I ought to mention it. :unsure:

Edited by czardas
Link to comment
Share on other sites

Here's the midi audio output test (mentioned above) for anyone who wants to have a laugh. All the notes are played on all the instruments, one after another. The test should take just under one hour to run, :unsure: ... but you can exit the script with the ESC key if you get bored. You will need to download I also advise that, before running this test, you change the single line of code in the UDF, as suggested in my previous post.

#include <midiudf.au3>

HotKeySet("{ESC}", "_Quit")

Local $aInstrument = _GetInstrumentName()
Local $aNotes = _GetNoteRange()
Local $open = _MidiOutOpen()

For $i = 0 To 127
    ConsoleWrite("Currently listening to " & $aInstrument[$i] & @LF)

    _MidiOutShortMsg($open,256 * $i + 192)
    For $j = 0 To 87
        _MidiOutshortmsg($open,$aNotes[$j][0])
        sleep(300)
        _MidiOutshortmsg($open,$aNotes[$j][1])
        ; $j += Random(0,2,1) ; => Skips one or two notes.
    Next
Next

_MidiOutclose($open)

Func _GetNoteRange()
    Local $aArray[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]]
    Return $aArray
EndFunc

Func _GetInstrumentName()
    Local $aArray[128] = _
    ["Acoustic Grand Piano","Bright Piano","Electric Grand Piano", _
    "Honky-tonk piano", "Electric Piano 1","Electric Piano 2", _
    "Harpsichord","Clav", "Celesta","Glockenspiel","Music Box", _
    "Vibraphone", "Marimba","Xylophone","Tubular Bells","Dulcimer", _
    "Drawbar Organ","Percussive Organ","Rock Organ","Church Organ", _
    "Reed Organ","Accordian","Harmonica","Tango Accordian","Nylon String Guitar", _
    "Steel String Guitar","Jazz Guitar","Clean Electric Guitar","Muted Electric Guitar", _
    "Overdrive Guitar","Distortion Guitar","Guitar Harmonics","Acoustic Bass", _
    "Fingered Bass","Picked Bass","Fretless Bass","Slap Bass 1","Slap Bass 2", _
    "Synth Bass 1","Synth Bass 2","Violin","Viola","Cello","Contrabass", _
    "Tremolo Strings","Pizzicato Strings","Orchestral Harp","Timpani", _ ;
    "String Ensemble 1","String Ensemble 2","Synth Strings 1","Synth Strings 2", _
    "Choir Ahh","Choir Oohh","Synth Voice","Orchestral Hit","Trumpet", _
    "Trombone","Tuba","Muted Trumpet","French Horn","Brass Section", _
    "Synth Brass 1","Synth Brass 2","Soprano Sax","Alto Sax","Tenor Sax", _
    "Baritone Sax","Oboe","English Horn","Bassoon","Clarinet","Piccolo", _
    "Flute","Recorder","Pan Flute","Blown Bottle","Shakuhachi","Whistle", _
    "Ocarina","Square Wav","Sawtooth Wav","Caliope","Chiff","Charang", _
    "Voice","Fifth's","Bass&Lead","New Age","Warm","Polysynth","Choir", _
    "Bowed","Metallic","Halo","Sweep","FX Rain","FX Soundtrack","FX Crystal", _
    "FX Atmosphere","FX Brightness","FX Goblins","FX Echo Drops","FX Star Theme", _
    "Sitar","Banjo","Shamisen","Koto","Kalimba","Bagpipe","Fiddle","Shanai", _
    "Tinkle Bell","Agogo","Steel Drums","Woodblock","Taiko Drum","Melodic Tom", _
    "Synth Drum","Reverse Cymbal","Guitar Fret Noise","Breath Noise","Seashore", _
    "Bird Tweet","Telephone Ring","Helicopter","Applause","Gunshot"]
    Return $aArray
EndFunc

Func _Quit()
    Exit
EndFunc

This audio test is to check the suitability of different midi instruments for any particular purpose. While listening, you may notice that not all of midi sounds work well over the full range of frequencies.

Edited by czardas
Link to comment
Share on other sites

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...