Old 02-05-2019, 05:05 AM   #1
rKeeling75
Human being with feelings
 
Join Date: Sep 2018
Posts: 1
Default Harmonizing A Scale For A Key

EDIT: NVM, This function was in the forum all along! The MIDI Harmonizer does everything I want and then some.

I am still curious about how the code works, but it is not a roadblock at the moment.

Thanks.


--------------------------
ORIGINAL MESSAGE
--------------------------

(I hope I am in the right thread)

I am trying to work up a small tool to help with harmonizing a scale. I am basing this work on the midi_chordkey fx. My desire is to have a 'one key pressed returns a chord' functionality that I can put in the input fx of a midi track. The difference with what I want and what midi_chordkey is:

1) the ability to produce four note chords
2) the ability to select a scale to harmonize against.

I have modified the midi_chordkey chord as shown below (simply added the 4th note of the chord). It is hard coded for the harmonic major scale (standard major scale with a flattened 6th) for testing sake. And it works EXCEPT when I press the the 6th scale degree.

As an example, assume we are in C Major.

I press C on my midi controller and I get a Cmaj7 (C, E, G, B)
I press D on my midi controller and I get a Dmin7b5 (D, F, Ab, C)
etc.
But when I press Ab on my midi controller, I get... Ab, C, E (NOT an F), G

I am sure it is something I have messed up in the code (I am not familiar with this script at all). Any help would be appreciated.




-------------------------------------------
desc:MIDI Chord In Key2
//tags: MIDI processing

slider1:2<-24,24,1>Notes In Key Advance For Note 1
slider2:4<-24,24,1>Notes In Key Advance For Note 2
slider3:6<-24,24,1>Notes In Key Advance For Note 3
slider4:0<0,11,1{C,C#,D,D#,E,F,F#,G,G#,A,A#,B}>Key
slider5:1<0,1>Velocity Scale For Additional Notes
slider6:0<0,127,1>Lowest Key (MIDI Note #)
slider7:127<0,127,1>Highest Key (MIDI Note #)

in_pin:none
out_pin:none

@init

// maps a in-key note to a semitone note
tab=0;
tab[0]=0;
tab[1]=2;
tab[2]=4;
tab[3]=5;
tab[4]=7;
tab[5]=8;
tab[6]=11;

// maps a note to its nearest in-Cmaj note
tab2=16;
tab2[0]=0;
tab2[1]=0;
tab2[2]=2;
tab2[3]=2;
tab2[4]=4;
tab2[5]=5;
tab2[6]=5;
tab2[7]=7;
tab2[8]=7;
tab2[9]=8;
tab2[10]=8;
tab2[11]=11;

@slider
slider1|=0;
slider2|=0;
slider3|=0;
key = slider4|0;

@block

while (
midirecv(ts,msg1,msg23) ?
(
m=msg1&240;
note=msg23&127;

(m == 8*16 || m==9*16) && note >= slider6 && note <= slider7 ?
(
note += 12-key;
noteidx=note%12;
octavebase=note-noteidx;

n2=noteidx+tab[slider1%7];
note2 = octavebase + tab2[n2%12] + ((n2/12)|0)*12;

n2=noteidx+tab[slider2%7];
note3 = octavebase + tab2[n2%12] + ((n2/12)|0)*12;

n2=noteidx+tab[slider3%7];
note4 = octavebase + tab2[n2%12] + ((n2/12)|0)*12;


note-=12-key;
note2-=12-key;
note3-=12-key;
note4-=12-key;


(m == 9*16 && msg23>=256) ?
(
vel=(msg23/256)|0;
vel<0?vel=0:vel>=127?vel=127:vel|=0;
vel2=vel*slider5;
vel2<0?vel2=0:vel2>=127?vel2=127:vel2|=0;
vel2 *= 256.0;
vel *= 256.0;
note >= 0 && note < 128 ? midisend(ts,9*16,note+vel); // send note on
note2 >= 0 && note2 < 128 ? midisend(ts,9*16,note2+vel2); // send note on
note3 >= 0 && note3 < 128 ? midisend(ts,9*16,note3+vel2); // send note on
note4 >= 0 && note4 < 128 ? midisend(ts,9*16,note4+vel2); // send note on
) : (m == 8*16 || m == 9*16) ? (
note >= 0 && note < 128 ? midisend(ts,8*16,note); // send note off
note2 >= 0 && note2 < 128 ? midisend(ts,8*16,note2); // send note off
note3 >= 0 && note3 < 128 ? midisend(ts,8*16,note3); // send note off
note4 >= 0 && note4 < 128 ? midisend(ts,8*16,note4); // send note off
);
) :
(
midisend(ts,msg1,msg23);
);
bla=1;
);
);


@sample

Last edited by rKeeling75; 02-05-2019 at 06:09 AM. Reason: Found the answer
rKeeling75 is offline   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 08:58 AM.


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