HISE Script Coding Standards
-
@d-healey its what I do too...
-
Good idea and yes, definitely go for the ALL_CAPS constants.
I'll go through it and do a pull request for the stuff I find, but it's mostly spot on.
I would also recommend that for performance-related coding tips, you include a benchmark of the good and bad result so that people can directly see the benefit. Here's for example a minor tip to call
reserve()
before pushing large amounts of data:const var NUM_ELEMENTS = 100000; const var badList = []; const var goodList = []; Console.start(); for(i = 0; i < NUM_ELEMENTS; i++) badList.push(i); Console.stop(); // ~41ms Console.start(); goodList.reserve(NUM_ELEMENTS); for(i = 0; i < NUM_ELEMENTS; i++) goodList.push(i); Console.stop(); // ~39ms
The 5% perfomance benefit of this tip may not be enough to be taken into a "official" coding style doc though :)
-
@Christoph-Hart I've added the note about the
reserve()
keyword, I think it's good to have it there as a reminder (I always forget about it!). I also added the rule for all caps constants and tweaked a few other bits. Adding benchmarks is a good idea, I'll go through the examples and add this when I have a bit of spare time. -
@d-healey Now I've read the scripting standards at least 4 times, and for me it's really good to have this document, I learn a lot and understand more and more of the complexity in scripting, and also why the standards makes it so easier to understand the code.
Thank you once again for making this document! -
@d-healey Oh I forgot to ask, in the doc you say:
"Prefer MIDI Lists over arrays when possible, especially for storing polyphonic data."How do a MIDI List work, is it an array with all the array functions?
-
@ulrik I think Christoph explained it well here - https://docs.hise.audio/scripting/scripting-api/midilist/index.html
-
@d-healey Thank you!
-
@d-healey said in HISE Script Coding Standards:
@ulrik I think Christoph explained it well here - https://docs.hise.audio/scripting/scripting-api/midilist/index.html
Question for @d-healey and @Christoph-Hart : Can a MidiList array store multiple dimensions of data? Like a multi-dimensional array?
I ask cause an important KSP script I am trying to recreate use a polyphony script containing 128x4 values that look for amounts of current equal note hits. Would I be able to nest midi-lists in a normal array? Or do they come with multi-depth features?
Additional question. Is there a performance overhead using MidiLists over a normal array/nested arrays when accessing specific / one-time data, not looped, but like this:
var get_my_value = my_array[0][3]
? Or is the performance in the iteration? -
@andioak A MIDI List is a single dimension array with 128 elements that can store numbers. Yes you can store MIDI Lists in an array.
-
@d-healey Okay, thanks. Will probably be using lots of those then. :)