Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Friday, February 17, 2017

Recording generated MIDI to drag'n'drop object in Kontakt

Someone asked me to add MIDI drag'n'drop function to Rhythm Assembler sequencer. Apparently, in some DAWs recording MIDI notes generated by Kontakt is not quite trouble free. While adding this function to Rhythm Assembler would be a bit of a hassle, I thought, that capturing generated notes live and making the recording a drag'n'drop object inside Kontakt would be quite easy.

So, here's this simple script named "MIDI catch'n'drop". It will memorize all note on/note off messages (both send into Kontakt and those generated by instrument scripts) and write them into a drag'n'drop MIDI object. Suppose, you want to export a drum pattern from Kontakt instrument to MIDI. You load the instrument, put the catch'n'drop into empty script slot, press "start recording" button, start the drum sequencer, wait for the pattern to play through and then drag'n'drop midi pattern to your DAW or file system.

Some notes:
When you press "start recording" button, previous recording is deleted.
The script will only record notes generated by the instrument it's placed into and by scripts placed in previous script slots. So, it's best to place it in the last script slot.
Essentially this script is thought to help with instruments, which do not use MIDI object functionality. Instruments which actually use MIDI data, may have drag'n'drop function already available. Also note, that whenever you start recording in catch'n'drop script, it clears MIDI buffer in Kontakt. So, if the instrument is using MIDI object for note patterns, it will not play back anything, as the MIDI pattern will be deleted.
This script only records note on/note off messages.
While recording, the script will display buffer status and time of recording. Buffer defines how many notes you can record. When it goes to zero, the recording will stop and script will display message "buffer is full". Default buffer setting is 10000, so the script can record up to 5000 notes (two messages per note). You can rise buffer size in the script, changing $MIDI_BUFFER_SIZE, up to one million. Time is displayed in MIDI ticks (960 ticks per quarter note here).
If you plan to create a file, rather than dropping pattern straight into a DAW, you can change generated file name. Just double click "file_name" and enter new name. Note that it may not be possible while sequencer is running (it's Kontakt's "feature").

You can get the script here:
as preset file
or in plain text

Use at your own risk! This script is provided ‘as is’ and there is no warranty of any kind.

Sunday, January 22, 2017

Rhythm Assembler

And now something completely different... A step sequencer.

Well, it really is a bit different. Rhythm Assembler is a drum computer script I wrote for Kontakt, remains of a cancelled project. Usually a step sequencer has a regular grid, you can use to place notes. Here, you define the grid structure, assuming there's a note at every step. It may seem backwards, but once you overcome old habits, it may be simpler to do it this way. Example, you want a four on the floor, you only need to program one step. Also, I feel, breaking down a rhythm to such formula, gives me a better understanding, of how the rhythm works.

The machine offers 8 sequence tracks, each can have a different grid sequence with different cycle loop. Grid step is defined as a multiplication or fraction of base duration, like "1 quarter note", "3 sixteenth notes", "1/3 half note" or "3/4 whole note". On top of that you can program a repeat sequence, telling the machine how many times to repeat a grid step. Considering both sequences can have a different loop cycle, it is possible to program fairly complex rhythms with a simple formula. Also the sequencer is not bound to a time signature, you can program odd, irregular rhythms, rhythms with asymmetric measures.
Another, somewhat uncommon feature of the sequencer is the "humanizer" function, which not only can delay notes by random duration, but can play them too early as well. This "timing error" function can be configured separately for each track.

And here's a quick overview video:

