New Tool (2.8): Pitch Device Automator

Update June 7th:
V1.08
Corrected a crash problem with a garbage collected variable.

Update May 28th:
Removed the toolpage on advise of Taktik.
V1.07
Corrected forgotten reference changes causing pitch alterations of other instruments when browsing through the devices or instruments.

V1.06
Also fixed a problem where pitch devices were affecting other pitch device linked instruments that were not linked to that device.

V1.05(.001)
-Fixed problem with adding another pitch device on the same track not getting renamed properly. not a biggy, but updated the tool on the toolpage without updating the version number!

V1.05
-Optimised pitch-bend controller recording (routine is only applied when recording mode is on and the specific pitch device is selected)
-Fixed sample transpose option (wasn’t accurate) with the semitones.
-Added smooth transitions between semitones for the sample transpose by altering Pitch LFO1.

Update May 27th:
V1.03
-Found a way to support recording the pitch bend wheel messages to automation, but i don’t think it is of much use (unless you’re doing slow transitions) :D rather advise to map a controller to the slider instead.
The current status is not half-baked but still half-assed.

V1.02
-Fixed issue where sample transpose got influenced while automated during instrument selections.
-Fixed app-crash that choked on ea_gui at line 316
-Several optimisations applied.

I had the basic framework up in a few hours to control one instrument with one pitch device.
I have expanded it to make it work with multiple automatable devices on several tracks.

To add a device to a track either rightclick in the mixer or somewhere in the DSP rack and select “Add favorite DSP” (I assume it will become your favorite DSP) and then Add Pitch device.

On the bottom you have the option to pop up a dialog where you can set specific options to set.

Because i have no access to the linked instrument parameter and all the parameter names and properties of the midi control device, i stuff this info in the device name:


Do not touch the device title. if you accidentally do so and did removed something that you don’t know, then simply erase all the figures and comma’s yet leave the title intact.

You can pick two instrument transpose options to alter:The pitch envelope or the sample transpose. By default, the pitch envelope is picked. it will add or decrease the transpose value to the current sample transpose value, so if it was tuned, it wil remain tuned. This doesn’t count so for the pitch envelope, so if you already are using the pitch envelope for a specific instrument effect, then rather go for the sample transpose.
The maximum transpose range that you can set is 12 semitones (up and down).
The midi device is to route the pitch-bend controller to the instrument and allowing you to record your device actions to automation. Do not record the pitch bend to the pattern editor!

I have used creation of dynamic functions, not using the _G[‘foo’] option, but a similar way to attach notifiers to the devices.

The tool is reasonably usable, but don’t expect that you can use hundreds of these devices and have them working smooth because Lua still has its boundaries, even if functions are realtime fired by notifiers.

I have added monitoring of instrument changes, track changes (swap / add / remove) and songrelease/loading but i don’t expect it to work that super.
Your configurations are saved with the song and automatically set after reloading so automation would most likely work without having toggle something.
If you notice some change is not working, try selecting another instrument and then back to the previous one, but i hope i have catched all situations where changes are propagated.

Woohoo. I’ve wanted something like this for a long time.

Just after installation, I added the device. Then it said:

'...\Renoise\V2.8.0\Scripts\Tools\com.vvoois.Envelope_pitch_automater.xrnx\' failed to execute in one of its menu entry functions.  
  
Please contact the author (v.voois) for assistance...  
  
main.lua:316: attempt to index global 'ea_gui' (a nil value)  
stack traceback:  
 main.lua:316: in function 'set_pitch_device_properties'  
 main.lua:379: in function <370><br>```

<br>
<br>
It seems to work, though.<br>
Using Renoise 2.8, WinXP.</370>

[quote=“Drop Shadow, post:2, topic:36400”]
Woohoo. I’ve wanted something like this for a long time.

Just after installation, I added the device. Then it said:

'...\Renoise\V2.8.0\Scripts\Tools\com.vvoois.Envelope_pitch_automater.xrnx\' failed to execute in one of its menu entry functions.  
  
Please contact the author (v.voois) for assistance...  
  
main.lua:316: attempt to index global 'ea_gui' (a nil value)  
stack traceback:  
 main.lua:316: in function 'set_pitch_device_properties'  
 main.lua:379: in function <370><br>```

