- 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:
parent
b450a06cc6
commit
bfc8dc51be
|
@ -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.
|
||||
*/
|
||||
|
||||
; *** New rule handler functions ***
|
||||
ProcessNote(device, channel, note, velocity, isNoteOn) {
|
||||
/*
|
||||
Add your own note filters here.
|
||||
|
||||
Example:
|
||||
if (isNoteOn and note == 20)
|
||||
{
|
||||
; Clamp the velocity to 80
|
||||
if (velocity > 80) {
|
||||
velocity := 80
|
||||
}
|
||||
gosub, SendNote ; send the note out.
|
||||
}
|
||||
*/
|
||||
global iInterface
|
||||
|
||||
if (note >= 1 and note <= 32) {
|
||||
VJoy_SetBtn(isNoteOn, iInterface, note)
|
||||
button_state_text := isNoteOn ? "On" : "Off"
|
||||
DisplayOutput("Button " + button_state_text, note)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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)
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
ProcessPitchBend(device, channel, value) {
|
||||
|
|
|
@ -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, 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|
|
||||
LV_ModifyCol(1, 105)
|
||||
LV_ModifyCol(2, 110)
|
||||
gui,14:Show, autosize xcenter y5, MidiMonitor
|
||||
|
||||
Return
|
||||
|
@ -117,19 +119,14 @@ Return
|
|||
; MIDI Rules dispatcher
|
||||
|
||||
MidiRules:
|
||||
if (statusbyte between 128 and 143) { ; Note off
|
||||
ProcessNote(0, chan, byte1, byte2, false)
|
||||
}
|
||||
if (statusbyte between 144 and 159) { ; Note on
|
||||
ProcessNote(0, chan, byte1, byte2, true)
|
||||
}
|
||||
if (statusbyte between 176 and 191) { ; CC
|
||||
if (statusbyte >= 128 and statusbyte <= 159) { ; Note off/on
|
||||
isNoteOn := (statusbyte >= 144 or byte2 == 0)
|
||||
ProcessNote(0, chan, byte1, byte2, isNoteOn)
|
||||
} else if (statusbyte >= 176 and statusbyte <= 191) { ; CC
|
||||
ProcessCC(0, chan, byte1, byte2)
|
||||
}
|
||||
if (statusbyte between 192 and 208) { ; PC
|
||||
} else if (statusbyte >= 192 and statusbyte <= 208) { ; PC
|
||||
ProcessPC(0, chan, byte1, byte2)
|
||||
}
|
||||
if (statusbyte between 224 and 239) { ; Pitch bend
|
||||
} else if (statusbyte >= 224 and statusbyte <= 239) { ; Pitch bend
|
||||
ProcessPitchBend(0, chan, pitchb)
|
||||
}
|
||||
; Maybe TODO: Key aftertouch, channel aftertouch,
|
||||
|
|
|
@ -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
|
||||
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
|
||||
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
|
||||
|
@ -46,6 +46,19 @@ gosub, midiMon ; see below - a monitor gui - see Midi_In_and_Gu
|
|||
|
||||
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 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.
|
|
@ -5,22 +5,21 @@ DisplayOutput(event, value) {
|
|||
LV_Add("",event,value)
|
||||
LV_ModifyCol(1,"center")
|
||||
LV_ModifyCol(2,"center")
|
||||
LV_ModifyCol(3,"center")
|
||||
LV_ModifyCol(4,"center")
|
||||
LV_ModifyCol(5,"center")
|
||||
If (LV_GetCount() > 10)
|
||||
{
|
||||
LV_Delete(1)
|
||||
}
|
||||
{
|
||||
LV_Delete(1)
|
||||
}
|
||||
}
|
||||
|
||||
ConvertCCValueToAxis(value, maximum_value, maximum_axis_value) {
|
||||
return Floor(ConvertCCValue(value, maximum_value) * maximum_axis_value)
|
||||
ConvertToAxis(value, maximum_axis_value) {
|
||||
return Floor(value * maximum_axis_value)
|
||||
}
|
||||
|
||||
ConvertCCValue(value, maximum_value) {
|
||||
ConvertCCValueToScale(value, minimum_value, maximum_value) {
|
||||
if (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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user