AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MIDI Output from AHK
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4517
Location: Boulder, CO

PostPosted: Tue Feb 03, 2009 10:39 pm    Post subject: Reply with quote

Code:
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)
}
Back to top
View user's profile Send private message
genmce



Joined: 10 Jan 2009
Posts: 57
Location: Virginia

PostPosted: Wed Feb 04, 2009 1:45 pm    Post subject: Reply with quote

Thank you again!
You are awesome!
_________________
GenMce - a free generic midi controller to mackie emulation.
KeyMce - Better mackie emulator for pc keyboard.
Back to top
View user's profile Send private message Yahoo Messenger
genmce



Joined: 10 Jan 2009
Posts: 57
Location: Virginia

PostPosted: Sun Mar 22, 2009 12:34 pm    Post subject: sysex and midi output Reply with quote

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...
_________________
GenMce - a free generic midi controller to mackie emulation.
KeyMce - Better mackie emulator for pc keyboard.
Back to top
View user's profile Send private message Yahoo Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4517
Location: Boulder, CO

PostPosted: Sun Mar 22, 2009 4:27 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
genmce



Joined: 10 Jan 2009
Posts: 57
Location: Virginia

PostPosted: Sun Mar 22, 2009 6:15 pm    Post subject: Reply with quote

Laszlo wrote:
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.
_________________
GenMce - a free generic midi controller to mackie emulation.
KeyMce - Better mackie emulator for pc keyboard.
Back to top
View user's profile Send private message Yahoo Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4517
Location: Boulder, CO

PostPosted: Sun Mar 22, 2009 6:45 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
genmce



Joined: 10 Jan 2009
Posts: 57
Location: Virginia

PostPosted: Mon Nov 02, 2009 8:42 pm    Post subject: Reply with quote

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.
_________________
GenMce - a free generic midi controller to mackie emulation.
KeyMce - Better mackie emulator for pc keyboard.
Back to top
View user's profile Send private message Yahoo Messenger
Stevie



Joined: 17 Aug 2006
Posts: 49

PostPosted: Sat Nov 07, 2009 11:28 am    Post subject: Reply with quote

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.


Code:
;=================== 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
Code:

config.ini

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

[Midiport]
Device=0




Cheers,

Stevie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group