Kontakt KSP and objects
I've found only arrays. however, to reduce the complexity of my code (searching) to o(1) I need to use dictionary data structure which also known as Associative_array (objects or dictionary).
in simple words i'm looking for a way to declare arrays with string as key, like:
%arr["key"] := value
Is it possible to define / declare objects with ksp?
Reid115 Member Posts: 47 Sine
No. But, in any scenario I've wished I had dicts/maps, there's always a relatively elegant workaround using arrays (and without search() -- I think that function is pretty slow). It would help to know what specifically you're doing. I can't imagine o(n) would be a huge problem vs. o(1).0
KSP is not an object-oriented language, and all the data types that it has are in KSP reference: integers, reals, strings, integer arrays, real arrays, string arrays. That's it!0
@Reid115 thanks for your response I built a chord recognition script.
I collect all the held notes i.e [-1,0,4,9], now I have to search what chord match for this pattern.
to find the chord, we are talking about array of 12*27=1524 (12-chords/scales [c,c#,d,d#,e...] * 27 types of chords [maj,min,m7,maj7,dim...])
does it make sense to go over 1524 elements each time? when with map/dic it'd be o(1)
@Reid115 i fond that I can "hash" the patterns(i.e [-1,0,4,9]) to be an int (i.e 2427) with some math calc and then create an array size 10,000. and then hold the pattern in the hash results like
declare %arr; %arr := "Cmaj";
With this approach I can achieve o (1) search operation, but the downside is that I have an array of size 10,000.
I'm not sure which better array of 10,000 with o(1) operations or search in o(n) (in my use case it would be 1524 elements), wdyt?0
Because Lua (especially LuaJIT) didn't exist back in 2005 when KSP was introduced, and JS was definitely not good for realtime audio thread performance back then. Then everything snowballed and nobody wanted to introduce more friction and risk by completely changing the language that Kontakt uses.
As for your last question... it's as always, trading memory vs CPU. You spend more memory in order to save CPU by not having to do search(). (By the way, search() is just basic linear search, nothing fancy.) I would personally commit to that tradeoff, if the goal is to be as efficient as possible at runtime.0
@EvilDragon thanks for your response, I agree with you. IMO, It is worthless to argue in what language they'd already decided to use KSP. however, Kontakt and Ksp is still in development, so why don't add objects to the language?
anyway, of course that at the end all comes to CPU vs memory.
how you decided to say that the search is better than a large array(size 10,000)? how much bytes you take for this array? in terms of computers with 16gb+ of ram it could be very tiny. while search is linear which means it could run over 1524 item every chord change.
i'm not saying that i wouldn't go with search function. but i'd like to hear why you said: "I would personally commit to that tradeoff, if the goal is to be as efficient as possible at runtime."
again, wanna say thanks :)0
@EvilDragon by the way if I use "Instrument Bank" and i move between banks/instruments
when the "on_init" executed? each instrument bank change? or only on the first loading?0
"on init" is executed on initial load and audio engine reset (that "!" button in top right).
By the way, I did not say I would choose search() over the large array. I would go with O(1) myself, too. When I said I'd commit to that tradeoff, I meant "trading memory usage to save CPU at runtime".
Adding objects to KSP is very likely never happening.0
- 10.6K All Categories
- 20 Welcome
- 442 Hangout
- 58 NI News
- 206 Tech Talks
- 1.1K Native Access
- 4.9K Komplete
- 614 Komplete General
- 1.1K Komplete Kontrol
- 1.8K Kontakt
- 483 Reaktor
- 153 Battery 4
- 268 Guitar Rig & FX
- 204 Massive X & Synths
- 211 Other Software & Hardware
- 2.2K Maschine
- 14 Sampling Room
- 2.6K Traktor
- 2.4K Traktor Software & Hardware
- Check out everything you can do
- Create an account
- See member benefits
- Answer questions
- Ask the community
- See product news
- Connect with creators