How to efficiently write OSC values in a MutableList?

Hello everyone,

I am trying to find a convenient way to parse osc value from almost identical addresses (like « /test1, /test2, /test3 etc…) into a MutableList so I can then reuse this values into chosen parameters, let’s say circles radiuses.

I came up with this idea :

 program {

	var radius = 0.0f
	val radiusList = mutableListOf(radius)

	val osc = OSC(InetAddress.getByName(, portIn = 12345, portOut = 1000)
	for (i in 0 until 3){
		osc.listen(String.format(« /test%01d », i)) { addr, it → 			
            radius = it[0] as Float
 			radiusList[i] = radius

 extend {

I send OSC from Ableton Live, using the OSC Send Max4Live module mapped to some knobs on an audio effect rack. Everything is fine when I move the first knob, mapped to /test0 here. But if I move the second knob, mapped to /test1 the console return
Index 1 out of bounds for length 1 (IndexOutOfBoundsException)
I am not a programming expert and I might have overlooked something obvious. Any advice would be helpful, I will take another look at the Kotlin documentation in the meantime. Thanks in advance and have a good day/night !

Quick update, it helped to specify a fixed size, here 3, for the MutableList.

Instead of

val radiusList = mutableListOf(radius)

I use

var radiusList = MutableList(3) {0f}

and it works as expected.

Marking this topic as solved, but feel free to reply if you find a better way !

1 Like

That sound like the right way to create mutable list of N elements. Great that you figured it out :slight_smile: