Old 06-11-2017, 09:31 PM   #1
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 1,388
Default Convert NI Reaktor PitchGate CV to MIDI via JS

Pitch is [-6dBFS...0dBFS] signal which represents [C-2...C8] notes.
And the Gate is implulses with with custom length.
Dear scripters, can anyone suggest me any starting point JS code example for this?

ps This takes me 2 minutes to build it in Reaktor, but Reaktor lost its MIDI out randomly with complex MIDI (seems Reaktor bug), so I`m searching for audio output way to control stuff.
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate
mpl is online now   Reply With Quote
Old 06-11-2017, 10:49 PM   #2
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 3,079
Default

So Pitch and Gate are Audio outputs of Reactor that don't hold audio signals but samples that represent the state of a control signal ? I.e. they are not meant to necessarily contain zero crossings ?

Is the Gate signal switching from zero (off) to 0dB (on) ?

I don't have Reactor so I would not be able to test...

-Michael
__________________
www.boa-sorte.de
mschnell is online now   Reply With Quote
Old 06-11-2017, 10:58 PM   #3
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 1,388
Default

(I`m totally noob in JSFX and it is my first JSFX code)

Yes, LeftRight pair of audio signal represents Pitch and Gate.
Here is what I get somehow working

Code:
desc:MPL_Test CV to MIDI

in_pin:left input
in_pin:right input

@init
  threshold_dB = -40;
  threshold = 10^(threshold_dB/20); // Gate threshold

@sample
  spl0=spl0;
  spl1=spl1;
  
  pitch = floor(spl0*120); 

  cur_smpl = abs(spl1);
  (last_smpl < threshold) && (cur_smpl > threshold) ? midisend(0, $x90, pitch, 127); // send MIDI Note On
  (last_smpl > threshold) && (cur_smpl < threshold) ? midisend(10, $x80, pitch); // send MIDI Note Off
  last_smpl = cur_smpl;

The only problem is for some reason MIDI NoteOff on implulse fall don`t let midi go to the synth ever.
The sequence of 8th notes from C3 to C4 looks like this (impulses are smoothed a bit on screenshot, they are approximately 100 samples width pulses):

https://drive.google.com/file/d/0B6U...ew?usp=sharing

Edit: seems fixed MIDI NoteOff partually (not working with very short impluses or very fast sequences), but timing still not good, maybe a MIDI protocoll specs not allow to proper timing.

__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate

Last edited by mpl; 06-11-2017 at 11:58 PM.
mpl is online now   Reply With Quote
Old 06-12-2017, 11:30 AM   #4
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 1,388
Default

Thanks to Eugen27771 found a solution!
It is sample offset compensation:

Code:
desc:MPL_CV to MIDI

in_pin:left input
in_pin:right input

@init
  threshold_dB = -80;
  threshold = 10^(threshold_dB/20); // Gate threshold
@block
  spl_cnt = 0;
@sample
  spl_cnt+=1;
  pitch = floor(spl0*120); 
  cur_smpl = abs(spl1);
  cur_smpl > threshold ? (gate = 1 ):( gate = 0);   
  (gate == 1 && last_gate != 1 && pitch > 0) ? 
    midisend(spl_cnt, $x90, pitch, 127); // send MIDI Note On
  (gate == 0 && last_gate == 1)  ?
    pitch == 0 ? midisend(spl_cnt, $x80, last_pitch):midisend(spl_cnt, $x80, pitch); // send MIDI Note Off
  last_gate = gate;
  last_pitch = pitch;
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate
mpl is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.