Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

MIDI Output from AHK


  • Please log in to reply
65 replies to this topic
Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
MidiDev = 0 ; Default

GoSub MOcreate

Menu TRAY, Add, Refresh MIDI-out list, MOrefresh ; needed after you switch, un/plug a Midi device

Menu TRAY, Add, Select MIDI-out device,:MOmenu   ; Midi out selection submenu



;... your code here



Return



!z::ExitApp



MOrefresh:

   Menu MOmenu, DeleteAll

MOcreate:

   MOlist := MidiOutsList(NumPorts)

   Loop Parse, MOlist, |

   {

      Menu MOmenu, Add, %A_LoopField%, MOselect

      MO%A_Index% := A_LoopField

   }

   I := MidiDev + 1

   Menu MOmenu, Check, % MO%I%

Return



MOselect:

   I := MidiDev + 1

   Menu MOmenu, UnCheck, % MO%I%

   MidiDev := A_ThisMenuItemPos - 1

   Menu MOmenu, Check, % MO%A_ThisMenuItemPos%

Return



MidiOutsList(ByRef NumPorts) { ; Returns a "|"-separated list of midi output devices

  Local List, MidiOutCaps, PortName, result

  VarSetCapacity(MidiOutCaps, 50, 0)

  VarSetCapacity(PortName, 32)                       ; PortNameSize 32



  NumPorts := DllCall("winmm.dll\midiOutGetNumDevs") ; #midi output devices on system, first device ID = 0



  Loop %NumPorts% {

    result := DllCall("winmm.dll\midiOutGetDevCapsA", UInt,A_Index-1, UInt,&MidiOutCaps, UInt,50, UInt)

    If (result OR ErrorLevel) {

      List .= "|-ERROR-"

      Continue

    }

    DllCall("RtlMoveMemory", Str,PortName, UInt,&MidiOutCaps+8, UInt,32) ; PortNameOffset 8, PortNameSize 32

    List .= "|" PortName

  }

  Return SubStr(List,2)

}


genmce
  • Members
  • 144 posts
  • Last active: May 21 2015 03:09 PM
  • Joined: 10 Jan 2009
Thank you again!
You are awesome!

KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk? links dead.. pm me


genmce
  • Members
  • 144 posts
  • Last active: May 21 2015 03:09 PM
  • Joined: 10 Jan 2009
Is is possible to send out a sysex string using midi out and ahk.

Neither of these approaches, general funcitons nor the midi out described here show any examples on sending sysex strings.
For example, if I wanted to send out

F0 00 00 66 14 1B 58 59 5A 00 00 00 00 F7

to the selected midi port, from a keypress like f12...
how might this be accomplished?

My question comes from the desire to make a keyboard based synth editor using sysex with midi output stuff for ahk...

Ultimately certain values in the strings would change.
I thought I would start at just being able to send out the midi sysex string.

A midi monitor would be nice to for the midi output... done in ahk.

.... musing...

KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk? links dead.. pm me


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
You have to pack the message body (the bytes between the starting F0 and closing F7) in a MIDIHDR structure and send it with a dllcall to midiOutLongMsg, as described in the first post as a midi stream example.

genmce
  • Members
  • 144 posts
  • Last active: May 21 2015 03:09 PM
  • Joined: 10 Jan 2009

You have to pack the message body (the bytes between the starting F0 and closing F7) in a MIDIHDR structure and send it with a dllcall to midiOutLongMsg, as described in the first post as a midi stream example.


What if there is only that one message?

Could you give me an example of packing a sysex message to work from?
I don't remember seeing any examples of packing sysex messages in this thread.

Thank you.

KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk? links dead.. pm me


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I have no Midi device, which reacts to SysEX messages, so I cannot test it. You have to try the parameters, until they work. You don’t add events to the buffer, but the raw bytes to be sent.

genmce
  • Members
  • 144 posts
  • Last active: May 21 2015 03:09 PM
  • Joined: 10 Jan 2009
Hello all,

Is there a way to have two midi output ports, both active?

Example 2 hotkeys - both set to send a different CC message or Note.

1 sending midi out to 1 selectable midi out port
2nd key sending midi out to a 2nd selectable midi out port?

I tried using midi functions.ahk and general functions.ahk as includes in the same file, however, I don't know how to differentiate between the two, and I get an error stating duplicate functions...

Thanks for any help here.

KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk? links dead.. pm me


Stevie
  • Members
  • 68 posts
  • Last active: May 29 2011 01:52 AM
  • Joined: 17 Aug 2006
Hey all,

