How To Create A New Duplex Application

Edit : I found below reason and a way to avoid it. That reason is that when activating daw mode of LPX, the midi input device MIDIIN2 (LPX MIDI) is disapper just a moment. Then the variables of the midi input device instance are inserted nil into. But MIDIIN2 reappers and starts to work agin. GC understands MIDIIN2 is not refered from any variables, so it will be closed by GC. So I write a code to re-create the midi input device again after activating daw mode and insert the midi input device to launchpadx.midi_in again. Now it is working as I expect it to.
Thank you for giving your time.


Hi, there. I’m creating a new duplex midi device of Launchpad X(LPX).
Could you have an idea for avoiding premature garbage collection for a midi input device in Duplex?

Assumption, LPX has 2 midi interfaces and communicates with DAW(Renoise) by switching them depending on its mode. After activating these midi interface in two Duplex processes, only one midi input device is closed in a little while. Of course, I don’t write any code calling device:release() (it is strange that only one midi input device is closed). Even if I don’t act anyting in Renoise after reloading all scripts, it will happen.

It is log clip when happen it,

~~~ load some tools ~~~

ScriptingTools: Initializing Scripting Tool: 'C:\Users\user\AppData\Roaming\Renoise\V3.4.4\Scripts\Tools\com.renoise.Duplex.xrnx\'...

MIDI: Opening MME Midi-In device 'LPX MIDI'
MIDI: Opening MME Midi-Out device 'LPX MIDI'
MIDI: Opening MME Midi-In device 'MIDIIN2 (LPX MIDI)'
MIDI: Opening MME Midi-Out device 'MIDIOUT2 (LPX MIDI)'

~~~ finish loading all tools, and few seconds later ~~~~

MIDI: Closing MME Midi-In device 'MIDIIN2 (LPX MIDI)'

I tried the propsed method which is declaring global variable to avoid gc. It has similar purpose of my problem.

I declare global variable of MidiInputDevice like this:

class "LaunchpadX" (MidiDevice)

LPXmidiin = nil
LPXmidiout = nil

function LaunchpadX:open()

  local input_devices = renoise.Midi.available_input_devices()
  local output_devices = renoise.Midi.available_output_devices()

  if table.find(input_devices, self.port_in) then
    local midiin = nil
    if self.interface_type == "midi" and LPXmidiin == nil then
       LPXmidiin = renoise.Midi.create_input_device(self.port_in,
        {self, _G[type(self)].midi_callback},
        {self, _G[type(self)].sysex_callback}
      )
      midiin = LPXmidiin
    else
      midiin = renoise.Midi.create_input_device(self.port_in,
        {self, _G[type(self)].midi_callback},
        {self, _G[type(self)].sysex_callback}
      )
    end

    self.midi_in = midiin
  else
    LOG("Notice: Could not create MIDI input device ", self.port_in)
  end

  if table.find(output_devices, self.port_out) then
    local midiout = nil
    if self.interface_type == "midi" and not "LPXmidiout" == nil then
      LPXmidiout = renoise.Midi.create_output_device(self.port_out)
      midiout = LPXmidiout
    else
      midiout = renoise.Midi.create_output_device(self.port_out)
    end

    self.midi_out = midiout
  else
    LOG("Notice: Could not create MIDI output device ", self.port_out)
  end

end

But it did not work. Its reason may be declaring in a MidiDevice of Duplex.
Any thoughts would be greatly appreciated.