What would be the way to make use if the midi relative knob movements without storing values? I suppose the reading of the value would be needed, which would require setting up a midi in port?
Help would be much appreciated.
Code: Select all
;q:: ;MIDI play notes
hModule := DllCall("kernel32\LoadLibrary", "Str","winmm", "Ptr")
vDeviceID := 1, hMIDIOutputDevice := 0
if DllCall("winmm\midiOutOpen", "Ptr*",hMIDIOutputDevice, "UInt",vDeviceID, "UPtr",0, "UPtr",0, "UInt",0, "UInt")
return
hDev := hMIDIOutputDevice
vChan := 0
;==============================
AW:= A_IsUnicode? "W": "A", A_CharSize:= A_IsUnicode? 2: 1
hWinMM:= DllCall("kernel32\LoadLibrary" AW, "Str", "Winmm.dll", "Ptr")
NumDevs:= DllCall("Winmm\midiOutGetNumDevs"), sz:= 20+32*A_CharSize
Loop, % NumDevs {
VarSetCapacity(DevCaps, sz, 0)
DllCall("Winmm\midiOutGetDevCaps" AW, "UInt", id:=A_Index-1, "Ptr", &DevCaps, "UInt", sz)
Name:= StrGet(&DevCaps+8)
DevName%A_Index%:= Name
DevNames.= id ": " Name "`n"
}
StringTrimRight, DevNames, DevNames, 1
MsgBox % DevNames
^F12::
;C3 and C4 at the same time:
MidiNoteOn(hDev, vChan, 48, 100)
MidiNoteOn(hDev, vChan, 60, 100)
Sleep, 2000
MidiNoteOff(hDev, vChan, 48, 0)
MidiNoteOff(hDev, vChan, 60, 0)
Sleep, 2000
ControlNo := 111
Value := 64
MidiControlChange(hMIDIOutputDevice, vChan, ControlNo, Value)
MidiControlChange(1, Channel, ControlNo, Value)
return
;==============================
;==============================
DllCall("winmm\midiOutClose", "Ptr",hMIDIOutputDevice, "UInt")
DllCall("kernel32\FreeLibrary", "Ptr",hModule)
return
;==================================================
MidiNotePlay(hMIDIOutputDevice, vChannel, vNote, vVelocity, vDuration)
{
MidiNoteOn(hMIDIOutputDevice, vChannel, vNote, vVelocity)
Sleep, % vDuration
MidiNoteOff(hMIDIOutputDevice, vChannel, vNote, 0)
}
MidiNoteOn(hMIDIOutputDevice, vChannel, vNote, vVelocity)
{
DllCall("winmm\midiOutShortMsg", "Ptr",hMIDIOutputDevice, "UInt",0x90 | vChannel | (vNote << 8) | (vVelocity << 16), "UInt")
}
MidiNoteOff(hMIDIOutputDevice, vChannel, vNote, vVelocity)
{
DllCall("winmm\midiOutShortMsg", "Ptr",hMIDIOutputDevice, "UInt",0x80 | vChannel | (vNote << 8) | (vVelocity << 16), "UInt")
}
;==================================================
MidiControlChange(hMIDIOutputDevice, Channel, ControlNo, Value)
{
DllCall("winmm\midiOutShortMsg", "UInt", hMIDIOutputDevice, "UInt", 0xB0 | Channel
| (ControlNo << 8) | (Value << 16)) ;"Control Change" event
}