<br>
<br>
It seems to work, though.<br>
Using Renoise 2.8, WinXP.<br>[/quote]<br>
<br>
system should not matter in this case, i'll have a look, also try to optimize a few things today.<br>
Had a good night sleep and woke up with some new fresh ideas this morning.</370>

I have uploaded an update which fixes a few things, also wrong behavior with the sample transpose sliders.
I could use some help with the math optimisations, if you do a lot of intensive changes, you notice that Lua has a problem to keep up with the notifiers.
I can accomplish desired results, but i’m not that kind of a math expert that i also can get the algorithms optimized enough or at least i don’t have the proper experience with these things. So any math wizard here that could optmize this below snippet to a better performance?

 local slider_max_value = 127  
 local factor = 100  
  
 --Calculation of the pitch envelope point values  
 --the pitch range is always in semitones  
 --the envelope range is +1200 and -1200, these are translated to float-values that range from 0 to 1  
 --In short: the current pitch-bend value of 0 to 127 should translate to the pitch range:  
 --0 to 63.5 = (-)pitch_range to 0, 63.5 is the 'center' of the midi dev. PB slider. The pitch bend controller value of 64 has already been translated to 63.5   
 --63.5 to 127 = 0 to pitch_range  
 --(-)pitch_range to 0 = the lower portion in the 0 to 0.5 range (multiplied by the factor)  
 --0 to pitch_range = the higher portion in 0.5 to 1 range.   
 local pitch_center = (pitch_range*factor)/2   
 local pitch_envelope_range = 1200  
 local pitch_range_one_percent = (pitch_range/slider_max_value) *factor  
 local slider_value = (pitch_range_one_percent* selected_pitch_device.parameters[1].value)  
 local envelope_point_val = 0.5+(1/pitch_envelope_range*slider_value) - (1/pitch_envelope_range*pitch_center)   
  
 if slider_value <= pitch_center then  
 local offset = (1/pitch_envelope_range*pitch_center) - (1/pitch_envelope_range*slider_value)  
 envelope_point_val = 0.5-(offset)  
 end  
  
------------------------------------------------------------------------------   
 --Calculation of the transpose slider values  
 --these translations go a little easier as simply 0 to 127 is only divided into 0-64 and 65-127.  
 --0 to 63.5 = (-)pitch_range to 0  
 --63.5 to 127 = 0 to pitch_range  
 --After that the floats are rounded and the transpose values are send.  
  
 local samples = song.instruments[selected_instrument].samples  
 local pitch_center = (slider_max_value+1)/2  
 local pitch_range_one_percent = (pitch_range/pitch_center)  
 local slider_value = pitch_range_one_percent* (selected_pitch_device.parameters[1].value/2)  
  
 if selected_pitch_device.parameters[1].value <= pitch_center then  
 slider_value = (pitch_range_one_percent* selected_pitch_device.parameters[1].value)  
 slider_value = pitch_range - slider_value  
 slider_value = 0 - slider_value   
 end  
  
 slider_value = math.round(slider_value)  
  

Thanks.

Oh Yes! Massive Thanks!

new update.
Also changed the menu context entry for adding the device. Added “Add Tool Device” submenu.

Final update and a tool page is up now.
Manual PDF is added to the tools page.

this is great ! :yeah:

Also fixed a problem where pitch devices were affecting other pitch device linked instruments that were not linked to that device.

crazy props

I get this error when adding the device and adding any other device to the chain;

'C:\Documents and Settings\Ian\Application Data\Renoise\V2.8.0\Scripts\Tools\com.vvoois.Envelope_pitch_automater.xrnx\main.lua' failed in one of its notifiers.  
The notifier will be disabled to prevent further errors.  
  
