# Midi pitch remapping script?



## set (Jul 10, 2006)

Hello All I am new to this forum. I have had kontakt 2 for a couple of weeks and love it. I was hoping someone could help me. I have been playing with the scripts and find them very interesting. I was hoping there was a script that might allow me to map an incoming midi note number to any other note number. 

eg. 

Incoming Outgoing 

C36 E40 
D38 G43 
E40 A33 

I would like to map these pitches or midi note numbers over a one to three octave range.Is there a script that will do this?


----------



## Thonex (Jul 10, 2006)

Hi Set,  

Welcome to the forum!!!

Yes... what you descripbed wouldn't be too difficult at all.

It's just a matter of transposing the $EVENT_NOTE to another note.

Page 41 in the Scripting PDF that came with K2 would be a good place to start:



> The values of $EVENT_NOTE und $EVENT_VELOCITY can be changed by using the
> following functions:
> change_note(<ID-number>,<new-note-number>)
> change the note value of a specific note event
> ...




Hope this helps.

Cheers,

T


----------



## set (Jul 10, 2006)

Thanks for the info. I haven't tried to program a script as of yet, I am finding the whole thing a little confusing. I guess there is no time like the present.


----------



## Thonex (Jul 10, 2006)

If I wasn't so crammed with deadlines right now, I might write you a little script, but I won't be able to get to anything like that for a few weeks.

Give it a shot.... it's easier than you think.... and there are some really talented programmers that hang out here and might help you.

Cheers,

T


----------



## kotori (Jul 10, 2006)

Please see my post on the NI forum. I don't know if it's what you are after (eg. maybe you want to remap all octaves in the same way), so please tell me if you need any help adapting it.

Cheers,
Nils


----------



## set (Jul 11, 2006)

I found it, thanks once again.


----------



## Thonex (Jul 11, 2006)

Hi Nils,

I like your style!!! Very clean and simple. 

DIdn't you mean to say "{ change the numbers on the *left* side to remap the notes }"?

If it's ok with you... I'm posting it here so that we can share this code in one place. Let me know if that's a problem and I'll take it down. 

Cheers,

T

Nils' code:


```
on init
  { change the numbers on the left side to remap the notes }
  declare %mapping[128] := (...
                       0,  {#0, C-2}...
                       1,  {#1, C#-2}...
                       2,  {#2, D-2}...
                       3,  {#3, D#-2}...
                       4,  {#4, E-2}...
                       5,  {#5, F-2}...
                       6,  {#6, F#-2}...
                       7,  {#7, G-2}...
                       8,  {#8, G#-2}...
                       9,  {#9, A-2}...
                       10, {#10, A#-2}...
                       11, {#11, B-2}...
                       12, {#12, C-1}...
                       13, {#13, C#-1}...
                       14, {#14, D-1}...
                       15, {#15, D#-1}...
                       16, {#16, E-1}...
                       17, {#17, F-1}...
                       18, {#18, F#-1}...
                       19, {#19, G-1}...
                       20, {#20, G#-1}...
                       21, {#21, A-1}...
                       22, {#22, A#-1}...
                       23, {#23, B-1}...
                       24, {#24, C0}...
                       25, {#25, C#0}...
                       26, {#26, D0}...
                       27, {#27, D#0}...
                       28, {#28, E0}...
                       29, {#29, F0}...
                       30, {#30, F#0}...
                       31, {#31, G0}...
                       32, {#32, G#0}...
                       33, {#33, A0}...
                       34, {#34, A#0}...
                       35, {#35, B0}...
                       36, {#36, C1}...
                       37, {#37, C#1}...
                       38, {#38, D1}...
                       39, {#39, D#1}...
                       40, {#40, E1}...
                       41, {#41, F1}...
                       42, {#42, F#1}...
                       43, {#43, G1}...
                       44, {#44, G#1}...
                       45, {#45, A1}...
                       46, {#46, A#1}...
                       47, {#47, B1}...
                       48, {#48, C2}...
                       49, {#49, C#2}...
                       50, {#50, D2}...
                       51, {#51, D#2}...
                       52, {#52, E2}...
                       53, {#53, F2}...
                       54, {#54, F#2}...
                       55, {#55, G2}...
                       56, {#56, G#2}...
                       57, {#57, A2}...
                       58, {#58, A#2}...
                       59, {#59, B2}...
                       60, {#60, C3}...
                       61, {#61, C#3}...
                       62, {#62, D3}...
                       63, {#63, D#3}...
                       64, {#64, E3}...
                       65, {#65, F3}...
                       66, {#66, F#3}...
                       67, {#67, G3}...
                       68, {#68, G#3}...
                       69, {#69, A3}...
                       70, {#70, A#3}...
                       71, {#71, B3}...
                       72, {#72, C4}...
                       73, {#73, C#4}...
                       74, {#74, D4}...
                       75, {#75, D#4}...
                       76, {#76, E4}...
                       77, {#77, F4}...
                       78, {#78, F#4}...
                       79, {#79, G4}...
                       80, {#80, G#4}...
                       81, {#81, A4}...
                       82, {#82, A#4}...
                       83, {#83, B4}...
                       84, {#84, C5}...
                       85, {#85, C#5}...
                       86, {#86, D5}...
                       87, {#87, D#5}...
                       88, {#88, E5}...
                       89, {#89, F5}...
                       90, {#90, F#5}...
                       91, {#91, G5}...
                       92, {#92, G#5}...
                       93, {#93, A5}...
                       94, {#94, A#5}...
                       95, {#95, B5}...
                       96, {#96, C6}...
                       97, {#97, C#6}...
                       98, {#98, D6}...
                       99, {#99, D#6}...
                       100, {#100, E6}...
                       101, {#101, F6}...
                       102, {#102, F#6}...
                       103, {#103, G6}...
                       104, {#104, G#6}...
                       105, {#105, A6}...
                       106, {#106, A#6}...
                       107, {#107, B6}...
                       108, {#108, C7}...
                       109, {#109, C#7}...
                       110, {#110, D7}...
                       111, {#111, D#7}...
                       112, {#112, E7}...
                       113, {#113, F7}...
                       114, {#114, F#7}...
                       115, {#115, G7}...
                       116, {#116, G#7}...
                       117, {#117, A7}...
                       118, {#118, A#7}...
                       119, {#119, B7}...
                       120, {#120, C8}...
                       121, {#121, C#8}...
                       122, {#122, D8}...
                       123, {#123, D#8}...
                       124, {#124, E8}...
                       125, {#125, F8}...
                       126, {#126, F#8}...
                       127  {#127, G8}...
                      )
end on

on note
  change_note($EVENT_ID, %mapping[$EVENT_NOTE])
end on
```