with the help of genmce I created a script to control the volume of the Total Mix application (RME soundcards).
As you might know the RME driver (non-MME) architecture does not link to the windows volume control.
But you can control the Total Mix application via MIDI commands. So I wanted to develop a script that
can exactly do that, but with simple keyboard hotkeys instead of an external MIDI controller.
Since I had no idea where to start, genmce provided me with the midi framework.
Thanks again genmce for helping me here!

Besides the the basic volume control that genmce gave me I added
the following functionality:

- setup gui
- hotkeys are assignable and saved to config.ini
- selected midi port is saved to config.ini
- the saved MIDI-port is read from config.ini on startup (no prompt)
- mute function (linked to DIM. The DIM level is adjusted in Total Mix)

You need to have MIDI Yoke installed!

This project is pretty much work in progress.
On my todo list are following items:
- the saved MIDI port does not show in the drop down menu
- add an OSD

Feel free to correct the code and post it here if you find bug/problems
or see a way to improve it.


;=================== Total Control 1.0 ===================
;****************** Control the volume on the Total Mix application of the RME soundcards via computer keyboard ***************

/* 

The following file (general functions.ahk) must be included in the directory of the script - if you compile to exe, then you won't need it since it is built into it.
the file was taken from the midiout thread on ahk forum: http://www.autohotkey.com/forum/topic18711.html
*/



#Include general functions.ahk
#SingleInstance force
#NoEnv



;============= Define variables =================================
    
  Channel  := 1        			; midi channel for sending midi data to Total Mix
  Note 	   := 60           		; midi number for middle C
  NoteDur  := 100				; note duration
  VolCC    := 7       			; cc # for volume on Total Mix
  CCIntVal := 127      			; This is the starting value to change the volume
  Speed    := 1       			; This value will make the value change slower or faster. Increase the number to make value change slower
  MuteState:= 0					; default mute state = off
  ToggleSetup:= 0				; toggle state of the setup GUI

  
;======================= select midi port ========================

NumPorts := MidiOutsEnumerate()  											; count the amount of installed MIDI ports
  
Loop, %  NumPorts															; loop this action until the end of NumPorts is reached
{
Port := A_Index -1															; assign MIDI port ID -1 to variable "Port"
PortList .= "ID " . Port . ": " MidiOutPortName%Port% "|"					; create the different dropdownlist entries seperated with a |
}

IniRead, SelectedMidiPort, config.ini, Midiport, Device						; read saved MIDI port from config.ini

;Do some midi work by opening port for the messages to pass.
OpenCloseMidiAPI()
h_midiout := midiOutOpen(SelectedMidiPort) 


;============== define hotkey triggers ========================
IniRead, EnterVolumeUpHotkey, config.ini, Hotkeys, VolumeUpHotkey			; read setting from config.ini
IniRead, EnterVolumeDownHotkey, config.ini, Hotkeys, VolumeDownHotkey		; read setting from config.ini
IniRead, EnterVolumeMuteHotkey, config.ini, Hotkeys, VolumeMuteHotkey		; read setting from config.ini																; read hotkeys from config.ini		
Hotkey, %EnterVolumeUpHotkey%, VolumeUp 									; assign retrieved value from config.ini to hotkey
Hotkey, %EnterVolumeDownHotkey%, VolumeDown									; assign retrieved value from config.ini to hotkey
Hotkey, %EnterVolumeMuteHotkey%, VolumeMute									; assign retrieved value from config.ini to hotkey


;==================== setup gui ============================

Menu, Tray, NoStandard														; don't show the default ahk menu on the tray
Menu, Tray, Icon, volume.ico								
Menu, Tray, Add, Setup, GuiShow												; add menu entry "Setup"
Menu, Tray, Add																; add seperator
Menu, Tray, Add, Exit, QuitScript											; add menu entry "Exit"

Menu, Tray, Default, Setup													; default action on left click = "Setup"
Menu, Tray, Click, 1														; left click
Return

QuitScript:
 ExitApp
Return