Please contact the author (v.voois) for assistance...  
  
No matching overload found, candidates:  
custom [class LuaMidiInputDeviceRef] create_input_device(custom [class String] const&,luabind::object const&,luabind::object const&,lua_State*)  
custom [class LuaMidiInputDeviceRef] create_input_device(custom [class String] const&,luabind::object const&,lua_State*)  
stack traceback:  
 [C]: in function 'create_input_device'  
 .\midi_device.lua:17: in function 'start'  
 .\midi_control.lua:14: in function 'midi_engine'  
 main.lua:318: in function 'monitor_pitch_bend_controller'  
 main.lua:243: in function 'set_pitch_device_notifier'  
 main.lua:219: in function <161><br>```

<br>
<br>
And I get this sometimes when entering automation;<br>
<br>

```<br>'C:\Documents and Settings\Ian\Application Data\Renoise\V2.8.0\Scripts\Tools\com.vvoois.Envelope_pitch_automater.xrnx\main.lua' failed in one of its notifiers.<br>
The notifier will be disabled to prevent further errors.<br>
<br>
Please contact the author (v.voois) for assistance...<br>
<br>
std::logic_error: 'invalid amount value '128'. valid values are (0 to 127).'<br>
stack traceback:<br>
  [C]: ?<br>
  [C]: in function '__newindex'<br>
  [string "do..."]:22: in function <br>
  main.lua:564: in function 'set_pitchbend_slider'<br>
  main.lua:209: in function <204><br>```

</204></161>

[quote=“Dunks, post:11, topic:36400”]
I get this error when adding the device and adding any other device to the chain;

'C:\Documents and Settings\Ian\Application Data\Renoise\V2.8.0\Scripts\Tools\com.vvoois.Envelope_pitch_automater.xrnx\main.lua' failed in one of its notifiers.  
The notifier will be disabled to prevent further errors.  
  
Please contact the author (v.voois) for assistance...  
  
No matching overload found, candidates:  
custom [class LuaMidiInputDeviceRef] create_input_device(custom [class String] const&,luabind::object const&,luabind::object const&,lua_State*)  
custom [class LuaMidiInputDeviceRef] create_input_device(custom [class String] const&,luabind::object const&,lua_State*)  
stack traceback:  
 [C]: in function 'create_input_device'  
 .\midi_device.lua:17: in function 'start'  
 .\midi_control.lua:14: in function 'midi_engine'  
 main.lua:318: in function 'monitor_pitch_bend_controller'  
 main.lua:243: in function 'set_pitch_device_notifier'  
 main.lua:219: in function <161><br>```

<br>
<br>
And I get this sometimes when entering automation;<br>
<br>

```<br>'C:\Documents and Settings\Ian\Application Data\Renoise\V2.8.0\Scripts\Tools\com.vvoois.Envelope_pitch_automater.xrnx\main.lua' failed in one of its notifiers.<br>
The notifier will be disabled to prevent further errors.<br>
<br>
Please contact the author (v.voois) for assistance...<br>
<br>
std::logic_error: 'invalid amount value '128'. valid values are (0 to 127).'<br>
stack traceback:<br>
  [C]: ?<br>
  [C]: in function '__newindex'<br>
  [string "do..."]:22: in function <br>
  main.lua:564: in function 'set_pitchbend_slider'<br>
  main.lua:209: in function <204><br>```

<br>[/quote]<br>
<br>
<br>
The first problem i can't recreate, it is midi device related, the second problem i have a hunch what that may be. What version were you using? Can you try 1.07 (nobody downloaded 1.07 yet)? it includes the possible fix for problem 2.<br>
Regarding problem one, i need the version number of the version that you are using now before updating to 1.07. I have added the "None" device again, i don't know what midi deviecs you have, but i suspect it fails so on the default Windows midi playback device.</204></161>

It was V1.06, I will try 1.07.

