Translate cc to note number

I’m using

var P_CC : Parameter 1..127 = 1
    P_NN : Parameter 1..127  = C3 
    
    //Called when a CC message is received

//Called when a CC message is received
//The CC numbers must be within the specified range

On ControlChangeEvent(m : ControlChangeMessage) 
 if GetCCNumber(m) == P_CC then
  if GetCCValue(m) == 127 then
   SendNow( ReinterpretAsNoteOnMessage(MakeNoteMessage(P_NN,100)))
  elsif GetCCValue(m) == 0 then
   SendNow( ReinterpretAsNoteOffMessage(MakeNoteMessage(P_NN,100)))  
  end
 end 
end

which was uploaded to this thread as cc2note.gpfav

I want to have four of the above slider pairs in a single scriptlet

the input is always the same: cc 20, 21, 22, 23

variable is the 4 notes (manually entered per scriptlet instance)

Also, if possible, I’d like have a slider to set the velocity on a per note basis rather than the script’s fixed setting of 100.

(some sample sets have > or < velocity splits for articulations)

So that would be 4 sets of 3 sliders

CC
Note
Velocity

However, given the incoming is always CC20, 21, 22, 23 - maybe that can be fixed in the script rather than a variable, which means 4 groups of two sliders

Note
Velocity

Does that make sense?

Thanks!

OK, understands

You want widgets for CC Number, Note Number, Velocity?

No, I wasnt thinking of that - I was wanting to use each instance of the scriptlet (inserted in the Wiring as a plugin) as a fixed script (set via sliders), which will then be enabled/disabled via widget. (using “bypass”)
IOW, configured in Wiring, enabled/disabled via widget.

But your suggestion might be more elegant, as a single instance in Wiring (before all samplers), linked as a group of widgets (4 note sliders, 4 velocity sliders). Use snapshots to capture the group of settings applicable to each sample set

Either method could work for my needs, but your suggestion would have much simpler Wiring in my system (which isn’t typical)

OK, gimme some (more) Minutes :wink:

1 Like

Try this:

cc_to_notenumbers.gig (246.7 KB)

This is the code - quick&dirty

var ccPar1 : Parameter 1..127 = 1
    ccPar2 : Parameter 1..127 = 2
    ccPar3 : Parameter 1..127 = 3
    ccPar4 : Parameter 1..127 = 4
    
    vvPar1 : Parameter 1..127 = 1
    vvPar2 : Parameter 1..127 = 2
    vvPar3 : Parameter 1..127 = 3
    vvPar4 : Parameter 1..127 = 4
    
    nnPar1 : Parameter AsNoteNames C-2..C8 = "C3"
    nnPar2 : Parameter AsNoteNames C-2..C8 = "C3"
    nnPar3 : Parameter AsNoteNames C-2..C8 = "C3"
    nnPar4 : Parameter AsNoteNames C-2..C8 = "C3"  
    
    v_ccn  : Integer
    v_ccv  : Integer

On ControlChangeEvent(m : ControlChangeMessage)
 v_ccn = GetCCNumber(m)
 v_ccv = GetCCValue(m)
 if v_ccn == ccPar1 then
    if v_ccv > 0 then
     v_ccv = vvPar1
    end
    SendNow(MakeNoteMessage(NoteNameToNoteNumber(nnPar1), v_ccv))
 elsif v_ccn == ccPar2 then
    if v_ccv > 0 then
     v_ccv = vvPar2
    end
    SendNow(MakeNoteMessage(NoteNameToNoteNumber(nnPar2), v_ccv))
 elsif v_ccn == ccPar3 then
    if v_ccv > 0 then
     v_ccv = vvPar3
    end
    SendNow(MakeNoteMessage(NoteNameToNoteNumber(nnPar3), v_ccv))
 elsif v_ccn == ccPar4 then
    if v_ccv > 0 then
     v_ccv = vvPar4
    end
    SendNow(MakeNoteMessage(NoteNameToNoteNumber(nnPar4), v_ccv))
 else
  SendNow(m)
 end   
 
End

Why not just use the NoteNameToNoteNumber function?

Did I miss something?

Now I know, will change it.

1 Like

(After a night’s sleep): This is exactly what I wanted! Thanks so much.

BUT, one query - is there a reason for commencing Note numbers at C2?
Is that a limitation of the AsNoteNames parameter?
I need to be able to use A0 to B1
i.e. I’m not playing notes, I using the notes to trigger articulations.
Some are hard coded in the sample set i.e. I cant change without another workaround in GP.

Thanks again!

I think it is C-2 as the starting point, not C2

1 Like

At first I wasn’t sure what you meant, but now I get it.
I learn more about GP every time I use it.
A stunningly powerful tool!
Thanks!

2 Likes

The script changes the MIDI channel from 16 to channel 1.
Possibly OMNI output is implicit unless specified?
So I used MakeNoteMessageEx instead, as per:

SendNow(MakeNoteMessageEx(NoteNameToNoteNumber(nnPar4), v_ccv,16))

and works fine. Output is now on channel 16.

Thanks!

This will change any channel into channel 16, you could rather use the original channel by using this in place of 16:

m.GetChannel()

1 Like

cool! Thanks for the tip.

1 Like