[Solved] Help, code for play/stop specific note of a instrument, is po

It should flash, very briefly, since it’s temporarily switching off edit_mode to prevent recording any notes. If edit_mode was on before, it should be on after.

The reason why you’re getting a strange behavior is likely due to the dubious structure of your code, specifically the way you handle the player object (rather creating two separate objects for pressed/released, which is not optimal).

Create one player object (with no_autoplay = true) in the scope above the button creation, then call my_player:play() and my_player.stop() from the pressed/released notifiers.

I think (!) it is enough if the workaround goes inside the OscPlayer:play() function. IIRC “orphan” note-offs won’t get recorded anyway.

I true this:

function OscPlayer:__init( client, voices, duration, no_autoplay )
  self.client = client
  self.voices = voices
  --self.duration = duration

  self._playing_voices = { }
  self._release_func = function() self:stop() end
  --don't autoplay if true
  if not no_autoplay then
    self:play()
  end  

----delay edit_mode 40ms 
  local stored_edit_mode = renoise.song().transport.edit_mode
  -- we only need the workaround if recording mode was on. let's not clutter memory/cpu otherwise ;)
  if stored_edit_mode then
    renoise.song().transport.edit_mode = false
end
  -- put playing trigger here!
  -- reset to edit_mode = true after some delay
  if stored_edit_mode then
    local timer_func
    timer_func = function()
            renoise.song().transport.edit_mode = true
            renoise.tool():remove_timer(timer_func) -- works?
        end
    renoise.tool():add_timer(timer_func, 40)
  end
end

Keep writing one note (or two notes, depending the timer), when press the mouse.

What exactly happens (in slow process):

  1. Pressing click: write note A in note column 01
  2. Releasing click: write note B (the same note A) in note column 02

That is, as the gif shows.

This seems to work perfectly fine here…

local button = vb:button {
      text = tostring(note_value),
      pressed = function()
          local stored_edit_mode = renoise.song().transport.edit_mode
          if stored_edit_mode then
              renoise.song().transport.edit_mode = false
          end
      
          osc_client:trigger_instrument(true, instrument, track, note_value, velocity)
  
          if stored_edit_mode then
            local timer_func
            timer_func = function()
                renoise.song().transport.edit_mode = true
                renoise.tool():remove_timer(timer_func)
              end
            renoise.tool():add_timer(timer_func, 40)
          end      
        end,
      released = function()
          osc_client:trigger_instrument(false, instrument, track, note_value, velocity)
        end,
    }

A practical example is attached.

7145 joule.no0b.testpad.xrnx

This seems to work perfectly fine here…

local button = vb:button {
text = tostring(note_value),
pressed = function()
local stored_edit_mode = renoise.song().transport.edit_mode
if stored_edit_mode then
renoise.song().transport.edit_mode = false
end
      
osc_client:trigger_instrument(true, instrument, track, note_value, velocity)
  
if stored_edit_mode then
local timer_func
timer_func = function()
renoise.song().transport.edit_mode = true
renoise.tool():remove_timer(timer_func)
end
renoise.tool():add_timer(timer_func, 40)
end      
end,
released = function()
osc_client:trigger_instrument(false, instrument, track, note_value, velocity)
end,
}

A practical example is attached.

attachicon.gifjoule.no0b.testpad.xrnx

Is there a problem with setting the value “15” or “10” or “5” instead of 40?Why 40?With value <16 edit_modenot blinking, but I do not know if it depends on the hardware.

The “left click repeat rate” in preferences/Keys/Mouse Wheel has something to do?

I’ll try to build a new piano based on your code, even if it means starting over. I want the tool to work as fine as possible. I believe that with all this I can move forward.I also have another option in mind, edit the notes without using edit_mode.In this case, osc server would be canceled, and the notes would not sound if active edit_mode. As I have my code, I have a separate configuration for each button.I think I understand all your code, and I can use it to compress it to the maximum (within my possibilities).

Thank you very much for all this!I think it’s the best solution for this case.

…withmy_player:play() and my_player.stop(),I had an error in the terminal, by using them separately in “pressed” and “released” of the button.I was doing something wrong.

I will continue to build, and when I have something fine I will comment here, maybe this weekend.

Yeah, I could use 10ms to avoid any noticable flickering, but that’s on an I7 processor. To be safe on slower computers, I would guess that 40ms would be OK. I’d suggest making a stress test in 1 core mode while using a couple of heavy VST/VSTi:s.

Yeah, I could use 10ms to avoid any noticable flickering, but that’s on an I7 processor. To be safe on slower computers, I would guess that 40ms would be OK. I’d suggest making a stress test in 1 core mode while using a couple of heavy VST/VSTi:s.

Ok, I’ll try it on a laptop.My main PC has an i7.I’ll have to test things on 2 PCs, one fast and one slow. :slight_smile:

I point out this topic as solved.