Using a CC-knob to run a script when at 127 and ...

Hi, how would I go about using a midicontroller CCKnob to toggle two settings as “true” when the knob hits 127, and set those settings as “false” when the knob hits anything below 127?

i was trying to use toggle-scripts like this:

renoise.tool():add_midi_mapping {name="Global:Paketti:Record and Follow On/Off x[Toggle]", invoke = function() RecordFollowToggle() 
renoise.app().window.active_middle_frame=1 end}

but it keeps toggling rec+follow on/off everytime i move the knob.

i need to be able to twist a knob and forget about it, cos i know i did something with the knob that set it to max - and a script ran, then twist the knob again, below the max, and to know that the functions will be run for sure…

How can this be done?

it keeps toggling rec+follow on/off everytime i move the knob

Of course, because you are not checking any condition: “If this, then do that”

You need to add something like the following:

function(message)
if (message.int_value == 127) then
 -- do something at top
elseif (value == 0) then
 -- do something else at bottom
else
 -- do something inbetween
end
end

At the very least…

Of course, because you are not checking any condition: “If this, then do that”

You need to add something like the following:

function(message)
if (message.int_value == 127) then
-- do something at top
elseif (value == 0) then
-- do something else at bottom
else
-- do something inbetween
end
end

At the very least…

Hi danoise, I tried this but it doesn’t seem to work:

renoise.tool():add_midi_mapping {name="Global:Paketti:Record and Follow On/Off x[Knob]", invoke = function(midi_message) 
local t=renoise.song().transport
renoise.app().window.lock_keyboard_focus=true
renoise.app().window.active_middle_frame=1 
if (midi_message.int_value >= 100) then
t.edit_mode = true
t.follow_player = true
else end

if (midi_message.int_value <= 127) then
t.edit_mode = false
t.follow_player = false
else end
end}

Harrumph. All I needed to do was make it send a return right after t.edit_mode+t.follow_player = true and everything works.

renoise.tool():add_midi_mapping {name="Global:Paketti:Record and Follow On/Off x[Knob]", invoke = function(midi_message) 
local t=renoise.song().transport
renoise.app().window.lock_keyboard_focus=true
renoise.app().window.active_middle_frame=1 
oprint (midi_message.int_value)

if (midi_message.int_value >= 100) then
t.edit_mode = true
t.follow_player = true return
else end

if (midi_message.int_value <= 127) then
t.edit_mode = false
t.follow_player = false
else end
end}

Harrumph. All I needed to do was make it send a return right after t.edit_mode+t.follow_player = true and everything works.

If we examine the structure of your code a bit more and make a few simple tweaks, this extra stuff is not necessary.

(midi_message.int_value <= 127) will always evaluate to true, since int_value will always be a value from 0 to 127, so the second if/then check is not really needed. We simply have to alter the structure of the first if/then/else block to handle both cases.

renoise.tool():add_midi_mapping {name="Global:Paketti:Record and Follow On/Off x[Knob]", invoke = function(midi_message) 
  
  renoise.app().window.lock_keyboard_focus = true
  renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR 

  local t = renoise.song().transport

  if (midi_message.int_value >= 100) then
    t.edit_mode = true
    t.follow_player = true 
  else 
    t.edit_mode = false
    t.follow_player = false
  end

end}

If we examine the structure of your code a bit more and make a few simple tweaks, this extra stuff is not necessary.

(midi_message.int_value <= 127) will always evaluate to true, since int_value will always be a value from 0 to 127, so the second if/then check is not really needed. We simply have to alter the structure of the first if/then/else block to handle both cases.

Awesome! I modified that a bit and got this:

renoise.tool():add_midi_mapping {name="Global:Paketti:Record and Follow On/Off x[Knob]", invoke = function(midi_message) 
--Aided by dblue
  renoise.app().window.lock_keyboard_focus = true
  renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR 

 local t=renoise.song().transport

if (midi_message.int_value == 127) then t.edit_mode = true t.follow_player = true t.playing = true
else end
if (midi_message.int_value == 0) then t.edit_mode = false t.follow_player = false t.playing = false
else end

    if (midi_message.int_value >= 100) then
      t.edit_mode = true
      t.follow_player = true 
    else 
      t.edit_mode = false
      t.follow_player = false
    end
end}

so now i have a really rather decent knob that does everything i want to. i turn it to 127 - it starts playback, takes to pattern editor, follows pattern, edit_mode = on. i turn to below 100, playback continues, pattern editor, patternfollow+edit=off. i turn to 0, playback stops, pattern editor, pfollow+edit=off.

i guess the next step is to apply this kind of thinking to another knob, maybe to take one to phrase editor or something. either that, or start sample recorder and start sampling. should be intriguing.

Edit: Thanks dblue!!