Rhythm Assembler is just a script, it comes with no samples and no instrument patches. There are script preset files, you can add to an existing instrument. Which is also the reason, there is no custom graphic interface and the background is black (for the workaround to disable instrument's background image). The script requires Kontakt 5.6.5 or later to work. It could be rather easily ported to any earlier version of Kontakt 5 and with some work and (loosing option to rename sounds) to Kontakt 4.

The script is free to download and use (although it's not free to re-distribute). DOWNLOAD IT HERE. To install the script, you need to locate Kontakt's user preset/scripts folder and copy the "Rhythm Assembler" directory there. There are several example presets, with pre-programmed rhythms and an "empty" preset.

There's some further beta development, you can follow here (scroll down the thread).

Friday, January 1, 2016

On reversing instruments in Kontakt

I wonder how would that piano sound backwards... That probably crossed every sampler user mind, at least once. Well, Kontakt has 'reverse' button, press it and Kontakt will play the samples backwards. However, the problem is, samples often have very long tails, so it takes a while until you can hear the sound and it's useless for dynamic playing. You would want to play the sample, but not from the beginning (or the end, depending on how we look at it). For this 'offset' parameter can be used, it tells the sampler from which point in the sample it should start playback. Now, another problem is, that samples have different lengths. To have more or less consistent volume envelope, when playing chords, you would want all played samples to reach the end of sample (reversed beginning) at the same time. Since offset is calculated from the beginning of the sample, and for reversed playback, from it's end, it's problematic. You would need to know the sample length for each note to calculate the proper offset. Considering velocity layers, it can be a lot of coding.
I wanted it, to be done automatically for any instrument, so I could play around with sound reversing. I came with somewhat crude solution, I wrote a script which will retrieve sample length for every note and every velocity in a group, remember it and apply offset accordingly when playing. To fetch the data for any sample set, I needed the script to actually play each note, so it could retrieve zone id and then sample length. Scanning takes a while, but in the end it's way faster, than doing it by hand. Here's a little presentation of reversing Kontakt's factory sitar.


You can get the script here. Both a preset file (which need to be copied to your Kontakt/presets/scripts folder) and as plain text that can be copied into Kontakt. It will work in Kontakt 4 or newer.

The shortcomings of this solutions are:
  • You can only use one group for reverse playing, so no round robin backwards.
  • It will work best on instruments build on sample per note basis. If samples are re-tuned, playback speed will vary and since offset is provided in microseconds, it will get misaligned. The more tune change, the more misalignment. To compensate for this, script would need to learn root key for each sample, which I don't know how to automatically retrieve in KSP.

About using the script:
  • First locate the group you want to reverse and set 'targ.group' accordingly. First group has index of zero.
  • Change sampler mode to 'sampler'. Disadvantage here is, that it will load all samples to memory, but offset parameter doesn't work in DFD mode. If you need to use DFD, you would have to edit 's.mod' value in wave editor to match sample length. And do that for every sample. No fun.
  • Switch reverse button!
  • You can adjust 'interval' setting, it's time to take to scan single note/velocity combination in microseconds. Lower the setting to scan faster. However I found that at low settings, the script failed to retrieve data correctly, 500 didn't work for me, 1000 did, but this may depend on settings/setup. I would consider 3000 a safe setting.
  • Now press scan button and wait for it to complete. If you need to break the process press it again.
  • Scanned data will be remembered in DAW project / patch, so if instrument/project is saved, you don't need to scan again.
  • Note that, the scanner will skip any note that hasn't a sample mapped at velocity of 1, to speed up scanning process.
  • Position knob sets the offset value, that is how far from the beginning should playback start. You can adjust this value while playing. Try not to exceed shortest sample length, or shorter samples will get misaligned.
  • When duration knob is set to zero, samples will play as long as the key is held (or until they reach the beginning of a sample). Any other setting will generate notes of fixed duration, defined in percentage of offset setting. You can use it, to prevent playback to reach the beginning of the sample and for smoother sound tail, if combined with volume envelope.
  • This script can interfere with other scripts, particularly those which also do ignore_event, play_note sequence, like factory portamento script, so you may need to disable other scripts, if it doesn't work.
  • Have fun reversing!

Friday, June 5, 2015

CC switch, virtual sustain pedal multiscript for Kontakt

I wrote this little Kontakt multiscript to automate sustain pedal from midi keyboard. I tend to loose sustain pedal in my floor level room chaos, as I keep it unplugged and I don't quite use it too often. I thought it would sometimes be handy to have a midi key acting as a CC switch, if only for testing purposes.


So, this script can be used to make a key act as sustain pedal, which is default setting, or to automate any other CC controller. You can assign two values to a CC and then switch between them, using midi keyboard or virtual button. Also you can set automation for secondary CC, so you could automate two different settings with the switch.

In example on screenshot, pressing MIDI key 36, will set CC20 to 0 and CC21 to 70. Releasing the key will set CC20 to 70 and CC21 to 0.

You can download the script preset here. It needs to be copied to multiscript preset folder (in my Windows it's "my documents\Native Instruments\Kontakt 4\presets\multiscripts"). This is multiscript, so you load it on top of instruments (use the scroll button). It has been written in Kontakt 4.2.4.

Monday, March 23, 2015

Note looper/recorder/player multiscript for Kontakt

This is probably pointless exercise, because it is what people use sequencers for, but I made an attempt at writing a script which would record and playback incoming note sequences in Kontakt. I was aiming at something that would allow me to record sequences while playing and then switch through them from keyboard. I took it to a point where I'm able to jam with it, e.g. trigger different drum loops and bass loops while playing another instrument. Feel free to try it out.

DOWNLOAD HERE
DOWNLOAD revision C
These are script preset files, they need to be uncompressed to multiscript preset folder (in my Windows it's "my documents\Native Instruments\Kontakt 4\presets\multiscripts"). This is multiscript, so you load it on top of some instruments. It has been written in Kontakt 4.2.4.

Update: revision C scripts should fix incompatibility with midi controllers, which use zero velocity note on command instead of note off command. Also midi learn function, may be a bit more bulletproof in this version and key cluster tape change automation functionality is fixed for reel 2. Rev C pack contains x2 and x4 versions.

It is an experiment and it is possible, it may have some bugs, so be cautious with it. I don't have the drive for bulletproof testing of this script, so take it as it is, maybe you will find it useful, but have in mind that it may go south at some point.

Note, if you re-save the preset, all recorded sequences will be saved within the preset, so you can easily make sequence sets.

A little guide to the script.

The script will memorize incoming note on and note off messages (no other MIDI data is processed) and then play back the sequence on request.
There are two versions of the script "x1" is a kind of one track recorder and "x2" has two tracks, so you can playback two sequences simultaneously.
Press record to start recording, which actually starts on first incoming note (the gap before pressing record button and receiving first note is ignored). When done press record again to stop the recording, or press play to stop recording and start playback right away. If loop switch is on, recorded sequence will play in a loop, else it will stop after last note. If auto rewind switch is on, the recorded sequence will start from beginning, when you press play button, else it will start from where it stopped.
There are 8 "tapes" per reel, so you can record up to 8 sequences which you can switch through while playing. If play button is on, tape will not change immediately, but it will be scheduled. After coming to the end of currently playing sequence, the machine will load selected sequence. This way you can switch loops "in advance". Each tape can store up to 2040 events, so a bit more than 1000 notes. If the limit is reached, the recording should stop automatically.
Play, record and tape change commands can be automated with midi keyboard. Note, that key used for automation will be unavailable for triggering notes. Tape change command has three automation modes, you can use CC message, a series of 8 keys, where pressing a key will load corresponding tape, or use one key to toggle through tapes. In last mode there is option named "select empty", when the switch is off, the machine will only toggle through recorded sequences, skipping empty tapes (as selecting empty tape will stop playback).
Snap is function, which will try to align recorded sequences to current tempo. When it's activated, the machine will wait for sync when starting to play the sequence, on play button or when restarting a loop. There is no synchronization in between, so this machine is not suitable to playback whole songs, better stick to 1-6 measure loops. So, e.g., if you pick snap resolution to whole note in 4/4 meter, have snap switches enabled and press play, the sequence will start at beginning of next measure.
Synchronize is function which will attempt to recalculate recorded times to fit a recording to different tempo. This is somewhat tricky, as the machine memorize events like this: note on, wait some thousands milliseconds, note off, etc. At the moment of recording, the quarter note length is stored, which is then being compared to current quarter note length and used to recalculate waiting times throughout the recording. Tempo changes while recording are not stored.
Key setting is simple transpose function, it will add key value to note numbers on playback.
Input port and channel settings can be used to pick a source of data, in case you have multiple controllers. "x2" version of the script has simple data router, so you can switch instruments while playing/recording. Changing channel/port can be automated with a key or CC.
There are somewhat limited "sequencing" options in Kontakt multiscript, so I made this script using "wait" command together with, $KSP_TIMER and $DISTANCE_BAR_START variables (first to detect event times, second to sync with tempo). The second variable is only being updated in Kontakt when transport is running, so synchronization will fail, if the play button is off in host. In standalone mode, it will always work, as Kontakt assumes transport is always on.

Feel free to write me, if you find it usable, yet limited or bugged in some aspect. I may look into it again.

Friday, March 6, 2015

Keyboard splitter multiscript for Kontakt

I wrote a little script for splitting keyboard in Kontakt. This may be handy, if you'd like to send part of the keyboard to one instrument and the other part to another instrument. Keyboard splitting can be done in many ways, but multiscipt is probably the most convenient to use. The script front looks like this:


You can split and re-direct data from any port/channel, in which case all midi inputs will be routed to destination channels. Or you can split selected channel only, in case you have multiply controllers connected. There is midi learn function for split position and octave transpose function for each part of the keyboard. The script is splitting "note on", "note off" and "polyphonic aftertouch" messages, however as I don't have any keyboard with poly aftertouch, this last function is somewhat untested. "Other messages" (pitch bend, CC, program change, etc.) can be blocked, send to one or both of destinations. The script sends "all notes off" messages to all channels, each time you manipulate its settings, to avoid "stuck notes".

If you think it might be useful to you, you cab grab it HERE. It will work Kontakt 4.2 or newer, I'm not sure about earlier versions. Remember that it is multiscript, you insert it in multi rack, on top of all instruments (use the "scroll" button to activate multiscript rack).

If you feel like splitting the keyboard further, you can insert copies of this script into following script slots, use specific channel in that case. E.g. split all inputs to channel 1 and channel 2 with first script, then split channel 2 to channel 2 and channel 3 with second script. With 5 script slots you could split the keyboard up to 6 parts, which, I bet, would be a lot of fun...

Monday, October 20, 2014

Automatable MIDI channel router script for Kontakt

This is my first exercise in writing a multiscript for Kontakt. It's a little tool to route MIDI messages between channels inside Kontakt. It may be used to switching instruments with keys or controllers while playing. It looks like this:


The top row of buttons is where you select the destination channel, these buttons can be automated, with keys of CC controllers. There are two routing modes: single channel is where you redirect midi messages to a channel of choice, in multi channel you can select multiple channels as destination, so you can reprogram a multi instrument setup live.
There are three ways of automation. Use keys, is where you assign keyboard keys as channel switches. You set (manually or by learn button) "start_from" parameter to point to first key number to use, from now on following 16 keys will be used to toggle channels switches. If you don't need to automate all 16 channels, or don't want to trade off so many keys, you can reduce automation range with "size" parameter. You can do the same using CC controllers, "use multi CC" option. Or, if you only use "single channel" destination, you can "use single CC" controller to set destination channel. Automation source can be assigned to any port / any channel, or a specified channel. So you could for example use one controller to play and another controller to select instruments. And this is how it works...


If you'd like to try it, download plain text file, or Kontakt preset file (to place in Kontakt's presets/multiscripts folder). It should work in Kontakt 4.2.4 or newer, I'm not sure about earlier versions. I tested it roughly and it seems to work, but there are no guarantees, so use it at your own risk. Also remember that it is multiscript, you insert it in multi rack, on top of all instruments (use the "scroll" button to activate multiscript rack).

Thursday, September 18, 2014

Key shuffler script for Kontakt

Another little Kontakt script today. This one will reorganize key-note assignments within an instrument. It can turn a pop ballad into modern atonal composition, or it can be lots of fun on drum kits. It looks like this:


Quick manual. 'Shuffle range' - here you set the range of keys to shuffle, set the lowest and highest key. To set it up quickly, use 'learn range' button, then press two keys one after another (in any order), the script will set the knob values accordingly. 'Shuffle intensity' - set how much shuffled you want keyboard to be. In one round the script takes two keys and exchange their note assignments. 'Shuffle method' - here you set the starting number for calculating key numbers to shuffle. When it's all set press 'shuffle keys' to perform the operation, or press 'restore keys' to return to 'un-shuffled' keyboard state. The shuffle is not random. It's calculated from range, intensity and method, so you can easily get back to a result you like, or you can automate shuffling in DAW. There are 1000000 possible combinations for each note range.

Here's how it works applied to one of Kontakt's factory drum machines. This machine is using 'drum computer' to create rhythms, so the notes can be shuffled. In this video I keep one rhythm pattern going while trying out different shuffle parameters.


If you like the idea, you can get the script here. It should work in Kontakt 4.2 or newer. Have fun.

Update: Revision A.

After a while of playing with drum kits, I though I would explore this idea a little further. I attempted to expand this script functionality.


First, I wanted to leave some keys out of the randomizing process. So I could e.g. have a bass drum and a snare going on, while randomizing sounds for the rest of drum pattern. I introduced two new buttons to script. 'Learn exceptions' - turn it on, now press the keys you don't want to be affected by the script, turn it off when finished. This procedure won't change the way keys are shuffled, it will just disable note properties modifications for keys in exception list. Exceptions list can be cleared any time with 'clear exceptions' button.

Another new feature is randomizing sound pitch, which can be quite fun with drums. Now every time 'shuffle keys' button is pressed, the script will create a pitch map for all keys, which will be derived from 'shuffle method' number (this is not depending on number of rounds). You can then control how much of the pitch modification to apply with 'shuffle pitch - range' knob. Also you can change pitch map polarity with the switch, mysteriously named 'pitch md. polarity'. Note that once pitch map is written, it will affect sounds also after you un-shuffle keys with 'restore' button. Pitch will be drawn from range of -24/+24 semitones. You can change maximum pitch range in the script, by editing $DETUNE_RANGE constant.

Get the expanded version of the script here.


Update 2: Small changes.

I make two small changes to the script... I have been testing its usability as a de-tuner. You can put a little life into some instruments (particularly synthetic) by de-tuning notes a little. Try this procedure: select a method number, shuffle keys, restore keys and move 'pitch range' knob just a little bit.
Some Kontakt instruments, like pianos, generate several notes, on one key stroke. It was quite disabling 'learn note range' function. As a workaround I added a condition to not to accept the same note as the second note of the range in learn function.
Another change is note range functionality, thus far it was only used when shuffle button was pressed. I added a condition, so the range is checked each time a note is played. Now you can manipulate range button while playing a shuffled keyboard, so you can automate restoring some keys original assignments and tuning.
The download link has been updated.

Update 3: Revision B.

Wouldn't it be handy, to trigger some of those buttons by a key? My controller has only knobs and sliders. Automating buttons with CC is not quite comfortable, so... Excuse me for yet another incarnation of this script. This one has 'key-learn' function for shuffle, reset and polarity buttons. They are color coded on virtual keyboard, red for shuffle, green for reset and yellow for polarity. Note that key assignments may interfere with instrument's key switches handled by other scripts, so it's best to make sure the key of choice has no other function.

Key shuffler script, revision b, download link.

Wednesday, September 17, 2014

Fake random round robin script for Kontakt

This little tool spawned from Terrible piano instrument. It's a script for NI Kontakt which simulates round robin functionality. What is does is: take incoming note, trigger random different note from defined range and tune it to match the pitch of the incoming note. So it is using 'neighbor' notes, to introduce sound variations.
Obviously, it will only work on instruments which have different samples assigned to each note (or most of notes to some degree). If the instrument is based on a single sample, stretched all over the note range,  it will produce no audible results.
Besides 'faking round robin', it can also fake classic stereo effect, where you record two takes of the same phrase and then pan them in stereo. There are two controls. Round robin range is, how far from the original note can the machine look for substitutions. When range is set to zero, the effect if off. Stereo spread activates stereo effect. It only works when round robin is active. It simply triggers another random note and then positions both notes in stereo field according to spread value. In some cases it can produce a flanging effect.
I don't know, how to automatically detect instrument's note range in Kontakt, so it has to be set manually, by editing values in the script. Else some notes may wander off instrument range and produce no sound in effect.
Here's how it works, applied to one of Kontakt's factory e-pianos.


The effect can be subtle or weird, depending on instrument and settings. If you'd like to go weird way, try it on a choir library and push it to the limit.

The script is using classic algorithm to generate random numbers. It will restart the generator on transport start (whenever you press play in DAW), so if  you use it in a project, it will always render the same result.

You can download the script here. It will work Kontakt 4.2 or newer. Have fun with it.