ModScript: Using scripts for a better and richer integration with MIDI controllers (beta soon!)

It builds on lin-arm64 too :smiley:

ModScript lua doesn’t understand bitwise operators “>>” and “&”

or am I missing something ?

function scale_and_convert(f)
  -- Scales the float to 0..100.
  scaled = f * 100

  -- Converts the scaled float to two 7-bit numbers.
  upper = scaled >> 3
  lower = scaled & 0b111

  return upper, lower
end

I have changed to this, that seems to work so far (not tested with the korg minilogue XD yet)

config.frameDivider = 16
config.bufferSize = 32

done = false
buttonTrig = SchmittTrigger.new()

lastvalue_knob1 = 0
lastvalue_knob2 = 0

function process(block)

	value =  block.knobs[1]

        if (value ~= lastvalue_knob1) then
		lastvalue_knob1 = value
        	scaled = value * 100
  		upper = math.floor(scaled / 8)
  		lower = scaled % 8

                sendMidiMessage(CC, 98, 72) 	--NRPN 48h is User Param 1
        	sendMidiMessage(CC, 6, upper)   --Upper 5 bits of 8 bit value to CC#6
        	sendMidiMessage(CC, 63, lower)  --Lower 3 bits of 8 bit value to CC#63
        end

	value =  block.knobs[2]

        if (value ~= lastvalue_knob2) then
		lastvalue_knob2 = value
        	scaled = value * 100
  		upper = math.floor(scaled / 8)
  		lower = scaled % 8

                sendMidiMessage(CC, 98, 73) 	--NRPN 49h is User Param 2
        	sendMidiMessage(CC, 6, upper)   --Upper 5 bits of 8 bit value to CC#6
        	sendMidiMessage(CC, 63, lower)  --Lower 3 bits of 8 bit value to CC#63
        end
end

(it’s work in progress)

EDIT add: found in the ModScript makefile: luajit := dep/lib/libluajit-5.1.a

I guess lua 5.3 is needed to have included bitwise operators.

Edit2: add2 https://luajit.org/extensions.html I see now, i could have tried “bit.rshift” and “bit.band”

Something isn’t working right for me. I’ve tried to make the simplest possible script to debug, but I’m getting nothing:

I can turn the red LED on/off by changing the value at Line 46, but I can’t get any module to respond to a parameter change or reading a parameter on Lune or Pleine Lune. I’m running the Nightly build from GitHub, but didn’t recompile myself in Rack 2.4.1 on Windows. For good measure I tested the version you linked back in September, but still no dice.

“MS helper” does not display the correct module instance ID (this must have changed in Rack). edit: see below for a fix.

Use the ID reported by the target module right-click-menu


here, the module ID is “7992587039813875”

Simple example ModScript
config.frameDivider = 16
config.bufferSize = 1

function NewPatchMaster(id)
	mod = Module(id)
	mod.params = {
		["Controller 1"] = {index = 0, min = 0.000000, max = 1.000000, default = 0.000000},
		["Controller 2"] = {index = 1, min = 0.000000, max = 1.000000, default = 0.000000},
		["No name"] = {index = 2, min = 0.000000, max = 1.000000, default = 0.000000},
		["No name"] = {index = 3, min = 0.000000, max = 1.000000, default = 0.000000},
		["No name"] = {index = 4, min = 0.000000, max = 1.000000, default = 0.000000},
		["No name"] = {index = 5, min = 0.000000, max = 1.000000, default = 0.000000},
		["No name"] = {index = 6, min = 0.000000, max = 1.000000, default = 0.000000},
		["No name"] = {index = 7, min = 0.000000, max = 1.000000, default = 0.000000},
	}
	mod.inputs = {
	}
	mod.outputs = {
	}
	mod.lights = {
		{index = 0},
		{index = 1},
		{index = 2},
		{index = 3},
		{index = 4},
		{index = 5},
		{index = 6},
		{index = 7},
		{index = 8},
		{index = 9},
		{index = 10},
		{index = 11},
		{index = 12},
		{index = 13},
		{index = 14},
		{index = 15},
		{index = 16},
		{index = 17},
		{index = 18},
		{index = 19},
		{index = 20},
		{index = 21},
		{index = 22},
		{index = 23},
		{index = 24},
		{index = 25},
		{index = 26},
		{index = 27},
		{index = 28},
		{index = 29},
		{index = 30},
		{index = 31},
		{index = 32},
		{index = 33},
		{index = 34},
		{index = 35},
		{index = 36},
		{index = 37},
		{index = 38},
		{index = 39},
		{index = 40},
		{index = 41},
		{index = 42},
		{index = 43},
		{index = 44},
		{index = 45},
		{index = 46},
		{index = 47},
		{index = 48},
		{index = 49},
		{index = 50},
		{index = 51},
		{index = 52},
		{index = 53},
		{index = 54},
		{index = 55},
		{index = 56},
		{index = 57},
		{index = 58},
		{index = 59},
		{index = 60},
		{index = 61},
		{index = 62},
		{index = 63},
		{index = 64},
		{index = 65},
		{index = 66},
		{index = 67},
		{index = 68},
		{index = 69},
		{index = 70},
		{index = 71},
	}
	return mod
end

myPM = NewPatchMaster(7992587039813875)

function process(block)

	value = myPM:getParam("Controller 1")
	display('Controller 1: ' .. value)

	value = myPM:getParam("Controller 2")
	display('Controller 2: ' .. value)

end

Result is live values scrolling, if Rack was started in a shell.

[2508.086 debug src/LuaJITEngineAPI.cpp:6 display] Controller 1: 0.5
[2508.086 debug src/LuaJITEngineAPI.cpp:6 display] Controller 2: 0
1 Like

Looks like it’s showing a left-truncated version of the hex value, so the eight rightmost digits. The full hex is 0x1C65372F5830F3

1 Like

Around here, I think:

way over my C++ skills to fix it.

It’s been too long since I did any C++ for me to suggest the fix, other than bumping up the size of hexID.

Thanks for the tip.

changed two occurences of %lx to %llx in LuneHelper.cpp - and the “long long” hex shows.

$ diff LuneHelper.cpp LuneHelper.cpp.new
89c89
<                       sprintf(hexID, "0x%lx", hoveredModule);
---
>                       sprintf(hexID, "0x%llx", hoveredModule);
147c147
<                               moduleIdLabel->text = string::f("0x%lx", (int64_t)hoveredModule);
---
>                               moduleIdLabel->text = string::f("0x%llx", (int64_t)hoveredModule);
224c224

4 Likes

Thanks for the contributions and fixes provided. I have just pushed a fix for this and tried to credit both correctly. The new nightly should be up now!

At this point I am willing to grant commit access to the repo if anyone wants to contribute. I feel honored that people are actually using ModScript and even take on the task of fixing my own blunders, hehe. More generally don’t hesitate to ping me on Discord in the # development channel if I’m not active here. Thanks!

@Vega Did you get ModScript to work the way you needed it? And hello by the way! :slight_smile:

3 Likes

Hi, Welcome back :slight_smile:

Hello :wave: Yep, got it working. Really digging ModScript!

1 Like