1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Transform midi CC to note

Discussion in 'Scripting Workshop' started by d.barretta, Jan 8, 2011.

Thread Status:
Not open for further replies.
  1. d.barretta

    d.barretta New Member

    Messages:
    16
    Hello to everyone! :D
    I'd like to transform a midi CC to note...example : I push sustain pedal and note C2 plays...Is it possible ? :S
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Try using the Transformer multi-script if you're on Kontakt 4. I believe there's something similar for instrument scripts but I can't recall correctly.
     
  3. d.barretta

    d.barretta New Member

    Messages:
    16
    Yes i'm on kontakt 4 but there is only notes to cc script...i need an instrument script to transform cc to note :(
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    There is a Transformer multiscript. Try using that.
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Or try this simple instrument script:

    Code:
    on init
    	declare $note_id
    
    	declare ui_value_edit $CC (0,95,1)
    	declare ui_value_edit $Note (0,127,0)
    	declare ui_value_edit $Velocity (1,127,1)
    	declare ui_value_edit $Duration (0,10000,1)
    
    	make_persistent($CC)
    	make_persistent($Note)
    	make_persistent($Velocity)
    	make_persistent($Duration)
    
    	message("")
    end on
    
    on controller
    	if (%CC[$CC] = 127)
    		$note_id := play_note($Note,$Velocity,0,$Duration*1000)
    	end if
    	if (%CC[$CC] = 0)
    		note_off($note_id)
    	end if
    end on
     
  6. d.barretta

    d.barretta New Member

    Messages:
    16
    Thank you EvilDragon, your script works very very well...but not for drum
    computer script :(
    if i play C3 note, the drum loop starts but if i use your script to simulate C3
    note, the drum loop doesn't play :S
     
  7. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Did you insert this script BEFORE the drum computer script?
     
  8. d.barretta

    d.barretta New Member

    Messages:
    16
    sorry sorry sorry :eek:
    yes now it works
    Many many thanks!
     
  9. tonewheeltom

    tonewheeltom Forum Member

    Messages:
    74
    Thanks EvilDragon for directing me to this link, but I am not having luck.

    I've tried both Transformer presets, both in the Multi and in the Instrument, which appear to be a little different. Neither did what I wanted, which is:

    When I tap a footswitch plugged into my controller (Nord Stage), either sustain (Controller 64) or rotor speed (Controller 90), I'd like to play a note of a Kontakt instrument.

    After messing around with the Transformer presets, I tried to copy and paste the script you posted for d.baretta. I was able to copy the script, but not paste in Kontakt's script edit window. So I entered it by hand, and after hitting "Apply" in Kontakt, a line is highlighted in pink noting an error (the one that begins with $note_id, perhaps I'm misreading the asterisk?).

    A bonus for my project would be if I depress the footswitch I get one note, and upon releasing get another, e.g. a tambourine tap on the down, a tambourine shake on the up.

    Thanks for your time.
     
  10. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    This script MUST work. Perhaps you've pasted the code wrongly, check if you perhaps have any superfluous lines pasted in. I'm not sure why it wouldn't work, it works well over here...
     
  11. tonewheeltom

    tonewheeltom Forum Member

    Messages:
    74
    For some reason the Receptor was not letting me paste the script in K4's edit window, so I pasted it from this forum into K4 on my PC, and still had an error in that line I mentioned, this time with the following message in K4:

    Status:
    ERROR (line 19): play_note is not allowed in this callback type!
     
  12. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Sorry, I'm not getting that error here at all... What is your Kontakt version? It works over here in K3, K4.1.1 and K4.1.3. I can't tell what's the issue, because play_note CAN be used in "on controller" callback. Sorry I can't be of more help. This might be Receptor related in some weird convoluted way.

    Can you please try it on your PC/Mac if you have Kontakt installed over there?
     
  13. tonewheeltom

    tonewheeltom Forum Member

    Messages:
    74
    I was pasting it as a Multi script. It DOES load as an Instrument script. :eek:

    Because of the pasting issues with Receptor I saved it as a text file, and it loads fine in a New Instrument when I "apply from text file".

    What I'm now having trouble with is inserting into Kontakt Library instruments, i.e. Abbey Road Drums. Seems the 5 script tabs are in use already and I can't insert another, and if I remove one and put this script in place I get an error message. Forgive me if I'm now OT and in noob territory.
     
  14. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    I specifically mentioned "instrument script" above ;)


    Yeah if all 5 script slots are already taken, then you're in deep. Especially with things like Abbey Road Drums etc. Well, the script can be modified as multiscript, too. Here's a version which enables you to define four controllers for four different notes, each on separate channel if needed:

    Code:
    on init
    	set_script_title("MIDI CC To Note")
    
    	declare ui_label $1 (1,1)
    	declare ui_label $2 (1,1)
    	declare ui_label $3 (1,1)
    	declare ui_label $4 (1,1)
    	declare ui_menu $Channel1
    	declare ui_menu $Channel2
    	declare ui_menu $Channel3
    	declare ui_menu $Channel4
    	declare ui_value_edit $CC1 (0,95,1)
    	declare ui_value_edit $CC2 (0,95,1)
    	declare ui_value_edit $CC3 (0,95,1)
    	declare ui_value_edit $CC4 (0,95,1)
    	declare ui_value_edit $Note1 (0,127,0)
    	declare ui_value_edit $Note2 (0,127,0)
    	declare ui_value_edit $Note3 (0,127,0)
    	declare ui_value_edit $Note4 (0,127,0)
    	declare ui_value_edit $Velocity1 (1,127,1)
    	declare ui_value_edit $Velocity2 (1,127,1)
    	declare ui_value_edit $Velocity3 (1,127,1)
    	declare ui_value_edit $Velocity4 (1,127,1)
    
    	declare $count
    	declare !port[4]
    	!port[0] := "[A]"
    	!port[1] := "[B]"
    	!port[2] := "[C]"
    	!port[3] := "[D]"
    
    	while ($count <= 63)
    		add_menu_item($Channel1,"Port: " & !port[$count / 16] & " Ch: " & $count mod 16 + 1,$count)
    		add_menu_item($Channel2,"Port: " & !port[$count / 16] & " Ch: " & $count mod 16 + 1,$count)
    		add_menu_item($Channel3,"Port: " & !port[$count / 16] & " Ch: " & $count mod 16 + 1,$count)
    		add_menu_item($Channel4,"Port: " & !port[$count / 16] & " Ch: " & $count mod 16 + 1,$count)
    		if (in_range($count,0,19))
    			set_control_par(32768 + $count,$CONTROL_PAR_GRID_X,($count / 4) + 1)
    			set_control_par(32768 + $count,$CONTROL_PAR_GRID_Y,($count mod 4) + 1)
    		end if
    		inc($count)
    	end while
    
    	$CC1 := 16
    	$CC2 := 17
    	$CC3 := 18
    	$CC4 := 19
    	$Note1 := 60
    	$Note2 := 62
    	$Note3 := 64
    	$Note4 := 65
    	$Velocity1 := 96
    	$Velocity2 := 96
    	$Velocity3 := 96
    	$Velocity4 := 96
    
    	make_persistent($Channel1)
    	make_persistent($Channel2)
    	make_persistent($Channel3)
    	make_persistent($Channel4)
    	make_persistent($CC1)
    	make_persistent($CC2)
    	make_persistent($CC3)
    	make_persistent($CC4)
    	make_persistent($Note1)
    	make_persistent($Note2)
    	make_persistent($Note3)
    	make_persistent($Note4)
    	make_persistent($Velocity1)
    	make_persistent($Velocity2)
    	make_persistent($Velocity3)
    	make_persistent($Velocity4)
    
    	set_text($1,"Conversion Slot 1:")
    	set_text($2,"Conversion Slot 2:")
    	set_text($3,"Conversion Slot 3:")
    	set_text($4,"Conversion Slot 4:")
    	set_text($CC1,"CC #")
    	set_text($CC2,"CC #")
    	set_text($CC3,"CC #")
    	set_text($CC4,"CC #")
    	set_text($Note1,"Note")
    	set_text($Note2,"Note")
    	set_text($Note3,"Note")
    	set_text($Note4,"Note")
    	set_text($Velocity1,"Velocity")
    	set_text($Velocity2,"Velocity")
    	set_text($Velocity3,"Velocity")
    	set_text($Velocity4,"Velocity")
    
    	message("")
    end on
    
    on midi_in
    	if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_CHANNEL = $Channel1 and $MIDI_BYTE_1 = $CC1 and $MIDI_BYTE_2 = 127)
    		ignore_midi
    		set_midi($Channel1,$MIDI_COMMAND_NOTE_ON,$Note1,$Velocity1)
    	end if
    	if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_CHANNEL = $Channel2 and $MIDI_BYTE_1 = $CC2 and $MIDI_BYTE_2 = 127)
    		ignore_midi
    		set_midi($Channel2,$MIDI_COMMAND_NOTE_ON,$Note2,$Velocity2)
    	end if
    	if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_CHANNEL = $Channel3 and $MIDI_BYTE_1 = $CC3 and $MIDI_BYTE_2 = 127)
    		ignore_midi
    		set_midi($Channel3,$MIDI_COMMAND_NOTE_ON,$Note3,$Velocity3)
    	end if
    	if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_CHANNEL = $Channel4 and $MIDI_BYTE_1 = $CC4 and $MIDI_BYTE_2 = 127)
    		ignore_midi
    		set_midi($Channel4,$MIDI_COMMAND_NOTE_ON,$Note4,$Velocity4)
    	end if
    	if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_CHANNEL = $Channel1 and $MIDI_BYTE_1 = $CC1 and $MIDI_BYTE_2 = 0)
    		ignore_midi
    		set_midi($Channel1,$MIDI_COMMAND_NOTE_ON,$Note1,0)
    		set_midi($Channel1,$MIDI_COMMAND_NOTE_OFF,$Note1,64)
    	end if
    	if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_CHANNEL = $Channel2 and $MIDI_BYTE_1 = $CC2 and $MIDI_BYTE_2 = 0)
    		ignore_midi
    		set_midi($Channel2,$MIDI_COMMAND_NOTE_ON,$Note2,0)
    		set_midi($Channel2,$MIDI_COMMAND_NOTE_OFF,$Note2,64)
    	end if
    	if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_CHANNEL = $Channel3 and $MIDI_BYTE_1 = $CC3 and $MIDI_BYTE_2 = 0)
    		ignore_midi
    		set_midi($Channel3,$MIDI_COMMAND_NOTE_ON,$Note3,0)
    		set_midi($Channel3,$MIDI_COMMAND_NOTE_OFF,$Note3,64)
    	end if
    	if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_CHANNEL = $Channel4 and $MIDI_BYTE_1 = $CC4 and $MIDI_BYTE_2 = 0)
    		ignore_midi
    		set_midi($Channel4,$MIDI_COMMAND_NOTE_ON,$Note4,0)
    		set_midi($Channel4,$MIDI_COMMAND_NOTE_OFF,$Note4,64)
    	end if
    end on
     
  15. tonewheeltom

    tonewheeltom Forum Member

    Messages:
    74
    That's even better! 4 channels and 4 controllers suit my needs perfectly. Thanks for that.

    Next I have to figure out if I can get 2 different notes from the same CC trigger's on/off, like the tambourine scenario I described earlier.
     
  16. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Not with this version of script, it would need to be readjusted.
     
  17. thumky

    thumky Forum Member

    Messages:
    43
    tonewheeltom,
    Your setup is insanely similar to mine. I use a Nord NE3 plus a Receptor Pro 2. I'm also interested in foot pedal triggers ( i use a FCB 1010 for that ). To get a sequence of Notes like you describe i use a Midi Solutions Event Processor. They're really small and are only $150. I can hit a foot pedal and cycle thru a sequence of 4 notes. I'll then use Kontakt to translate these notes into chords... I'll be playing bass and when the chorus comes, i'll have the keys kick in and play along. Sounds great!

    I thought i'd share since our needs and setups are similar. I'd imagine there would be a way to use Kontakt to make a sequence, i just couldn't figure it out!
     
  18. tonewheeltom

    tonewheeltom Forum Member

    Messages:
    74
    I haven't reported back with my results since the project I needed this for has been delayed a few weeks, but so far so good.

    I assume if I need a higher MIDI CC than 95 I could substitute a higher value in the script, e.g. $CC1 (0,105,1) instead of $CC1 (0,95,1), etc.

    thumky, thanks for the suggestion! I was looking into MIDI Solutions stuff but wasn't sure exactly what I needed. The Event Processor combined with EvilDragon's multi script may indeed help me achieve the tambourine effect I need.
     
Thread Status:
Not open for further replies.