MIDI library for AutoHotKey v2

I have created a MIDI library for AutoHotKey v2.
The library is available for download on GitHub here:
https://github.com/emliberace/MIDIv2.ahk

Detailed documentation is available online here.

Features

  • Open and close Input and Output ports
  • Get all available MIDI Input/Output ports
  • Define a default MIDI Output channel
  • Filter incoming MIDI messages to a specific channel
  • Send and receive MIDI messages:
    • Note On/Off
    • Control Change
    • Aftertouch
    • Poly Aftertouch
    • Pitchbend
    • Program Change
    • SysEx
    • MMC (MIDI Machine Control)
    • MIDI Time Code
  • MIDI Through

I have an older version of a MIDI library for AutoHotKey v1 that is available in these forums here. It has fewer features but is still functional.
The library for v2 is recommended.

(Special thanks to @Aurasphere for inspiration!)

Looks brilliant…ill get a chance to check next week…under pressure to get our translation speakers ready for namm :wink:

Ahk is just brilliant for keys>midi…i migrated all those bits from Bome and its so much better. Im just looking to add HID trapping so u can add kb etc as dedicated/single purpose

Cant wait to check our your guru scribing :slight_smile:

MIDIv2 Updated to v1.1!

Added

  • Added support for RPN/NRPN
  • Added support for System Real Time messages
  • Properties added

    • RPN_Enabled
    • NRPN_Enabled
    • SRT_Enabled
  • Functions added

    • SendRPN()
    • SendNRPN()
    • ControlChangePair()
    • SRT_TimingClock()
    • SRT_Start()
    • SRT_Stop()
    • SRT_ActiveSensing()
    • SRT_SystemReset()
  • Callbacks added

    • RPN
    • NRPN
    • SRT_Timing
    • SRT_Start
    • SRT_Continue
    • SRT_Stop
    • SRT_ActiveSensing
    • SRT_SystemReset

Changed

  • Updated error handling to be more concise and descriptive

Fixed

  • MMC_DeviceID Get - Now returns Integer and rather than String

To download, see link in the top most post of this thread.

MIDIv2 Updated to v1.1.2

Added

  • Properties added

    • SysExInputBuffers
    • SysExInputBufferSize

Changed

  • Incoming SysEx messages now use multiple buffers which enables larger sized messages to be received
  • Minor code cleanup

Notes:

Each SysEx buffer is still limited to 64KB (65536 Bytes) but as far as I know, there is no limit, other than system resources (RAM), of how many buffers you can assign.
It’s probably good practice to not go too crazy when allocating buffers and keep it to just over the expected maximum data size.
Since the buffers are automatically allocated when a MIDI Input port is opened, I kept the default buffers and sizes quite small—16 buffers of 64 Bytes each for a total of 1KB. For SysEx dumps, especially sample data, they must be increased by a fair amount.
Also note that if a virtual MIDI port is used, it might impose a limitation on the total size of the SysEx message.
I have successfully tested receiving a single data stream from a .syx file of 256KB in size.


To download, see link in the top most post of this thread.

Interesting! I’m very interested to use MIDI controllers as PC input devices (MIDI → HID) to fire scripts, shortuts etc.

Could you provide an example that fire a messagebox if C2 (note 48) and C3 (note 60) is pressed, as a Input proof of concept? I have tried for hours but can’t figure it out.
I know my devices work from Midi Debugger and my DAW.

The basic script to check devices does work:

Hi there and welcome to the forums!

Here you go:

#Requires AutoHotkey v2.0
#SingleInstance force
Persistent
#include <MIDIv2>

MIDI := MIDIv2()

MIDI.OpenMidiIn(3)	; Change to your MIDI Input port

note48 := False
note60 := False

MidiInNoteOn48(e) {
	global note48 := True
	
	if (note60)
		note48and60()
}

MidiInNoteOff48(e) {
	global note48 := False
}

MidiInNoteOn60(e) {
	global note60 := True
	
	if (note48)
		note48and60()
}

MidiInNoteOff60(e) {
	global note60 := False
}

note48and60() {
	MsgBox("Note 48 & Note 60 is held")
	global note48 := False
	global note60 := False
}

Hi @mlib

I just filed this bug:

If you had any reports of the script failing on Windows 11 earlier this year, that was likely the reason. The MIDIHDR structure you have set up is too small (96 bytes instead of 112) and some of your field offsets are incorrect.

(There are a couple other bugs in there that you may run into with folks on Windows 11. I’ve added them as comments in that same issue.)

Pete
Microsoft