samedi 27 août 2016

Help needed: Minor change to my modded midi note repeater

Hello JS Wizards...

I made some mods to a midi note repeater JS I found, but there's one mod I need and I can't figure it out...

Here's the code:

Code:

desc:MIDI Note Repeater
//tags: MIDI processing

//slider1:1<8,0,0.03125>Beats
//slider1:1<8,0,.0625>Beats

in_pin:none
out_pin:none

slider1:1<16,0,.001>Beats
slider2:60<0,127,1{0: C-1,1: C#/Db-1,2: D-1,3: D#/Eb-1,4: E-1,5: F-1,6: F#/Gb-1,7: G-1,8: G#/Ab-1,9: A-1,10: A#/Bb-1,11: B-1,12: C0,13: C#/Db0,14: D0,15: D#/Eb0,16: E0,17: F0,18: F#/Gb0,19: G0,20: G#/Ab0,21: A0,22: A#/Bb0,23: B0,24: C1,25: C#/Db1,26: D1,27: D#/Eb1,28: E1,29: F1,30: F#/Gb1,31: G1,32: G#/Ab1,33: A1,34: A#/Bb1,35: B1,36: C2,37: C#/Db2,38: D2,39: D#/Eb2,40: E2,41: F2,42: F#/Gb2,43: G2,44: G#/Ab2,45: A2,46: A#/Bb2,47: B2,48: C3,49: C#/Db3,50: D3,51: D#/Eb3,52: E3,53: F3,54: F#/Gb3,55: G3,56: G#/Ab3,57: A3,58: A#/Bb3,59: B3,60: C4,61: C#/Db4,62: D4,63: D#/Eb4,64: E4,65: F4,66: F#/Gb4,67: G4,68: G#/Ab4,69: A4,70: A#/Bb4,71: B4,72: C5,73: C#/Db5,74: D5,75: D#/Eb5,76: E5,77: F5,78: F#/Gb5,79: G5,80: G#/Ab5,81: A5,82: A#/Bb5,83: B5,84: C6,85: C#/Db6,86: D6,87: D#/Eb6,88: E6,89: F6,90: F#/Gb6,91: G6,92: G#/Ab6,93: A6,94: A#/Bb6,95: B6,96: C7,97: C#/Db7,98: D7,99: D#/Eb7,100: E7,101: F7,102: F#/Gb7,103: G7,104: G#/Ab7,105: A7,106: A#/Bb7,107: B7,108: C8,109: C#/Db8,110: D8,111: D#/Eb8,112: E8,113: F8,114: F#/Gb8,115: G8,116: G#/Ab8,117: A8,118: A#/Bb8,119: B8,120: C9,121: C#/Db9,122: D9,123: D#/Eb9,124: E9,125: F9,126: F#/Gb9,127: G9}>note
slider3:.0625<1,0,.001>Beat Quant
slider4:1<16,0,.001>Qtz'd Beat
slider5:1<1,16,1>Out Channel

@init
status=0;
status2=128;
memset(status,-1,128);
memset(status2,0,128);

@slider
div=slider1;
note_slider = slider2 & 127;
beat_quant = slider3;
out_channel = (slider5 - 1) & 15;

quant=div/beat_quant;
quant_test=div/beat_quant==floor(div/beat_quant);
div/beat_quant != floor(div/beat_quant) ? (
  div=ceil(quant)*beat_quant;
);
slider4=div;
@block

while(midirecv(ts,msg1,msg23)) (

  m=msg1&240;
  note=msg23&127;
while(note_slider==note) ? (
  (m == 9*16 && msg23>=256) ? (
    status[note]=0;
    vel=(msg23/256);
    vel<1?vel=1:vel>=127?vel=127:vel|=0;
    status2[note]=vel;
   
    midisend(ts,9*16|out_channel,note+vel*256); // send note on
  ) : (m == 8*16 || m == 9*16) ? (
    status[note]=-1;
    status2[note]>0 ? (
      midisend(ts,8*16|out_channel,note); // send note off
      status2[note]=0;
    );
  )) : (
    midisend(ts,msg1,msg23);
  );
  1;
);


inc = (samplesblock/srate*(tempo/60)*2/div);
x=0;
loop(128,
  status[x]>=0.0 ?
  (
    status[x] += inc;
    status[x] >= 1.0 ?
    (
      status[x] -= 1.0;
        status2[x]>0.0 ? (
          midisend(0,8*16|out_channel,x);
        )
        :
        (
          midisend(0,9*16|out_channel,x - status2[x]*256);
        );
      status2[x]*=-1;
    );
  );
 x+=1;
 
);

@sample

It works well, but I can't figure out why it seems to send the MIDI note off message 1/2 way through the repeat period...

What I mean is, If I set the repeat to be 4 beats, it will indeed send a midi note on every 4 beats (i.e. once per measure in 4/4 time). The issue is that it sends the MIDI note off message 1/2 way though, i.e. on "3".

I REALLY need this script to send a MIDI note off at the same time (well, actually just before obviously) that it plays the new repeated note.

Visually, here's how it works now:

Beats=4

Beat 1.1-Note On
Beat 2.1-Nothing
Beat 3.1-Note Off
Beat 4.1-Nothing

Beat 1.2-Note On
Beat 2.2-Nothing
Beat 3.2-Note Off
Beat 4.2-Nothing

Here's how I need/want it to work:

Beats=4

Beat 1.1-Note On
Beat 2.1-Nothing
Beat 3.1-Nothing
Beat 4.1-Nothing

Beat 1.2-Note Off + Note On
Beat 2.2-Nothing
Beat 3.2-Nothing
Beat 4.2-Nothing


I've tried fiddling with all the places it's sending note info, etc. but I can't get it to do it. I can't even figure out WHY it sends the note off 1/2 way through the repeat period...

Anybody got an idea?


Help needed: Minor change to my modded midi note repeater

Aucun commentaire:

Enregistrer un commentaire