Using notifiers to always toggle autofade = ON after recording?


(esaruoho) #1

Hi, how would I go about making it so that every time that I record, when the recording is complete, the autofade=true is triggered after sample has been written to the Instrument Box?

I’m no good with notifiers, so could use some halp :o


(Raul (ulneiz)) #2

Hi, how would I go about making it so that every time that I record, when the recording is complete, the autofade=true is triggered after sample has been written to the Instrument Box?

I’m no good with notifiers, so could use some halp :o

Related documentation:

-- Selected in the instrument's sample list. Only nil when no samples 
-- are present in the selected instrument.
renoise.song().selected_sample, _observable
  -> [read-only, renoise.Sample object or nil]

-- Has sample data?
renoise.song().instruments[].samples[].sample_buffer.has_sample_data
  -> [read-only, boolean]

renoise.song().instruments[].samples[].autofade, _observable
  -> [boolean]

-- Invoked periodically in the background, more often when the work load
-- is low, less often when Renoise's work load is high.
-- The exact interval is undefined and can not be relied on, but will be
-- around 10 times per sec.
-- You can do stuff in the background without blocking the application here.
-- Be gentle and don't do CPU heavy stuff please!
renoise.tool().app_idle_observable
  -> [renoise.Document.Observable object]

I have built a solution that checks the status of the autofade after recording the sample, using an idle_obserbable notifier and a checkbox to activate it. Make sure you add this checkbox (CHECKBOX_AUTOFADE) in your GUI and activate it manually when you need it.Personally, I do not like having an idle_notifier working all the time. I think it’s better to have control with a checkbox.

--globals
vb = renoise.ViewBuilder()
vws = vb.views
rna = renoise.app()
rnt = renoise.tool()

--automatic autofade function
function enable_autofade()
  --print("working")
  local song = renoise.song()
  --check if the Sample Recorder dialog is visible 
  if ( rna.window.sample_record_dialog_is_visible == false ) then
    return
  else
    --check if the selected instrument has at least one sample slot available
    if ( song.selected_sample == nil ) then
      return
    else
      --check if the selected sample has a buffer
      if ( song.selected_sample.sample_buffer.has_sample_data == false ) then
        return
      else
        --check if the selected sample has the autofade false
        if ( song.selected_sample.autofade == true ) then
          return
        else
          --enable autofade
          song.selected_sample.autofade = true
        end
        --here you can change other properties of the sample
        --
        --
      end
    end
  end
end

--checkbox function with idle_obserbable for enable_autofade()
function checkbox_autofade()
  if ( CHECKBOX_AUTOFADE.value == false ) then
    if ( rnt.app_idle_observable:has_notifier(enable_autofade) ) then
      rnt.app_idle_observable:remove_notifier(enable_autofade)
    end
  else
    if not ( rnt.app_idle_observable:has_notifier(enable_autofade) ) then
      rnt.app_idle_observable:add_notifier(enable_autofade)
    end
  end
end

--checkbox for automatic autofade function
CHECKBOX_AUTOFADE = vb:checkbox {
  value = false,
  notifier = function() checkbox_autofade() end,
  tooltip = "Enable/disable automatic autofade with Sample Recorder"
}

Maybe there is a more elegant and direct way to solve it, with a specific observable, that you check only once after recording the sample. This would avoid the idle_observable.

Is there an observable to indicate that the sample recording is over?

Edit :This could also be done with a slower timer, about 500ms or something like that. So not so many checks.

Edit2 :Keep in mind that it will also activate the autofade when you insert any new sample, even when you activate the checkbox(CHECKBOX_AUTOFADE) when there is a selected sample, as long as the Sample Recorder dialog is active…Be careful with this.