GuiShow:
if ToggleSetup = 0
{
ToggleSetup = 1																					; set toggle variable to "setup is shown"
   
Gui, Add, Text, x152 y20 w130 h20 +Center, Total Control Setup 									; text

;******* volume up hotkey assignment *******
Gui, Add, Text, x30 y80 w110 h20 , Volume Up Hotkey												; text
Gui, Add, Hotkey, x160 y80 w210 h20 vEnterVolumeUpHotkey, %EnterVolumeUpHotkey%					; assign value from config.ini to hotkey

;******* volume down hotkey assignment *******
Gui, Add, Text, x30 y120 w110 h20 , Volume Down Hotkey											; text
Gui, Add, Hotkey, x160 y120 w210 h20 vEnterVolumeDownHotkey, %EnterVolumeDownHotkey%			; assign value from config.ini to hotkey

;******* volume mute hotkey assignment *******
Gui, Add, Text, x30 y160 w110 h20 , Volume Mute Hotkey											; text	
Gui, Add, Hotkey, x160 y160 w210 h20 vEnterVolumeMuteHotkey, %EnterVolumeMuteHotkey%			; assign value from config.ini to hotkey

;******* midi device selection *******
Gui, Add, DropDownList,% "x162 y200 w210 AltSubmit vSelectedPort Choose", %PortList% 			; chose MIDI port
Gui, Add, Text, x32 y200 w110 h20 , MIDI-Port													; text
Gui, Add, Button, x252 y310 w110 h30 , OK 														; create ok button
Gui, Add, Button, x62 y310 w100 h30 , Cancel 													; create cancel button
Gui, Show, x304 y135 h396 w427, Total Control Setup 											; show GUI
Return
}


Else
{
   ToggleSetup = 0																				; set toggle variable to "setup hidden"
   Gui, destroy
}
Return


;******* ok button function *******
ButtonOK:
Gui, Submit																						; submit changed values in GUI
IniWrite, %EnterVolumeUpHotkey%, config.ini, Hotkeys, VolumeUpHotkey							; write hotkey settings to config.ini
IniWrite, %EnterVolumeDownHotkey%, config.ini, Hotkeys, VolumeDownHotkey						; write hotkey settings to config.ini
IniWrite, %EnterVolumeMuteHotkey%, config.ini, Hotkeys, VolumeMuteHotkey						; write hotkey settings to config.ini
Hotkey, %EnterVolumeUpHotkey%, VolumeUp															; re-assign hotkeys with saved value
Hotkey, %EnterVolumeDownHotkey%, VolumeDown														; re-assign hotkeys with saved value
Hotkey, %EnterVolumeMuteHotkey%, VolumeMute														; re-assign hotkeys with saved value
SelectedPort-=1																					; actual selected port number -1
IniWrite, %SelectedPort%, config.ini, Midiport, Device											; write port value to config.ini
IniRead, SelectedMidiPort, config.ini, Midiport, Device											; re-read saved MIDI port from config.ini
ToggleSetup = 0																					; set toggle variable to "setup hidden"
Gui, destroy
Return

;******* cancel button function *******
ButtonCancel:
ToggleSetup = 0																					; set toggle variable to "setup hidden"
Gui, destroy
Return


GuiClose:
ExitApp




;========== Define keys for midi output CC value =============


;******* volume up command ********  

VolumeUp:
Loop 
{ 
	CCIntVal := CCIntVal < 127 ? CCIntVal+1 : 127              	; check for max value reached.
	midiOutShortMsg(h_midiout, "CC", Channel, VolCC, CCIntVal) 	; midi "CC" message(definded in general funtions.ahk)on Channel(definded above),VolCC,CCIntVal in vars above 
	Sleep, %Speed%                                           	; repeat speed
	if !GetKeyState(EnterVolumeUpHotkey,"P") 					; if not, or, if key is released 
	break 
} 
Return



; ********* volume down command *************

VolumeDown: 
Loop 
{
	CCIntVal := CCIntVal > 0 ? CCIntVal-1 : 0                 	; check min value reached.
	midiOutShortMsg(h_midiout, "CC", Channel, VolCC, CCIntVal) 
	Sleep, %Speed%          									; repeat speed
	if !GetKeyState(EnterVolumeDownHotkey,"P") 					; if not, or, if key is released 
	break 
} 
Return


; ********* volume mute command *************

VolumeMute:
{
 midiOutShortMsg(h_midiout, "N1", 1, 93, 127)     				; send note on event on A5 
  Sleep %NoteDur%												; repeat speed
  midiOutShortMsg(h_midiout, "N0", 1, 93, 0)					; send note off event on A5 
exit
}
Return

midiOutClose(h_midiout) 										; stop midi output
OpenCloseMidiAPI()


And here a default config.ini
config.ini

[Hotkeys]
VolumeUpHotkey=Volume_Up
VolumeDownHotkey=Volume_Down
VolumeMuteHotkey=Volume_Mute

[Midiport]
Device=0



Cheers,

Stevie

hoai_vien
  • Members
  • 2 posts
  • Last active: Apr 07 2010 06:06 AM
  • Joined: 25 Mar 2010