----------



## kotori (Jul 11, 2006)

Thonex said:


> Hi Nils,
> 
> I like your style!!! Very clean and simple.
> 
> Didn't you mean to say "{ change the numbers on the *left* side to remap the notes }


Yes, you're right. :oops: :smile: Thanks! I edited my post at the NI forum. Please feel free to edit the previous post as well.



Thonex said:


> If it's ok with you... I'm posting it here so that we can share this code in one place. Let me know if that's a problem and I'll take it down.
> 
> Cheers,
> T


Of course it's ok.

Cheers,
Nils


----------



## Thonex (Jul 11, 2006)

kotori @ Tue Jul 11 said:


> Thanks! I edited my post at the NI forum. Please feel free to edit the previous post as well.



Done


----------



## Thonex (Jul 11, 2006)

Nils,

I thought you did such a great job on this that I decided to add a few lines of code that displays the in-coming and out-going note as you play them. Your little script would be great for re-assigning percussion so all patches are assigned the same way.

Cheers,

T

[edit -- I just corrected a mistake in my portion of the script... all's fine now]


```
on init
   message("")
   declare ui_button $Choose_Note
   declare ui_button $Assign_to
   declare ui_value_edit $Transpose (0,100,1)
   declare $Chosen_Note
   declare $Chosen_Trans
   declare ui_label $In_nòim\0\0\0?yim\0\0\0?zim\0\0\0?{im\0\0\0?|im\0\0\0?}im\0\0\0?~im\0\0\0?im\0\0\0?€im\0\0\0?im\0\0\0?‚im\0\0\0?ƒim\0\0\0?„im\0\0\0?…im\0\0\0?†im\0\0\0?‡im\0\0\0?ˆim\0\0\0?‰im\0\0\0?Šim\0\0\0?‹im\0\0\0?Œim\0\0\0?im\0\0\0?Žim\0\0\0?im\0\0\0?im\0\0\0?‘im\0\0\0?’im\0\0\0?“im\0\0\0?”im\0\0\0?•im\0\0\0?–im\0\0\0?—im\0\0\0?˜im\0\0\0?™im\0\0\0?šim\0\0\0?›im\0\0\0?œim\0\0\0?im\0\0\0?žim\0\0\0?Ÿim\0\0\0? im\0\0\0?¡im\0\0\0?¢im\0\0\0?£im\0\0\0?¤im\0\0\0?¥im\0\0\0?¦im\0\0\0?§im\0\0\0?¨im\0\0\0?©im\0\0\0?ªim\0\0\0?«im\0\0\0?¬im\0\0\0?­im\0\0\0?®im\0\0\0?¯im\0\0\0?°im\0\0\0?±im\0\0\0?²im\0\0\0?³im\0\0\0?´im\0\0\0?µim\0\0\0?¶im\0\0\0?·im\0\0\0?¸im\0\0\0?¹im\0\0\0?ºim\0\0\0?»im\0\0\0?¼im\0\0\0?½im\0\0\0?¾im\0\0\0?¿im\0\0\0?Àim\0\0\0?Áim\0\0\0?Âim\0\0\0?Ãim\0\0\0?Äim\0\0\0?Åim\0\0\0?Æim\0\0\0?Çim\0\0\0?Èim\0\0\0?Éim\0\0\0?Êim\0\0\0?Ëim\0\0\0?Ìim\0\0\0?Íim\0\0\0?Îim\0\0\0?Ïim\0\0\0?Ðim\0\0\0?Ñim\0\0\0?Òim\0\0\0?Óim\0\0\0?Ôim\0\0\0?Õin\0\0\0?Öin\0\0\0?×in\0\0\0?Øin\0\0\0?Ùin\0\0\0?Úin\0\0\0?Ûin\0\0\0?Üin\0\0\0?Ýin\0\0\0?Þin\0\0\0?ßin\0\0\0?àin\0\0\0?áin\0\0\0?âin\0\0\0?ãin\0\0\0?äin\0\0\0?åin\0\0\0?æin\0\0\0?çin\0\0\0?è\0\0\0\0\0\0\0\0\0\0\0\0\0\0òin\0\0\0?êin\0\0\0?ëin\0\0\0?ìin\0\0\0?íin\0\0\0?îin\0\0\0?ïin\0\0\0?ðin\0\0\0?ñin\0\0\0?òin\0\0\0?óin\0\0\0?ôin\0\0\0?õin\0\0\0?öin\0\0\0?÷in\0\0\0?øin\0\0\0?ùin\0\0\0?úin\0\0\0?ûio\0\0\0?üio\0\0\0?ýio\0\0\0?þio\0\0\0?ÿio\0\0\0?\0io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?	io\0\0\0?
io\0\0\0?io\0\0\0?io\0\0\0?
io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0?io\0\0\0? io\0\0\0?!io\0\0\0?"io\0\0\0?#io\0\0\0?$io\0\0\0?%io\0\0\0?&io\0\0\0?'io\0\0\0?(io\0\0\0?)io\0\0\0?*io\0\0\0?+io\0\0\0?,io\0\0\0?-io\0\0\0?.io\0\0\0?/io\0\0\0?0io\0\0\0?1io\0\0\0?2io\0\0\0?3io\0\0\0?4io\0\0\0?5io\0\0\0?6io\0\0\0?7io\0\0\0?8io\0\0\0?9io\0\0\0?:io\0\0\0?;io\0\0\0?<io\0\0\0?=io\0\0\0?>io\0\0\0??io\0\0\0?@io\0\0\0?Aio\0\0\0?Bio\0\0\0?Cio\0\0\0?Dio\0\0\0?Eio\0\0\0?Fio\0\0\0?Gio\0\0\0?Hio\0\0\0?Iio\0\0\0?Jio\0\0\0?Kio\0\0\0?Lio\0\0\0?Mio\0\0\0?Nio\0\0\0?Oio\0\0\0?Pio\0\0\0?Qio\0\0\0?Rio\0\0\0?Sio\0\0\0?Tio\0\0\0?Uio\0\0\0?Vio\0\0\0?Wio\0\0\0?Xio\0\0\0?Y\0\0\0\0\0\0\0\0\0\0\0\0\0\0òio\0\0\0?[io\0\0\0?\io\0\0\0?]io\0\0\0?^io\0\0\0?_io\0\0\0?`io\0\0\0?aio\0\0\0?bio\0\0\0?cio\0\0\0?dio\0\0\0?eio\0\0\0?fio\0\0\0?gio\0\0\0?hio\0\0\0?iio\0\0\0?jio\0\0\0?kio\0\0\0?lio\0\0\0?mio\0\0\0?nio\0\0\0?oio\0\0\0?pio\0\0\0?qio\0\0\0?rio\0\0\0?sio\0\0\0?tio\0\0\0?uio\0\0\0?vio\0\0\0?wio\0\0\0?xio\0\0\0?yio\0\0\0?zio\0\0\0?{io\0\0\0?|io\0\0\0?}io\0\0\0?~io\0\0\0?io\0\0\0?€io\0\0\0?io\0\0\0?‚io\0\0\0?ƒio\0\0\0?„io\0\0\0?…io\0\0\0?†io\0\0\0?‡io\0\0\0?ˆio\0\0\0?‰io\0\0\0?Šio\0\0\0?‹io\0\0\0?Œio\0\0\0?io\0\0\0?Žio\0\0\0?io\0\0\0?io\0\0\0?‘io\0\0\0?’io\0\0\0?“io\0\0\0?”io\0\0\0?•io\0\0\0?–io\0\0\0?—io\0\0\0?˜io\0\0\0?™io\0\0\0?šio\0\0\0?›io\0\0\0?œio\0\0\0?io\0\0\0?žio\0\0\0?Ÿio\0\0\0? io\0\0\0?¡io\0\0\0?¢io\0\0\0?£io\0\0\0?¤io\0\0\0?¥io\0\0\0?¦io\0\0\0?§io\0\0\0?¨io\0\0\0?©io\0\0\0?ªio\0\0\0?«io\0\0\0?¬io\0\0\0?­io\0\0\0?®io\0\0\0?¯io\0\0\0?°io\0\0\0?±io\0\0\0?²io\0\0\0?³io\0\0\0?´io\0\0\0?µio\0\0\0?¶io\0\0\0?·io\0\0\0?¸io\0\0\0?¹io\0\0\0?ºio\0\0\0?»io\0\0\0?¼io\0\0\0?½io\0\0\0?¾io\0\0\0?¿io\0\0\0?Àio\0\0\0?Áio\0\0\0?Âio\0\0\0?Ãio\0\0\0?Äio\0\0\0?Åio\0\0\0?Æio\0\0\0?Çio\0\0\0?Èio\0\0\0?Éio\0\0\0?Ê\0\0\0\0\0\0\0\0\0\0\0\0\0\0òio\0\0\0?Ìio\0\0\0?Íio\0\0\0?Îio\0\0\0?Ïio\0\0\0?Ðio\0\0\0?Ñio\0\0\0?Òio\0\0\0?Óio\0\0\0?Ôio\0\0\0?Õio\0\0\0?Öio\0\0\0?×io\0\0\0?Øio\0\0\0?Ùio\0\0\0?Úio\0\0\0?Ûio\0\0\0?Üio\0\0\0?Ýio\0\0\0?Þio\0\0\0?ßio\0\0\0?àio\0\0\0?áio\0\0\0?âio\0\0\0?ãio\0\0\0?äio\0\0\0?åio\0\0\0?æio\0\0\0?çio\0\0\0?èio\0\0\0?éio\0\0\0?êio\0\0\0?ëio\0\0\0?ìio\0\0\0?íio\0\0\0?îio\0\0\0?ïio\0\0\0?ðio\0\0\0?ñio\0\0\0?òio\0\0\0?óio\0\0\0?ôio\0\0\0?õio\0\0\0?öio\0\0\0?÷io\0\0\0?øio\0\0\0?ùio\0\0\0?úio\0\0\0?ûio\0\0\0?üio\0\0\0?ýio\0\0\0?þio\0\0\0?ÿio\0\0\0?	\0io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?		io\0\0\0?	
io\0\0\0?	io\0\0\0?	io\0\0\0?	
io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	io\0\0\0?	 io\0\0\0?	!io\0\0\0?	"io\0\0\0?	#io\0\0\0?	$io\0\0\0?	%io\0\0\0?	&io\0\0\0?	'io\0\0\0?	(io\0\0\0?	)io\0\0\0?	*io\0\0\0?	+io\0\0\0?	,io\0\0\0?	-io\0\0\0?	.io\0\0\0?	/io\0\0\0?	0io\0\0\0?	1io\0\0\0?	2io\0\0\0?	3io\0\0\0?	4io\0\0\0?	5io\0\0\0?	6io\0\0\0?	7io\0\0\0?	8io\0\0\0?	9io\0\0\0?	:io\0\0\0?	;\0\0\0\0\0\0\0\0\0\0\0\0\0\0             55, {#55, G2}...
                             56, {#56, G#2}...
                             57, {#57, A2}...
                             58, {#58, A#2}...
                             59, {#59, B2}...
                             60, {#60, C3}...
                             61, {#61, C#3}...
                             62, {#62, D3}...
                             63, {#63, D#3}...
                             64, {#64, E3}...
                             65, {#65, F3}...
                             66, {#66, F#3}...
                             67, {#67, G3}...
                             68, {#68, G#3}...
                             69, {#69, A3}...
                             70, {#70, A#3}...
                             71, {#71, B3}...
                             72, {#72, C4}...
                             73, {#73, C#4}...
                             74, {#74, D4}...
                             75, {#75, D#4}...
                             76, {#76, E4}...
                             77, {#77, F4}...
                             78, {#78, F#4}...
                             79, {#79, G4}...
                             80, {#80, G#4}...
                             81, {#81, A4}...
                             82, {#82, A#4}...
                             83, {#83, B4}...
                             84, {#84, C5}...
                             85, {#85, C#5}...
                             86, {#86, D5}...
                             87, {#87, D#5}...
                             88, {#88, E5}...
                             89, {#89, F5}...
                             90, {#90, F#5}...
                             91, {#91, G5}...
                             92, {#92, G#5}...
                             93, {#93, A5}...
                             94, {#94, A#5}...
                             95, {#95, B5}...
                             96, {#96, C6}...
                             97, {#97, C#6}...
                             98, {#98, D6}...
                             99, {#99, D#6}...
                             100, {#100, E6}...
                             101, {#101, F6}...
                             102, {#102, F#6}...
                             103, {#103, G6}...
                             104, {#104, G#6}...
                             105, {#105, A6}...
                             106, {#106, A#6}...
                             107, {#107, B6}...
                             108, {#108, C7}...
                             109, {#109, C#7}...
                             110, {#110, D7}...
                             111, {#111, D#7}...
                             112, {#112, E7}...
                             113, {#113, F7}...
                             114, {#114, F#7}...
                             115, {#115, G7}...
                             116, {#116, G#7}...
                             117, {#117, A7}...
                             118, {#118, A#7}...
                             119, {#119, B7}...
                             120, {#120, C8}...
                             121, {#121, C#8}...
                             122, {#122, D8}...
                             123, {#123, D#8}...
                             124, {#124, E8}...
                             125, {#125, F8}...
                             126, {#126, F#8}...
                             127  {#127, G8}...
                             )
   
   make_persistent (%mapping)
   make_persistent ($Transpose)
end on

on note
   ignore_event ($EVENT_ID)
   if ($Choose_Note = 1 and $Assign_to = 1) {Assign Tuning to Chosen Note Logic}
      
      %mapping [$Chosen_note] := $EVENT_NOTE
      $Choose_Note := 0
      $Assign_to := 0
   end if
   
   if ($Choose_Note = 1 and $Assign_to = 0){Select Choose Note Logic}
      
      $Chosen_Note := $EVENT_NOTE       
      $Assign_to := 1
   end if
   %InNoteVisual [$EVENT_NOTE-21] := $EVENT_VELOCITY {Display the note being played}
   %OutNoteVisual [%mapping[$EVENT_NOTE + $Transpose]-21] := $EVENT_VELOCITY {Display the note being played}
   set_text ($In_note,"Note In: " & $EVENT_NOTE & "   " &...
             !Tones[$EVENT_NOTE mod 12] & ($EVENT_NOTE/12 -2))
   set_text ($Out_note,"Note Out: " & %mapping[$EVENT_NOTE + $Transpose] & "   " &...
             !Tones[(%mapping[$EVENT_NOTE + $Transpose]) mod 12] & ((%mapping[$EVENT_NOTE + $Transpose])/12) -2)
   play_note (%mapping[$EVENT_NOTE + $Transpose],$EVENT_VELOCITY,0, -1)
end on

on release
   %InNoteVisual [$EVENT_NOTE-21] := 0
   %OutNoteVisual [%mapping[$EVENT_NOTE + $Transpose]-21] := 0
end on
```


----------



## kotori (Jul 11, 2006)

Thanks Andrew!


----------



## set (Jul 12, 2006)

Wow, that is amazing. Thankyou all so much for the big hand. This will make life a little easier. 

Is there a way to take the outgoing data and transpose it quickly rather than re-inputing the data for every key I want to use the map in?


----------



## Thonex (Jul 12, 2006)

set @ Wed Jul 12 said:


> Wow, that is amazing. Thankyou all so much for the big hand. This will make life a little easier.
> 
> Is there a way to take the outgoing data and transpose it quickly rather than re-inputing the data for every key I want to use the map in?



Yeah... I just updated it this morning before you posted... check it out...

I guess it need explanation....

click on the "choose note" button and play the note you want changed...then play the note you want it assigned to... and you're done for that note.

You don't ever have to ckick on the "Assign to" button.

Cheers.

T


----------



## set (Jul 12, 2006)

Thanks for the reply. I did understand how it worked. but what I was asking was whether I could develope a keymap in the key of "C" lets say than have a transpose button of some sorts to shift all the setting to work ing the key of "E".


----------



## Thonex (Jul 12, 2006)

set @ Wed Jul 12 said:


> Thanks for the reply. I did understand how it worked. but what I was asking was whether I could develope a keymap in the key of "C" lets say than have a transpose button of some sorts to shift all the setting to work ing the key of "E".



Yeah it would be possible.

From what I under stand, you'd need to create a data entry field or add a button allowing you to choose your transposition and then you'd add your variable (say) $Transposition to this line on code:

play_note (%mapping[$EVENT_NOTE],$EVENT_VELOCITY,0, -1) 

would now be:

play_note ((%mapping[$EVENT_NOTE] + $Transposition),$EVENT_VELOCITY,0, -1) 


cheers,

T


----------



## kotori (Jul 12, 2006)

set @ Wed Jul 12 said:


> Thanks for the reply. I did understand how it worked. but what I was asking was whether I could develope a keymap in the key of "C" lets say than have a transpose button of some sorts to shift all the setting to work ing the key of "E".



set, maybe you could cascade this script with the builtin Midi Transpose script to achieve what you want. Another way if to replace every occurance of "%mapping[$EVENT_NOTE]" with "%mapping[$EVENT_NOTE+$transpose]" where $transpose represents the number of notes with which you want to transpose.

Andrew, I think you forgot a couple of make_persistent statements for the script above.


----------



## Thonex (Jul 12, 2006)

kotori @ Wed Jul 12 said:


> Andrew, I think you forgot a couple of make_persistent statements for the script above.



heh heh.... :smile: 

oh yeah...... :lol: Thanks Nils... 

I think it only need 1 statement.... no? Just make_persistent (%mapping)... no?


ANyway... I updated it....


CHeers,

T


----------



## kotori (Jul 12, 2006)

Thonex @ Wed Jul 12 said:


> heh heh.... :smile:
> oh yeah...... :lol: Thanks Nils...
> I think it only need 1 statement.... no? Just make_persistent (%mapping)... no?


Yeah, my mistake. Just one. :smile:


----------



## set (Jul 12, 2006)

> set, maybe you could cascade this script with the builtin Midi Transpose script to achieve what you want. Another way if to replace every occurance of "%mapping[$EVENT_NOTE]" with "%mapping[$EVENT_NOTE+$transpose]" where $transpose represents the number of notes with which you want to transpose.




I'm not sure why but that doesn't work[/quote]


----------



## set (Jul 12, 2006)

Thonex @ 12th July 2006 said:


> set @ Wed Jul 12 said:
> 
> 
> > Thanks for the reply. I did understand how it worked. but what I was asking was whether I could develope a keymap in the key of "C" lets say than have a transpose button of some sorts to shift all the setting to work ing the key of "E".
> ...



Sorry for the stupid question but were would I insert this? At the beginning?


----------



## Thonex (Jul 12, 2006)

set @ Wed Jul 12 said:


> Sorry for the stupid question but were would I insert this? At the beginning?



No... there are no stupid questions. Here.... I updated it one more time with a Transpose entry field... it's a little tricky... but it works.

You should go through the K2 scripting PDF that came along with k2... there is a great tutorial there... also I think Kotori has a great tutorial as well... go to his website... there is a wealth of info there.

Cheers,

T


----------



## Thonex (Jul 12, 2006)

If you are not going to use Kotori's simple idea of re-assigning the notes n the "on init"... then you might as well just use this script... its the same thing but with a loop instead of all those midi numbers.

Cheers,

T


```
{*********************************************************
**********   Key Re-assign and Transposer v1  ************
**********************************************************}

on init
   message("")
   declare ui_button $Choose_Note
   declare ui_button $Assign_to
   declare ui_value_edit $Transpose (0,100,1)
   declare $Chosen_Note
   declare $Chosen_Trans
   declare ui_label $In_note (2,1)
   declare ui_label $Out_note (2,1)
   declare ui_table %InNoteVisual [88](6,1,128)
   declare ui_table %OutNoteVisual [88](6,1,128)
   declare !Tones[12]  { Key tones array }
   !Tones[0] := "C"
   !Tones[1] := "C#"
   !Tones[2] := "D"
   !Tones[3] := "D#"
   !Tones[4] := "E"
   !Tones[5] := "F"
   !Tones[6] := "F#"
   !Tones[7] := "G"
   !Tones[8] := "G#"
   !Tones[9] := "A"
   !Tones[10] := "A#"
   !Tones[11] := "B"
   
   { change the numbers on the left side to remap the notes }
   declare %mapping[128]
   declare $i
   while ($i <= 127)
      %mapping [$i]:= $i
      inc ($i)
      end while
                                                  
   make_persistent (%mapping)
   make_persistent ($Transpose)
end on

on note
   ignore_event ($EVENT_ID)
   if ($Choose_Note = 1 and $Assign_to = 1) {Assign Tuning to Chosen Note Logic}
      
      %mapping [$Chosen_note] := $EVENT_NOTE
      $Choose_Note := 0
      $Assign_to := 0
   end if
   
   if ($Choose_Note = 1 and $Assign_to = 0){Select Choose Note Logic}
      
      $Chosen_Note := $EVENT_NOTE       
      $Assign_to := 1
   end if
   %InNoteVisual [$EVENT_NOTE-21] := $EVENT_VELOCITY {Display the note being played}
   %OutNoteVisual [%mapping[$EVENT_NOTE + $Transpose]-21] := $EVENT_VELOCITY {Display the note being played}
   set_text ($In_note,"Note In: " & $EVENT_NOTE & "   " &...
             !Tones[$EVENT_NOTE mod 12] & ($EVENT_NOTE/12 -2))
   set_text ($Out_note,"Note Out: " & %mapping[$EVENT_NOTE + $Transpose] & "   " &...
             !Tones[(%mapping[$EVENT_NOTE + $Transpose]) mod 12] & ((%mapping[$EVENT_NOTE + $Transpose])/12) -2)
   play_note (%mapping[$EVENT_NOTE + $Transpose],$EVENT_VELOCITY,0, -1)
end on

on release
   %InNoteVisual [$EVENT_NOTE-21] := 0
   %OutNoteVisual [%mapping[$EVENT_NOTE + $Transpose]-21] := 0
end on
```


----------



## set (Jul 12, 2006)

[quote:79d296a938="Thonex @ 12th July 2006"]If you are not going to use Kotori's simple idea of re-assigning the notes n the "on init"... then you might as well just use this script... its the same thing but with a loop instead of all those midi numbers.

Cheers,

T

[code:1:79d296a938]

{*********************************************************
********** Key Re-assign and Transposer v1 ************
**********************************************************}

on init
message("")
declare ui_button $Choose_Note
declare ui_button $Assign_to
declare ui_value_edit $Transpose (0,100,1)
declare $Chosen_Note
declare $Chosen_Trans
declare ui_label $In_note (2,1)
declare ui_label $Out_note (2,1)
declare ui_table %InNoteVisual [88](6,1,128)
declare ui_table %OutNoteVisual [88](6,1,128)
declare !Tones[12] { Key tones array }
!Tones[0] := "C"
!Tones[1] := "C#"
!Tones[2] := "D"
!Tones[3] := "D#"
!Tones[4] := "E"
!Tones[5] := "F"
!Tones[6] := "F#"
!Tones[7] := "G"
!Tones[8] := "G#"
!Tones[9] := "A"
!Tones[10] := "A#"
!Tones[11] := "B"

{ change the numbers on the left side to remap the notes }
declare %mapping[128]
declare $i
while ($i <= 127)
%mapping [$i]:= $i
inc ($i)
end while

make_persistent (%mapping)
make_persistent ($Transpose)
end on

on note
ignore_event ($EVENT_ID)
if ($Choose_Note = 1 and $Assign_to = 1) {Assign Tuning to Chosen Note Logic}

%mapping [$Chosen_note] := $EVENT_NOTE
$Choose_Note := 0
$Assign_to := 0
end if

òj   ?JÓj   ?JÔj   ?JÕj   ?JÖj   ?J×j   ?JØj   ?JÙj   ?JÚj   ?JÛj   ?JÜj   ?JÝj   ?JÞj   ?Jßj   ?Jàj   ?Jáj   ?Jâj   ?Jãj   ?Jäj   ?Jåj   ?Jæj   ?Jçj   ?Jèj   ?Jéj   ?Jêj   ?Jëj   ?Jìj   ?Jíj   ?Jîj   ?Jïj   ?Jðj   ?Jñj   ?Jòj   ?Jój   ?Jôj   ?Jõj   ?Jöj   ?J÷j   ?Jøj   ?Jùj   ?Júj   ?Jûj   ?Jüj   ?Jýj   ?Jþj   ?Jÿj   ?K j   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?K	j   ?K
j   ?Kj   ?Kj   ?K j   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?Kj   ?K j   ?K!j   ?K"j   ?K#j   ?K$j   ?K%j   ?K&j   ?K'j   ?K(j   ?K)j   ?K*j   ?K+j   ?K,j   ?K-j   ?K.j   ?K/j   ?K0j   ?K1j   ?K2j   ?K3j   ?K4j   ?K5j   ?K6j   ?K7j   ?K8j   ?K9j   ?K:j   ?K;j   ?K<j   ?K=j   ?K>j   ?K?j   [email protected]j   ?KAj   ?KB              òj   ?KDj   ?KEj   ?KFj   ?KGj   ?KHj   ?KIj   ?KJj   ?KKj   ?KLj   ?KMj   ?KNj   ?KOj   ?KPj   ?KQj   ?KRj   ?KSj   ?KTj   ?KUj   ?KVj   ?KWj   ?KXj   ?KYj   ?KZj   ?K[j   ?K\j   ?K]j   ?K^j   ?K_j   ?K`j   ?Kaj   ?Kbj   ?Kcj   ?Kdj   ?Kej   ?Kfj   ?Kgj   ?Khj   ?Kij   ?Kjj   ?Kkj   ?Kl


----------



## kotori (Jul 12, 2006)

set @ Thu Jul 13 said:


> Thanks to everybody for all the help. The transpose doesn't work the way I was hoping so I will just make a map for every key I need. Other than that it works like a charm.


Hi again,
please explain in more detail why it doesn't work the way you like and how you'd want it and I'm sure we can fix it for you. Doing it over and over again for different keys seems like unnecessary work to me.


----------



## set (Jul 13, 2006)

kotori @ 13th July 2006 said:


> set @ Thu Jul 13 said:
> 
> 
> > Thanks to everybody for all the help. The transpose doesn't work the way I was hoping so I will just make a map for every key I need. Other than that it works like a charm.
> ...



actually what you did does work correctly. it will take the edited data and allow you to transpose it. So I can take the edited data play in the key of "c" transpose up 2 and it maps out to "D". What I was hopping for it to to is take the edited data and apply it to other keys. In other word take the mapping for the key of "C" and keep the same interval information but apply it so now it works when I play in the key of "D".

Is it also possible to toggle the original note on or off, not per note but just for the whole script? Sometimes I may want to be able to hear the original note as well.


----------



## set (Jul 15, 2006)

So I started playing with the script that all of you have composed. I did figure out how to get the original note to play and even transpose, but what I can't figure out is how to toggle it on and off. Is there a list of commands or a quick reference manual I can use to help me try and put in a few things I would like to see in this script?


----------



## kotori (Jul 16, 2006)

set @ Sun Jul 16 said:


> So I started playing with the script that all of you have composed. I did figure out how to get the original note to play and even transpose, but what I can't figure out is how to toggle it on and off. Is there a list of commands or a quick reference manual I can use to help me try and put in a few things I would like to see in this script?



To turn the original note on or off you can change:
ignore_event ($EVENT_ID)
into something like:
if (%CC[1] < 64)
ignore_event ($EVENT_ID)
end if

That would ignore original notes when the mod-wheel (CC1) is below 50% and play them otherwise. The condition (%CC[1] < 64) can be changed to anything you like. To learn more about scripting please consult the file "Kontakt Script Language Manual.pdf" in the Documentation subdirectory of Kontakt and/or my scripting tutorial.

Cheers,
Nils


----------



## Thonex (Jul 16, 2006)

set @ Sat Jul 15 said:


> So I started playing with the script that all of you have composed. I did figure out how to get the original note to play and even transpose, but what I can't figure out is how to toggle it on and off. Is there a list of commands or a quick reference manual I can use to help me try and put in a few things I would like to see in this script?



Are you talking about bypassing the script?


----------



## set (Jul 16, 2006)

Yes the whole script


----------



## Thonex (Jul 16, 2006)

set @ Sun Jul 16 said:


> Yes the whole script



Thats easy.

I added a few lines of code.... namely the $Bypass button that is controllable by CC90... if you want to control it with another CC then change the following code to the CC number of your likingby replacing "90" with whatever CC number you want to use:


```
on controller 
   if (%CC_TOUCHED[90]= 1 and %CC[90]>64){CC90 is Bypass }
      $Bypass := 1
   else $Bypass := 0
   end if
   
end on
```

here is the full code:


```
{*********************************************************
**********   Key Re-assign and Transposer v1  ************
**********************************************************}

on init
   message("")
   declare ui_button $Bypass
   move_control ($Bypass, 6,6)
   declare ui_button $Choose_Note
   declare ui_button $Assign_to
   declare ui_value_edit $Transpose (0,100,1)
   declare $Chosen_Note
   declare $Chosen_Trans
   declare ui_label $In_note (2,1)
   declare ui_label $Out_note (2,1)
   declare ui_table %InNoteVisual [88](6,1,128)
   declare ui_table %OutNoteVisual [88](6,1,128)
   declare !Tones[12]  { Key tones array }
   !Tones[0] := "C"
   !Tones[1] := "C#"
   !Tones[2] := "D"
   !Tones[3] := "D#"
   !Tones[4] := "E"
   !Tones[5] := "F"
   !Tones[6] := "F#"
   !Tones[7] := "G"
   !Tones[8] := "G#"
   !Tones[9] := "A"
   !Tones[10] := "A#"
   !Tones[11] := "B"
   
   { change the numbers on the left side to remap the notes }
   declare %mapping[128]
   declare $i
   while ($i <= 127)
      %mapping [$i]:= $i
      inc ($i)
   end while
   
   make_persistent (%mapping)
   make_persistent ($Transpose)
end on

on note
   if($Bypass # 1)
      ignore_event ($EVENT_ID)
      if ($Choose_Note = 1 and $Assign_to = 1) {Assign Tuning to Chosen Note Logic}
         
         %mapping [$Chosen_note] := $EVENT_NOTE
         $Choose_Note := 0
         $Assign_to := 0
      end if
     
      if ($Choose_Note = 1 and $Assign_to = 0){Select Choose Note Logic}
         
         $Chosen_Note := $EVENT_NOTE       
         $Assign_to := 1
      end if
      %InNoteVisual [$EVENT_NOTE-21] := $EVENT_VELOCITY {Display the note being played}
      %OutNoteVisual [%mapping[$EVENT_NOTE + $Transpose]-21] := $EVENT_VELOCITY {Display the note being played}
      set_text ($In_note,"Note In: " & $EVENT_NOTE & "   " &...
                !Tones[$EVENT_NOTE mod 12] & ($EVENT_NOTE/12 -2))
      set_text ($Out_note,"Note Out: " & %mapping[$EVENT_NOTE + $Transpose] & "   " &...
                !Tones[(%mapping[$EVENT_NOTE + $Transpose]) mod 12] & ((%mapping[$EVENT_NOTE + $Transpose])/12) -2)
      play_note (%mapping[$EVENT_NOTE + $Transpose],$EVENT_VELOCITY,0, -1)
     
   end if
end on

on controller
   if (%CC_TOUCHED[90]= 1 and %CC[90]>64){CC90 is Bypass }
      $Bypass := 1
   else $Bypass := 0
   end if
   
end on


on release
   %InNoteVisual [$EVENT_NOTE-21] := 0
   %OutNoteVisual [%mapping[$EVENT_NOTE + $Transpose]-21] := 0
end on
```

Set, why don't you post your code and share it with us? 

T


----------



## set (Jul 18, 2006)

Here is what I have come up with. I needed to get the original note to play with the keymapped data. So I thought well, if I get the original to play why note transpose it up or down a couple of octaves. This worked out well. I than realized that I wanted a second root to follow and octave down from the original root so I added a second interval and that brings me to were I am almost happy.  

Here is what I have added:



> on init
> message("")
> declare ui_button $Choose_Note
> declare ui_button $Assign_to
> ...



So the thing I need to learn is how to tell the script were I would like to place the buttons and dials. I had to remove the input/output meters that were originally added because I couldn't figure out how to put the dials under the meters. Anyway I hope you find this mod useful. 

I have not had a chance to play with the latest edit which is the script bypass control but I'm sure it works just as mentioned and I am looking forward to adding in into my working script.


----------



## Thonex (Jul 18, 2006)

Hi Set,

Tt looks like your script Root and Interval perform the same function.

With regards to hiding tables and what not... this is from page 48 & 49 of the K2 Scripting PDF:



> Positioning of ui elements
> A script can appear with one, two or three height units. One height unit equals two lines, so
> six lines is the maximum a script module can have. The number of columns is always six.
> By using the command
> ...


----------



## set (Jul 18, 2006)

Thonex @ 18th July 2006 said:


> Hi Set,
> 
> Tt looks like your script Root and Interval perform the same function.
> 
> With regards to hiding tables and what not... this is from page 48 & 49 of the K2 Scripting PDF:



It does I just put 2 instances incase I wanted to have the root note an ocatve lower as well as the original pitch sound.


----------