V1.07 solved the issue when addig this device or any other, I will test some more with the Automation and report back later. Cheers.

Love this tool.
Two errors.

  1. Open device
  2. Change to sample transpose
  3. Close device
  4. Open device

Result:

main.lua:417: variable 'song' is not declared  
stack traceback:  
 [C]: in function '_error'  
 [string "local mt = getmetatable(_G)..."]:29: in function   
 main.lua:417: in function 'set_pitch_device_properties'  
 main.lua:526: in function <515><br>```

<br>
<br>
Another error:<br>
1. Open device (and change to sample transpose if it's set to pitch envelope)<br>
2. Put commands controlling the pitchbend in entire pattern (11xx on every line)<br>
3. Play<br>
4. Close device<br>
<br>
Result (cirka 50 pct. of the time so try a few times if you don't get the bug instantly):<br>
<br>

```<br>… failed in one of its notifiers.<br>
The notifier will be disabled to prevent further errors.<br>
<br>
Please contact the author (v.voois) for assistance...<br>
<br>
main.lua:556: attempt to index global 'selected_pitch_device' (a nil value)<br>
stack traceback:<br>
  main.lua:556: in function 'set_pitchbend_slider'<br>
  main.lua:262: in function <257><br>```

</257></515>

[quote=“Drop Shadow, post:14, topic:36400”]
Love this tool.
Two errors.

  1. Open device
  2. Change to sample transpose
  3. Close device
  4. Open device

Result:

main.lua:417: variable 'song' is not declared  
stack traceback:  
 [C]: in function '_error'  
 [string "local mt = getmetatable(_G)..."]:29: in function   
 main.lua:417: in function 'set_pitch_device_properties'  
 main.lua:526: in function <515><br>```

<br>[/quote]<br>
<br>
Good Find...<br>
This one is fixed.<br>
<br>
<br>
[quote="Drop Shadow, post:14, topic:36400"]<br>
Another error:<br>
1. Open device (and change to sample transpose if it's set to pitch envelope)<br>
2. Put commands controlling the pitchbend in entire pattern (11xx on every line)<br>
3. Play<br>
4. Close device<br>
<br>
Result (cirka 50 pct. of the time so try a few times if you don't get the bug instantly):<br>
<br>

```<br>… failed in one of its notifiers.<br>
The notifier will be disabled to prevent further errors.<br>
<br>
Please contact the author (v.voois) for assistance...<br>
<br>
main.lua:556: attempt to index global 'selected_pitch_device' (a nil value)<br>
stack traceback:<br>
  main.lua:556: in function 'set_pitchbend_slider'<br>
  main.lua:262: in function <257><br>```

<br>[/quote]<br>
<br>
I have not been successful in producing this one, but i have an idea that in rare occasions the function is called when a notifier was fired just before the device got removed.<br>
Tried to blind fix it, can you still reproduce this problem with 1.08?</257></515>

No, I can’t. It seems like you fixed it all. Thanks.

I think I found a minor bug:

When you change the “Linked instrument” from X to Y, pitch bend changes will still apply to instrument X.

It works when you change the instrument in the “Pitch properties” dialog though.

The linked instrument is not used at all (its value is not available / adjustable for us scripters).
The script uses only the device its name-title to bind it to an instrument, you will also see the number change in the title if you change it through its properties.
I can listen to instrument changes if they are swapped in the list, but the only thing i could then to is unbind the link, but not guess to where the other bound instrument got moved to. (we don’t have unique id’s available to pinpoint specific instruments/tracks/columns, all kinds of stuff that you can drag and swap)

Suspected the issue had to do with limited access to some renoise functions. Thanks for clarifying.

Another thing though.
When bringing the cursor to a track containing a Pitch Device, the instrument linked to that device will be “catured” (as in auto capture instrument).
Maybe necessary for the device to work?
If not, it would be nice if the device wouldn’t do that.

(If enabled, Renoise’s native auto capture function will override the Pitch Device capture.)