Hi, I'm very new here.
I wonder if someone figured out a way to provide feedback to the controller (I have a Behringer BCR2000), from AHK ??
The idea is, I used the BCR2000 and AHK to control a software slider/fader (except for Sony Vegas, most non-musical software don't provide a way to do that naturally).
Is there a way to read out the position of the software slider/fader using AHK and output the value to the controller, so the LED lights of a knob will display it correctly?
I'm not familiar with how MIDI signal travel and of course have no idea how to feed it to a controller, from a computer.
Please help ....

genmce
  • Members
  • 144 posts
  • Last active: May 21 2015 03:09 PM
  • Joined: 10 Jan 2009

Hi, I'm very new here.
I wonder if someone figured out a way to provide feedback to the controller (I have a Behringer BCR2000), from AHK ??
The idea is, I used the BCR2000 and AHK to control a software slider/fader (except for Sony Vegas, most non-musical software don't provide a way to do that naturally).
Is there a way to read out the position of the software slider/fader using AHK and output the value to the controller, so the LED lights of a knob will display it correctly?
I'm not familiar with how MIDI signal travel and of course have no idea how to feed it to a controller, from a computer.
Please help ....


Hey - have you tried
<!-- m -->http://launch.groups...bc2000/messages<!-- m -->

I wrote several presets for the bcr2000 and mackie emulation, that should work with vegas, might need some tweaking.
As for feedback to faders, the mackie presets will do that.
However, it will NOT work for the pans.
If using the mackie preset, the pan data coming back to the bcr will be meaningless as the information is relative midi data.
Turn the knob to the right and it puts out a bunch of 1's, turn it to the right it puts out a bunch of 65's.
When the bcr receives those values back, the display ring does not know what to do with them.

As for an ahk solution to visible pan data on the leds of the bcr... I don't see it happening, for the above reason, if using a mackie preset.
Sure, one could convert the midi data coming back from vegas, however, what would you convert it to?

Again, check over at the bc2000 yahoo group, it has been discussed there.
I don't have links tho. Royce and Martin know a lot about the device, perhaps they will know.

Now - if you were doing something else, like programming your own preset and mapping controls, you should be able to have the ring reflect current position, if you can route out of Vegas back to the bcr. The danger here is a midi loop, I don't know if your bcr or vegas will go into a midi loop or not on this setup, nor do I know much of anything about Vegas.

Not much help, maybe a few clues to go on tho.

KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk? links dead.. pm me


  • Guests
  • Last active:
  • Joined: --
Thanks genmce, for the quick reply. Are you the one who made KeyMce?

I will check out the yahoo group. What I look for is a way to control non-music and non-midi application like photoshop or lightroom, or other editing softwares. Mapping MIDI commands to the control is fairly easy and doable, thanks to some of the MIDI input threads on this forum (I can control some sliders in lightroom now, though if I move the knob too fast, it won't pick up the signal).

So the next problem is when I move to the next picture, I need to read the settings from all sliders inside lightroom and feed them back to the BCR2000, so when I turn the knobs, it's already matched with the position in the software --> no jumping (if I set Lightroom to match with knob value right away), no running out of "values" (like, if the knob is already at 127, I can't turn up anymore) (if I set Lightroom to respond to the UP and DOWN value only).
If I set the knob to Relative mode, I suppose it will work, but there won't be feed back and no value displayed on LED, like you said.

Do you know what parts a MIDI signal must contain when sent back to the Controller in order to change a knob/fader setting? I googled, but no good result. I hooked up both Behringer BCR2000 and BCN44 to computer (via MIDI-USB cable) and route them using MIDIOX. So input from BCN44 will be output to BCR2000. I set 2 knobs from the 2 controllers to the exact same setting. When turning the one on BCN44, I supposed that the signal fed to BCR2000 will change it, but did not. In MidiOX, it says BCN44 input is 9, BCR2000 is 10 (the column after "timestamp").

Sorry for the long and confusing explanation. I spent too much time already and it's not good. I wish AHK has native support for MIDI in/out (and parameter feedback :-)

hoai_vien
  • Members
  • 2 posts
  • Last active: Apr 07 2010 06:06 AM
  • Joined: 25 Mar 2010
"guest" above, is hoai_vien.
I forgot to login.

genmce
  • Members
  • 144 posts
  • Last active: May 21 2015 03:09 PM
  • Joined: 10 Jan 2009
I sent you a PM.
Please read and reply.

KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk? links dead.. pm me


genmce
  • Members
  • 144 posts
  • Last active: May 21 2015 03:09 PM
  • Joined: 10 Jan 2009
Well, I keep missing you.
Would you rather work here, via pm?

KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk? links dead.. pm me


Petru
  • Members
  • 236 posts
  • Last active: Jan 19 2012 06:47 PM
  • Joined: 17 Dec 2007
I've got a question. How do I change the instrument that is used to play a note?