- Add mapping for buttons 1 to 32

- Scale axis values, rather than just clamping
- Display actual actions, not dummy MIDI Out stuff
- Handle Note On with 0 velocity as a Note Off
- Fix MIDI rule dispatching ("between" doesn't work in an expression-style if
  statement)
- Init all max value variables as globals
This commit is contained in:
Laurence Dougal Myers 2014-01-27 15:42:59 +11:00
parent b450a06cc6
commit bfc8dc51be
4 changed files with 50 additions and 41 deletions

View File

@ -4,37 +4,37 @@
;************************************************* ;*************************************************
/* /*
The MidiRules section is for modifying midi input from some other source. The MidiRules section is for mapping MIDI input to actions.
Alter these functions as required. Alter these functions as required.
*/ */
; *** New rule handler functions ***
ProcessNote(device, channel, note, velocity, isNoteOn) { ProcessNote(device, channel, note, velocity, isNoteOn) {
/* global iInterface
Add your own note filters here.
Example: if (note >= 1 and note <= 32) {
if (isNoteOn and note == 20) VJoy_SetBtn(isNoteOn, iInterface, note)
{ button_state_text := isNoteOn ? "On" : "Off"
; Clamp the velocity to 80 DisplayOutput("Button " + button_state_text, note)
if (velocity > 80) { }
velocity := 80
}
gosub, SendNote ; send the note out.
}
*/
} }
ProcessCC(device, channel, cc, value) { ProcessCC(device, channel, cc, value) {
global AxisMax_X, max_cc_val, iInterface, HID_USAGE_X global iInterface, HID_USAGE_X, HID_USAGE_Y, AxisMax_X, AxisMax_Y
if (cc == 7) { if (cc == 7) {
new_axis_value := ConvertCCValueToAxis(value, 127, AxisMax_X) scaled_value := ConvertCCValueToScale(value, 8, 120)
new_axis_value := ConvertToAxis(scaled_value, AxisMax_X)
VJoy_SetAxis(new_axis_value, iInterface, HID_USAGE_X) VJoy_SetAxis(new_axis_value, iInterface, HID_USAGE_X)
DisplayOutput("Axis X", ConvertCCValue(value, 127)) DisplayOutput("Axis X", scaled_value)
} else if (cc == 27) {
scaled_value := ConvertCCValueToScale(value, 8, 112)
new_axis_value := ConvertToAxis(scaled_value, AxisMax_Y)
VJoy_SetAxis(new_axis_value, iInterface, HID_USAGE_Y)
DisplayOutput("Axis Y", scaled_value)
} }
} }
ProcessPC(device, channel, note, velocity) { ProcessPC(device, channel, note, velocity) {
} }
ProcessPitchBend(device, channel, value) { ProcessPitchBend(device, channel, value) {

View File

@ -90,6 +90,8 @@ gui,14:add,text, x305 y5, Midi Ouput ; %TheChoice2%
Gui,14:Add, DropDownList, x270 y20 w140 Choose%TheChoice2% vMidiOutPort gDoneOutChange altsubmit , %MoList% Gui,14:Add, DropDownList, x270 y20 w140 Choose%TheChoice2% vMidiOutPort gDoneOutChange altsubmit , %MoList%
Gui,14:Add, ListView, x5 r11 w220 Backgroundblack caqua Count10 vIn1, EventType|StatB|Ch|Byte1|Byte2| Gui,14:Add, ListView, x5 r11 w220 Backgroundblack caqua Count10 vIn1, EventType|StatB|Ch|Byte1|Byte2|
gui,14:Add, ListView, x+5 r11 w220 Backgroundblack cyellow Count10 vOut1, Event|Value| gui,14:Add, ListView, x+5 r11 w220 Backgroundblack cyellow Count10 vOut1, Event|Value|
LV_ModifyCol(1, 105)
LV_ModifyCol(2, 110)
gui,14:Show, autosize xcenter y5, MidiMonitor gui,14:Show, autosize xcenter y5, MidiMonitor
Return Return
@ -117,19 +119,14 @@ Return
; MIDI Rules dispatcher ; MIDI Rules dispatcher
MidiRules: MidiRules:
if (statusbyte between 128 and 143) { ; Note off if (statusbyte >= 128 and statusbyte <= 159) { ; Note off/on
ProcessNote(0, chan, byte1, byte2, false) isNoteOn := (statusbyte >= 144 or byte2 == 0)
} ProcessNote(0, chan, byte1, byte2, isNoteOn)
if (statusbyte between 144 and 159) { ; Note on } else if (statusbyte >= 176 and statusbyte <= 191) { ; CC
ProcessNote(0, chan, byte1, byte2, true)
}
if (statusbyte between 176 and 191) { ; CC
ProcessCC(0, chan, byte1, byte2) ProcessCC(0, chan, byte1, byte2)
} } else if (statusbyte >= 192 and statusbyte <= 208) { ; PC
if (statusbyte between 192 and 208) { ; PC
ProcessPC(0, chan, byte1, byte2) ProcessPC(0, chan, byte1, byte2)
} } else if (statusbyte >= 224 and statusbyte <= 239) { ; Pitch bend
if (statusbyte between 224 and 239) { ; Pitch bend
ProcessPitchBend(0, chan, pitchb) ProcessPitchBend(0, chan, pitchb)
} }
; Maybe TODO: Key aftertouch, channel aftertouch, ; Maybe TODO: Key aftertouch, channel aftertouch,

View File

@ -30,7 +30,7 @@ if A_OSVersion in WIN_NT4,WIN_95,WIN_98,WIN_ME ; if not xp or 2000 quit
version = midi_to_joy_2 version = midi_to_joy_2
VJoy_Init() VJoy_Init()
AxisMax_X := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_X) gosub VJoyInitMaxValues
readini() ; load values from the ini file, via the readini function - see Midi_under_the_hood.ahk file readini() ; load values from the ini file, via the readini function - see Midi_under_the_hood.ahk file
gosub, MidiPortRefresh ; used to refresh the input and output port lists - see Midi_under_the_hood.ahk file gosub, MidiPortRefresh ; used to refresh the input and output port lists - see Midi_under_the_hood.ahk file
port_test(numports,numports2) ; test the ports - check for valid ports? - see Midi_under_the_hood.ahk file port_test(numports,numports2) ; test the ports - check for valid ports? - see Midi_under_the_hood.ahk file
@ -46,6 +46,19 @@ gosub, midiMon ; see below - a monitor gui - see Midi_In_and_Gu
return return
VJoyInitMaxValues:
global AxisMax_X, AxisMax_Y, AxisMax_Z, AxisMax_RX, AxisMax_RY, AxisMax_RZ, AxisMax_SL0, AxisMax_SL1, AxisMax_WHL
AxisMax_X := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_X)
AxisMax_Y := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_Y)
AxisMax_Z := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_Z)
AxisMax_RX := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RX)
AxisMax_RY := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RY)
AxisMax_RZ := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RZ)
AxisMax_SL0 := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_SL0)
AxisMax_SL1 := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_SL1)
AxisMax_WHL := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_WHL)
return
#Include Midi_In_and_GuiMonitor.ahk ; this file contains: the function to parse midi message into parts we can work with and a midi monitor. #Include Midi_In_and_GuiMonitor.ahk ; this file contains: the function to parse midi message into parts we can work with and a midi monitor.
#Include MidiRules.ahk ; this file contains: Rules for manipulating midi input then sending modified midi output. #Include MidiRules.ahk ; this file contains: Rules for manipulating midi input then sending modified midi output.
#Include Midi_under_the_hood.ahk ; this file contains: (DO NOT EDIT THIS FILE) all the dialogs to set up midi ports and midi message handling. #Include Midi_under_the_hood.ahk ; this file contains: (DO NOT EDIT THIS FILE) all the dialogs to set up midi ports and midi message handling.

View File

@ -5,22 +5,21 @@ DisplayOutput(event, value) {
LV_Add("",event,value) LV_Add("",event,value)
LV_ModifyCol(1,"center") LV_ModifyCol(1,"center")
LV_ModifyCol(2,"center") LV_ModifyCol(2,"center")
LV_ModifyCol(3,"center")
LV_ModifyCol(4,"center")
LV_ModifyCol(5,"center")
If (LV_GetCount() > 10) If (LV_GetCount() > 10)
{ {
LV_Delete(1) LV_Delete(1)
} }
} }
ConvertCCValueToAxis(value, maximum_value, maximum_axis_value) { ConvertToAxis(value, maximum_axis_value) {
return Floor(ConvertCCValue(value, maximum_value) * maximum_axis_value) return Floor(value * maximum_axis_value)
} }
ConvertCCValue(value, maximum_value) { ConvertCCValueToScale(value, minimum_value, maximum_value) {
if (value > maximum_value) { if (value > maximum_value) {
value := maximum_value value := maximum_value
} else if (value < minimum_value) {
value := minimum_value
} }
return (value / maximum_value) return (value - minimum_value) / (maximum_value - minimum_value)
} }