# Additions to the SublimeKSP compiler



## FrozenPlain

A while back Jonathan Thompson did a fantastic job of setting up Nil's KSP Compiler for Kontakt 5.5 and for Package Control. Since then I've added some new features to the compiler, which are now part of this package. You can get the latest version of SublimeKSP from Package Control, or if you want to install it manually you can download it from GitHub.

Download: SublimeKSP

Details of the new features with examples: GitHub wiki

For any bug reports, the issues section on GitHub is the best place, or if not you can post them in this thread.

This new version supports Kontakt 5.6 and also has a load of new extended syntax. These features are all optional so they will not effect any of your current scripts. 

Key new features:

*Make arrays of UI controls*. No more making a long list of declare statements! The IDs are automatically made into an array, and the persistence can be handled with 1 keyword. You can also use new the iterate_macro() to create all the UI callbacks in one go.

*Structs*. A new simple data structure that allows you to group variables together and create instances of them, even as arrays. See the wiki for their limitations.
*New macro type*. There is a new macro type called the define macro that can be a text substitution for anything.
*New array type called list*. Lists are a simple construct that compile down into native arrays, but with lists you no longer need to worry about the array size and adding each element using a different number.

*Multidimensional arrays*. Properly create multidimensional arrays of any type (even UI) with constant variables generated as well for the dimension sizes.

*New functions for setting a load of UI properties at once*. These functions take an optional number of arguments, so you only need to set the properties that you actually want.
*New feature for integer constants*. Constants are great, and necessary for writing robust code in this language. You can now create a set of constants in a block with 'const <name>' and 'end const'. You can optionally have the values automatically generated.
Other features:

New single lines comments with //
Keyword 'pers' to make a variable persistent.
Always have the option to initialise a variable.
Automatic size for initialised arrays.
Initialise string arrays on 1 line.
New set of functions for setting the properties of UI controls.
Function for iterating a macro, either by number or by literals.
Create a run-time message log file, and print messages to it with a print() function.
Compiled code now has the time and date written into it.
Concatenate function for joining multiple arrays into one.
Create lists of lists (add single dimension arrays as elements to an array).
Handy built in macro for incrementing a number over lines of code.

Installation:



An example:


Code:


define NUM_PAGES := 5
on init
    set_ui_height(6)
    declare pers ui_menu   menus   [NUM_PAGES]
    declare pers ui_slider sliders [NUM_PAGES] (0, 100)

    list !menuItemText
        "Staccato"
        "Legato"
        "Pizzicato"
    end list

    declare i
    for i := 0 to num_elements(menuItemText) - 1
        // We are forced to use a macro here, because add_menu_item() does not accept UI IDs.
        iterate_macro(add_menu_item(menus#n#, menuItemText[i], i)) := 0 to NUM_PAGES - 1
    end for

    for i := 0 to NUM_PAGES - 1
        // Set the slider default, picture and mouse behavior in 1 command
        set_slider_properties(sliders[i], 50, "Knob_Graphic", 500)
        // Set the x, y, width, height of the menus and sliders
        set_bounds(menus[i]   , 10 + i * 90 , 20           , 86 , 18)
        set_bounds(sliders[i] , 10          , 40 + i * 20)
    end for
end on

function messageSliderValue(pageNum)
    message(sliders[pageNum] -> value)
end function

function messageMenuValue(pageNum)
    message(menus[pageNum] -> value)
end function

macro pageCallbacks(#n#)
    on ui_control(menus#n#)
        messageMenuValue(#n#)
    end on
    on ui_control(sliders#n#)
        messageSliderValue(#n#)
    end on
end macro
iterate_macro(pageCallbacks) := 0 to NUM_PAGES - 1


Like the original, these additions are open source, you can contribute here: https://github.com/nojanath/SublimeKSP

Sam


----------



## EvilDragon

Some really neat additions here!!


----------



## Mike Greene

This looks really cool. The two dimensional arrays, as well as the bulk defining of ui controls look especially useful. Oh, and single line comment markings would be great, too. Thank you or doing this.

Funny, I've been very reluctant to use the various shortcuts already available. I still type the $ symbol in front of all my variables! I don't know why, but I try to write my code so that it could be plugged into Kontakt directly, even without the Sublime compiler. I guess part of the reason is so that if Kontakt tells me there's an issue on Line 1472, then I can actually see what line that is.

I guess I need to move into the 21st Century, though . . .


----------



## tack

This sounds awesome!

It's still lipstick on a pig of course. But that pig is starting to smell a bit more like bacon.


----------



## EvilDragon

Bacon is awesome.


----------



## FrozenPlain

tack said:


> It's still lipstick on a pig of course. But that pig is starting to smell a bit more like bacon.


Haha  There are some still some really clunky parts of Kontakt script. For example forcing us to use UI names rather than UI IDs.




Mike Greene said:


> I guess part of the reason is so that if Kontakt tells me there's an issue on Line 1472, then I can actually see what line that is.


That's a good point. What I like to do is leave the 'Remove indents and empty lines' option off in Sublime. Then you can open the compiled text file up and use CTRL+G to jump to the line number. While it might look a little different to the uncompiled version, you can usually make sense of it.


----------



## Lindon

Just one (very small) point,. I don't know about anyone else, but I have to restart Sublime Text to get the new package to work, maybe if this is true for everyone you should add it into the installation instructions.


----------



## Lindon

...also: LogFileReader doesn't seem to work on Windows 7, which is (sadly) the OS on one of my machines, so I'm using BareTail if anyone else is stuck in the same situation...


----------



## FrozenPlain

Thanks, we can add that in. Unfortunately I've only tested LogFileReader on Windows 10. When I have some time, it shouldn't be too much work to build it for other OS's.


----------



## d.healey

Thanks, this looks awesome. Can't wait to try it out


----------



## Tod

When I opened Sublime 3 Text today, there was notice for what I assume is this update. I went ahead and clicked on it and it automatically installed.

Can I assume I'm good to go with this?



Mike Greene said:


> Funny, I've been very reluctant to use the various shortcuts already available. I still type the $ symbol in front of all my variables! I don't know why, but I try to write my code so that it could be plugged into Kontakt directly, even without the Sublime compiler. I guess part of the reason is so that if Kontakt tells me there's an issue on Line 1472, then I can actually see what line that is.





FrozenPlain said:


> That's a good point. What I like to do is leave the 'Remove indents and empty lines' option off in Sublime. Then you can open the compiled text file up and use CTRL+G to jump to the line number. While it might look a little different to the uncompiled version, you can usually make sense of it.



Oh yeah, good ideas, tracking those problems down can be a real pain.


----------



## FrozenPlain

Tod said:


> When I opened Sublime 3 Text today, there was notice for what I assume is this update. I went ahead and clicked on it and it automatically installed.
> 
> Can I assume I'm good to go with this?



This update is not automatic from the original compiler. However, when this new version is installed with package control, the updates will then be automatic.


----------



## Tod

FrozenPlain said:


> This update is not automatic from the original compiler. However, when this new version is installed with package control, the updates will then be automatic.



Thanks, I think I've got it.


----------



## FrozenPlain

New update! It is automatically applied if you use package control. There are a couple of little bug fixes, and also some new features. Have a look at the wiki for examples. https://github.com/nojanath/SublimeKSP/wiki/Added-Features


New list blocks with 'list <name>' and 'end list'. Instead of using a whole load of list_add() commands, you can declare a list and assign it a set of values in a code block. list_add() still works as normal. There is also a constant variable for the list size generated.
New constant integer blocks with 'const <name>' and 'end const'. You can create a set of constant integers in a block. The value of the constants can optionally be automatic, by default the first is 0 and each one after is the previous + 1. There is also an integer array generated, though as usual if you do not use it, the compiler will omit it when 'Optimise compiled code' is on.
New shorthand for read_persistent_var(). For any variable you can use the keyword 'read' to both make the variable persistent and also read its persistent value. The 'pers' keyword only makes it persistent.
New iterate_macro functionality. There is a short way of iterating a one line macro. Simply put the line you wish to repeat in the brackets of the iterate_macro() command, and use the token #n# to show the places that you want numbers to be substituted. At least 1 #n# token must be found to use this functionality.
New define functionality. You can use define as a literal text substitution macro. To do this, sandwich the value with # symbols. The text inside the # is replaced at the location you use the define, so be careful with this.


----------



## Tod

FrozenPlain said:


> Visit here to download: SublimeKSP



Hi Sam, sorry to bother you with this but I'm a little confused about how to install this.

I went to "Package Control", copied the "SUBLIME TEXT 3" into the console and restarted sublime, but am confused from there.

I opened Command Palette and here is where I'm confused. These are the instructions:


Type “Install Package”

Type “KSP” or “Kontakt” and select “KSP (Kontakt Script Processor)”
I typed in “Install Package”, hit enter and nothing happened. So I tried adding KSP to it and nothing happened.

What am I missing?


----------



## FrozenPlain

Hi Tod,

Once you copy the code from the installation page for Package Control into the console, you will need to hit enter. If you have installed package control correctly, when you open the command palette with Command+Shift+P (OS X) or Ctrl+Shift+P (Windows) when you start typing 'install', you should see an option automatically highlight called Package Control: Install Package. Hit enter, then start typing KSP to select that package and hit enter again.

Sam


----------



## Tod

Thanks Sam, I think I've got it. I think the part that was missing is after pasting Package Control into the console, there was nothing about hitting enter, at least I didn't see it, I did try to save it, but of course that didn't work.

One more question, is there a quick easy way to make sure it's installed properly?

Tod


----------



## FrozenPlain

You could try some of the new syntax and see if it compiles ok, such as the // comment. If not, perhaps you need to disable or remove the old version


----------



## Tod

Okay, thanks very much Sam, I think I've got it, but I'm going to have to setup my colors again.

When I load an older script, the colors show as they should. But if I add the "//comments" they don't show up as green.

I opened Preferences and all the "//comments" are green. Also I added a "//comments" to the old script and then compiled it and it compiled as it should and the "//comments" was gone because I have it set up to remove comments, but there's no colors.

I'll play around with this and see what I come up with.


----------



## FrozenPlain

I'm pleased you've got it working. However, all of the new syntax has the proper syntax highlighting and colours, perhaps you are still somehow using the old syntax highlighting file?

With the command palette (ctrl_shift+p) you type disable and hit enter to start disabling packages. The old version of the compiler will be called SublimeKSP, while the new version is called KSP (Kontakt Script Processor). Its best to disable the version you are not using.


----------



## Tod

Okay thanks again Sam, I will give this a try.


----------



## FrozenPlain

Update, with 2 new features! I've also updated this original forum post. Thanks to Andreas for implementing the literate_macro() feature.

You can now create multidimensional UI arrays.
New function for iterating a macro using a list of literal strings. First you define a list of literals, then use the command literate_macro() to call the macro for using each literal in the list as the argument. Have a look to see if you can achieve what you want with the UI arrays before you go bonkers declaring all your UI with macros!


----------



## derstefmitf

Hi,
I installed the KSP plugin via PackageControl, but I now get an error message with this line of code:


Code:


filter_load_id := set_engine_par(ENGINE_PAR_EFFECT_SUBTYPE,FILTER_TYPE_SV_LP4,-1,2,NI_BUS_OFFSET+1)

I use the variable for a async check and with the old package, which I installed manually, this was no problem.
The error message is this:


> Expected expression of integer type, got None. (line 4879)
> pluckP_FX.filter_load_id := set_engine_par(ENGINE_PAR_EFFECT_SUBTYPE,FILTER_TYPE_SV_LP4,-1,2,NI_BUS_OFFSET+1)
> 
> <main script> line 2788



Thanks.


----------



## andreasOL

Hmmm...set_engine_par doesn't return a value, so I wonder why it worked before. The message can mean that on the right side of the assignment an Integer is expected (which is correct), but set_engine_par returns nothing, i.e. "None"


----------



## derstefmitf

Ok, I thought that this would be necessary when you change an FX slot. I found this in the KSP 5.5 reference manual: 


> *on async_complete callback *
> 
> Changing FX slot contents is an asynchronous operation. This means, one cannot reliably access the newly instantiated effect immediately after instantiation. To resolve this, the command returns an $NI_ASYNC_ID and triggers the on async_complete callback.



This is what I do. Here some more code to make it more clear: 



Code:


function update_filter_type
    filter_load_id := set_engine_par(ENGINE_PAR_EFFECT_SUBTYPE,FILTER_TYPE_SV_LP4,-1,2,NI_BUS_OFFSET+1)

    while filter_load_id # 1
        wait(1)
    end while
end function

on async_complete
    if NI_ASYNC_ID = filter_load_id
        if NI_ASYNC_EXIT_STATUS = TRUE
            filter_load_id := 1
        end if
    end if
end on


----------



## andreasOL

Oh...right...K5.5 accepts this. Then the syntax checking of the new KSP package is too restrict. I can contact the author...


----------



## derstefmitf

andreasOL said:


> Oh...right...K5.5 accepts this. Then the syntax checking of the new KSP package is too restrict. I can contact the author...


Thanks, that would be cool. All in all, I am really happy with the new KSP plugin, but I use this routine quite a lot in my current project, so it would be nice to leave the script as it is right now.


----------



## andreasOL

I have filed a bug report.


----------



## derstefmitf

andreasOL said:


> I have filed a bug report.


Thanks.


----------



## EvilDragon

If you disable Extra syntax checks, it should work. Alternatively, you need to change the ksp_plugin.py file a bit to accomodate. Find this:

builtin_compl_funcs1.sort()
builtin_compl_funcs2.sort()

Notice the for loop above those two lines. If set_engine_par() and _set_engine_par() are not there, add them. Restart SublimeKSP.


----------



## FrozenPlain

I wasn't aware that set_engine_par had a return type either. I will fix this for the next update.



EvilDragon said:


> builtin_compl_funcs1.sort()
> builtin_compl_funcs2.sort()
> 
> Notice the for loop above those two lines. If set_engine_par() and _set_engine_par() are not there, add them.



Thanks! Yep this is for correctly adding the function to the auto completions. I believe in the ksp_builtins_data file, the set_engine_par line needs ':integer' added to the end as well.


----------



## EvilDragon

Correct!


----------



## FrozenPlain

New version is out. The set_engine_par bug has been fixed, and there are 3 new features:

New built-in macro for incrementing a number over lines of code. This is executed after standard macros are substituted, so it can almost be considered a type of variable.
Create lists of lists. In other words, add single dimension arrays (of any size) to a list as elements.
New function for concatenating multiple arrays into one. Can also be used to just make one array equal another.
Have a look at the wiki for full details and examples.
https://github.com/nojanath/SublimeKSP/wiki/Added-Features


----------



## EvilDragon

FrozenPlain said:


> New built-in macro for incrementing a number over lines of code.



I'd suggest using TextPastry addon for Sublime instead. Much more featured.


----------



## FrozenPlain

TextPasty is great, but it is a different tool to the incrementer macro. The incrementer is executed after regular macros are built, so the generated numbers will behave to this new code rather than the uncompiled source. I should perhaps make that a bit clearer in the info.


----------



## derstefmitf

FrozenPlain said:


> New version is out. The set_engine_par bug has been fixed


Sweet, thanks for the quick update.


----------



## tomaslobosk

Using this stuff right now, amazing work Sam!


----------



## tack

Sam, I wanted to express my thanks for releasing these excellent updates. Some of the new features, notably (for me) arrays for UI controls and macro iteration, are very, very welcome.

I'm adding some additional UI features to a multiscript and I shudder when I contemplate how horrifying the code would look without it.

We can only hope that some day NI will fully abandon the Abomination That Is KSP™ but meanwhile I'm grateful we have the work done by Nils and yourself to make the task of developing in KSP moderately less insane.

Thanks!


----------



## FrozenPlain

I'm pleased that you find it useful. I am grateful for Nils' work as well, for he is the one who has really done the hard work for the compiler. 

I agree with your thoughts on KSP. There are a few big advantages to developing in Kontakt, but a clean and robust programming language is not one of them


----------



## EvilDragon

Well, I'd say that the limitations are what enables KSP to be extremely efficient and caters to its realtime use more than, say, Lua, or god forbid Python, which has quite a bit more overhead in comparison... 

There are pros and cons to everything, as always. Do we want a more flexible scripting language with more CPU overhead, or do we want a tight and spanking-fast and efficient execution with a bit arcane language quirks? The truth is, as they say, out there. :D


----------



## tack

EvilDragon said:


> Well, I'd say that the limitations are what enables KSP to be extremely efficient and caters to its realtime use more than, say, Lua, or god forbid Python, which has quite a bit more overhead in comparison...


I don't think this is a valid argument. It is perfectly possible to make extremely efficient languages that don't make you want to gouge out your eyes.

I would rather code in C. Hell, I would rather code in assembler. 

I'm not asking for high level Pythonic features. They'd be nice, sure, but I understand the need for the language to be compileable to very efficient native instructions.

But in my opinion the work Sam is doing, and Nils before him, underlines the flaw in your argument. It is perfectly possible to add high level constructs to ease the programmer burden while having zero impact to runtime performance. What I want in a language is consistency and completeness, and intuitiveness isn't all that much to ask for either, I think. 

ED I know you of all people know all the weird and broken nooks and crannies of KSP that would make everyone's lives so much easier if they were addressed, and yet would have no performance impact.

I know this because every time I run into one of them and google for it, there is always a thread with you on it.


----------



## tack

BTW, speaking of high level constructs, am I the only one surprised to learn about this cool syntactic sugar in Sam's SublimeKSP fork. (Edit: Ah, ED points out it was in Nils' original compiler)?



Code:


set_control_par(get_ui_id(control), CONTROL_PAR_HIDE, HIDE_WHOLE_CONTROL)
if get_control_par(get_ui_id(control), CONTROL_PAR_HIDE) = HIDE_WHOLE_CONTROL
    [...]
end if



... can be expressed as ...



Code:


control -> hide := HIDE_WHOLE_CONTROL
if control -> hide = HIDE_WHOLE_CONTROL
    [...]
end if


----------



## EvilDragon

You probably are. I'm using it for quite some time now... And yes, that sugar indeed IS sweet. (That's actually Nils' addition from several KScript versions back, not Sam's.)

I can kinda understand that if KSP had this natively, we wouldn't waste time compiling scripts (especially when working on huge projects, compiling can take quite some time)... I mean, from what I understand, native KSP functions are basically pretty much the same thing as Nils' KScript functions - they get inlined when the script is compiled to bytecode. This is why you can't use a function on init. 



And let me plant some dynamite here. I think some of you guys might appreciate the following Kontakt update quite some much because... reasons. He he he.


----------



## tack

EvilDragon said:


> I mean, from what I understand, native KSP functions are basically pretty much the same thing as Nils' KScript functions - they get inlined when the script is compiled to bytecode. This is why you can't use a function on init.


I daresay if KSP had actually supported proper functions within init, and elsewhere in general, performance would be _improved_. My little piddly multiscript has a huge pile of code duplication. I can only imagine how much duplication exists in a full blown instrument.

There is a nontrivial amount of CPU cache pollution caused by inlining large amounts of code. The cost of cache misses is much higher than the cost of a few extra instructions to push a return address on the stack and jmp.


----------



## tack

EvilDragon said:


> And let me plant some dynamite here. I think some of you guys might appreciate the following Kontakt update quite some much because... reasons. He he he.


Nice teaser. 2018 is going to be an amazing year!


----------



## EvilDragon

No I'm talking about the next K5 update. :D


----------



## tack

EvilDragon said:


> No I'm talking about the next K5 update. :D


Ah, interesting. Ok, I await patiently and optimistically.


----------



## d.healey

I get a variable not declared error when using a multi-dimensional array declared inside a family, is this a known limitation?


----------



## FrozenPlain

d.healey said:


> I get a variable not declared error when using a multi-dimensional array declared inside a family, is this a known limitation?


I found this bug too, I have fixed it, but I haven't got around to pushing the fix to the repo yet. It will be available soon!


----------



## d.healey

FrozenPlain said:


> I found this bug too, I have fixed it, but I haven't got around to pushing the fix to the repo yet. It will be available soon!


Cool


----------



## d.healey

Just got the update :D

Have a new possible bug for you. I can't use pers or read when declaring things inside a family. Also seems like the regular make_persistent command doesn't work for variables declared inside a family


----------



## FrozenPlain

Great! That was also fixed with this new version. Seems to be working for me 

Edit: Sorry, I missed your make_persistent() comment, the pers and read keywords should now work inside families. I think to use make_persistent() in a family you will need to add the dot prefixes, but I think this has always been the case?


----------



## d.healey

FrozenPlain said:


> Great! That was also fixed with this new version. Seems to be working for me
> 
> Edit: Sorry, I missed your make_persistent() comment, the pers and read keywords should now work inside families. I think to use make_persistent() in a family you will need to add the dot prefixes, but I think this has always been the case?


I'll give it another go and see what happens


----------



## d.healey

Still not working for me unfortunately


----------



## FrozenPlain

So the chicken does come before the egg 

Have you disabled the old compiler, perhaps it conflicting? In the command palette (ctrl+shift+p) use the commands enable and disable to disable Nils' original version called 'SublimeKSP' and enable this new version called 'KSP (Kontakt Script Processor)'.


----------



## tack

FrozenPlain said:


> So the chicken does come before the egg


This must be the problem, because it's plainly clear that the chicken egg came before the chicken.


----------



## d.healey

FrozenPlain said:


> So the chicken does come before the egg
> 
> Have you disabled the old compiler, perhaps it conflicting? In the command palette (ctrl+shift+p) use the commands enable and disable to disable Nils' original version called 'SublimeKSP' and enable this new version called 'KSP (Kontakt Script Processor)'.


I checked in the command palette but Nils' compiler has been completely removed, I've tried the latest update on two machines now with the same results.

Can anyone else test this out please?


----------



## FrozenPlain

d.healey said:


> I checked in the command palette but Nils' compiler has been completely removed, I've tried the latest update on two machines now with the same results.



I'm a bit stumped on what might be going on here. When I try your exact example it works fine (using the package control version of the compiler). My only other idea would be to download the folder as a zip directly from github, extract it, and add it to your sublime packages folder manually.


----------



## d.healey

FrozenPlain said:


> I'm a bit stumped on what might be going on here. When I try your exact example it works fine (using the package control version of the compiler). My only other idea would be to download the folder as a zip directly from github, extract it, and add it to your sublime packages folder manually.


I removed the package and reinstalled it via package control and it's all working now - weird


----------



## Andreas Moisa

Hi Guys, I like the Monokai color scheme better than the KSP color schemes but I would like to edit it so that constants and functions appear orange etc...any idea how to do that? Thanks!


----------



## FrozenPlain

Andreas Moisa said:


> Hi Guys, I like the Monokai color scheme better than the KSP color schemes but I would like to edit it so that constants and functions appear orange etc...any idea how to do that? Thanks!


Actually, I'm not sure how the default colour schemes are accessed. What you might be able to do is google for sublime monokai colour scheme, perhaps someone else extracted the scheme before. If you can find one to download, you can then just open the .tmLanguage file and change the colours in it.


----------



## Andreas Moisa

I somehow managed to get something usable by extracting the theme and mixing it with the KSP color scheme to some degree If anyone's interested, pm me.


----------



## Kerranswell

Hi, guys!
First of all, thank you for this awesome additions!
Everything was cool before I included Math library
Compiler errors on multidimensional arrays:







Is there some kind of a conflict?
Also, using array in a family causes a bit another message:






I use Sublime Text 3 and latest downloaded plugin


----------



## d.healey

This sounds similar to the problem I was experiencing. Remove SublimeKSP completely and then reinstall it via package control.

Feature request: It would be good if the iterate macro feature could support macros that take multiple parameters.


----------



## Kerranswell

d.healey said:


> This sounds similar to the problem I was experiencing. Remove SublimeKSP completely and then reinstall it via package control.


I don't think so. Today I installed on the different computer sublime text and SublimeKSP package via package control, as instructed in manual. Nothing changed. As soon as I remove import of Math library everything starts working fine.


----------



## d.healey

Does it work if you remove the "as Math" part from the import statement?


----------



## Kerranswell

d.healey said:


> Does it work if you remove the "as Math" part from the import statement?


No, this doesn't change anything except that Math library gives its internal error.
But I fixed the problem! If I put Math import after "on init .... end on" block it starts working!


----------



## d.healey

Kerranswell said:


> No, this doesn't change anything except that Math library gives its internal error.
> But I fixed the problem! If I put Math import after "on init .... end on" block it starts working!


Weird but good to know


----------



## d.healey

define constants don't work if they are created inside a family - well they work if you don't reference them with the family name.


----------



## FrozenPlain

d.healey said:


> define constants don't work if they are created inside a family - well they work if you don't reference them with the family name.



Ah yes, this is sort of intentional. Define constants aren't really part of the program, they have no concept of the structure or anything, they're just text substitutions that happen before the script is even read. I think perhaps that making them pretend to follow the script's structure might add confusion to what the define constant actually is. People might start trying to declare them in macros for example.


----------



## neblix

FrozenPlain said:


> People might start trying to declare them in macros for example.



I do them in macros, but for specific reasons. I encapsulate a lot of code, and different frameworks and such sometimes rely on an order of declaration that's not always constant. Instead of doing them all manually via copy and paste every time we start a new project, it's nice to store them inside of the "plug and play" macros. So that way, different abstractions can be coherently pieced into any new sample library project without a lot of tedium of copy and pasting past code and re-adapting it to something new.

It's especially true when more than one script tab will share framework code. For instance, for an engine right now, I use a mathematical expression to derive a "number of PGS keys" as a define constant (that way it can be used in iterate_macro(), to dynamically generate the keys, generate functions for updating them, etc.). Since each script that's talking to each other needs to know this number, it's really easy to just have it be part of the common init macros that both scripts call.

They do work, especially as intended, so no problems so far with doing it. I agree though that conceptually it doesn't make a lot of sense (they're preprocessor defines, should normally be before any real code); I do it out of necessity for highly tuned maintenance more than anything else.


----------



## FrozenPlain

neblix said:


> Since each script that's talking to each other needs to know this number, it's really easy to just have it be part of the common init macros that both scripts call.



If it improves readability then this is a worthwhile thing to do. But, whether or not the macro is called doesn't matter, the define will still exist.


----------



## d.healey

What about instead of get_ui_id(switch_name) you could do switch_name -> ID?


----------



## d.healey

More feature requests 

Single line if statements for something like -


Code:


if ($i < 0) $i := 0 end if


Multi-dimensional PGS keys


----------



## FrozenPlain

Some cool suggestions David!


----------



## Kerranswell

If author accepts suggestions, for me, the most cool thing would be:
1. As minimum, arrays of families.
2. As maximum, objects, something like like:


Code:


object OCat
    declare legCount
    declare cuteLevel
    declare @homePlanet
end object

declare object Ozzy of OCat

Ozzy.legCount := 3
Ozzy.cuteLevel := -100
[email protected] := "Hell"

declare object Alice of OCat

Alice.legCount := 10
Alice.cuteLevel := 87
[email protected] := "Venus"

declare cats[10] of OCat
for i:= 0 to num_elements(cats)-1
    cats[i].legCount := (i-1)*Math.sin(i+3) / 10000
    cats[i].cuteLevel := 100-i
end for


3. Super cool: classes with methods.



Code:


class CCat
    declare legCount
    declare cuteLevel
    declare @homePlanet

    function killAllHumans(crueltyLevel)
    if (this.cuteLevel > 0)
        this.cuteLevel := -1 * this.cuteLevel
    end if
        // ... cencored (18+) ...
    end function
end class

declare cat of CCat
cat := new CCat()
cat.cuteLevel := 100500
cat.killAllHumans(cat.cuteLevel * 10)


This code, if I get it right, should compile into something like this:



Code:


declare $CCat_cat_legCount
declare $CCat_cat_cuteLevel
declare @CCat_cat_homePlanet

$CCat_cat_cuteLevel := 100500
declare $CCat_cat_killAllHumans_crueltyLevel
$CCat_cat_killAllHumans_crueltyLevel := $CCat_cat_cuteLevel * 10
if ($CCat_cat_cuteLevel > 0)
    $CCat_cat_cuteLevel := -1 * $CCat_cat_cuteLevel
end if

// ...


Is one of these suggestions possible to implement?


----------



## Kerranswell

Another strange thing with Math library:
Pseudo callback on pgs_changed calls error






But if to remove "Math." it works:
on_pgs_changed
message('test')
end_on


----------



## d.healey

I never use the "as" when importing libraries because it seems to create all sorts of strange problems


----------



## FrozenPlain

I'm not sure about the math library, as David suggested using 'as' does seem to complicate things. If you are using Kontakt 5.5, the PGS stuff in the math library can probably be moved to the persistence_changed callback.



Kerranswell said:


> Is one of these suggestions possible to implement?


You're in luck! I've actually already made this feature a while ago but haven't had a chance to test it properly yet. Rather than objects or classes, I decided to call them structs but they are the same as you are suggesting. They don't accept functions, only variables or other struct declarations. They can be made into arrays.

They need to be properly put through their paces before they are part of the main package. If you want to test it as well, you can download it on my github fork: https://github.com/SamWindell/SublimeKSP. Have a look at the StructExample file in the ksp_compiler folder for an example. Because this is a test version, if you have any issues shoot me an email rather than post here. [email protected]


----------



## Kerranswell

FrozenPlain, that is really good news! I will definitely try and test it, thanks a lot!


----------



## neblix

FrozenPlain said:


> If it improves readability then this is a worthwhile thing to do. But, whether or not the macro is called doesn't matter, the define will still exist.


Interesting, thanks!


----------



## Kerranswell

FrozenPlain said:


> They need to be properly put through their paces before they are part of the main package. If you want to test it as well, you can download it on my github fork: https://github.com/SamWindell/SublimeKSP. Have a look at the StructExample file in the ksp_compiler folder for an example.



Sorry, I'm not sure how to install these new ksp compiler updates into sublime without sublime-package. Do I need to build package myself or something?


----------



## FrozenPlain

Kerranswell said:


> Sorry, I'm not sure how to install these new ksp compiler updates into sublime without sublime-package. Do I need to build package myself or something?



It will have to be done the old fashioned way! Download and extract the zip to your sublime packages folder and use the command palette to disable any other versions of the compiler, then restart sublime. This is just a test version not an official release, so it may change. It's there just in case you wanted to try it out to give suggestions/bug reports.


----------



## Kerranswell

FrozenPlain said:


> It will have to be done the old fashioned way! Download and extract the zip to your sublime packages folder and use the command palette to disable any other versions of the compiler, then restart sublime. This is just a test version not an official release, so it may change. It's there just in case you wanted to try it out to give suggestions/bug reports.


Done! Works fine)


----------



## d.healey

Is there a changelog available to see how things have progressed?


----------



## FrozenPlain

d.healey said:


> Is there a changelog available to see how things have progressed?


Not exactly, but perhaps the history of pull requests serves a similar purpose at the moment https://github.com/nojanath/SublimeKSP/pulls?q=is:pr+is:closed


----------



## d.healey

Thanks

Here's a video I've made showing the install procedure using package control


----------



## FrozenPlain

New version: 1.4. See the revamped wiki page for more details https://github.com/nojanath/SublimeKSP/wiki/Added-Features

Big additions:
- Defines can now accept arguments to act like single line macros (and other improvements).
- Structs; a way of grouping together variables into a structure.
- Preprocessor section of the compiler is now much faster.
- New colour scheme "Monokai KSP" thanks to Davide Magni.

Other changes:
- Defines no longer require ## symbols for literal text substitutions - this is now handled automatically.
- Multidimensional arrays can now be initialised with a list (in the same way you would a single dim array).
- All elements in a string array can be initialised by just assigning it to a single string.
- 'define literals' are deprecated as the newly enhanced define can handle this.
- Better support for declaring variables inside families.
- Fix Kontakt constant NI_CB_TYPE_ASYNC_COMPLETE.
- Behind the scenes, activate_logger() now assigns the save_array() function to variable LOGGER_ASYNC_ID so that it can be filtered out of the async callback if required.
- Capitalise text in KSP tools menu to be more consistent with the rest of Sublime.


----------



## tomaslobosk

I'm having problems with assigning variables on the same line as declaration with 1.4
Can updates be optional in the future? I'm in the middle of a project right now :(
Can I get the previous version?
Thanks!


----------



## FrozenPlain

tomaslobosk said:


> I'm having problems with assigning variables on the same line as declaration with 1.4



You can go here and download the last version as a zip https://github.com/nojanath/SublimeKSP/releases

Then extract it to your sublime packages folder, and use the command palette (ctrl+shift+p) to disable any other versions you have active.

What is the error you were getting? I will try and fix this as soon as possible.


----------



## andreasOL

tomaslobosk said:


> I'm having problems with assigning variables on the same line as declaration with 1.4
> Can updates be optional in the future? I'm in the middle of a project right now :(
> Can I get the previous version?
> Thanks!



Is this an assignment on the same line with a "declare read"? Breaks for me, too, but that got me thinking.

The sequence of generated statements would be crucial in this case, i.e. the read_persistence_var must come after the assignment, as the assignment makes only sense as default value which then can be overwritten if the persistent state of the patch already contains a saved value for the variable (otherwise it would make no sense to make this variable persistent anyway if it gets assigned a value after the read_persistent_var).

Andreas


----------



## d.healey

Compiler doesn't recognise $KEY_COLOR_DEFAULT constant.


----------



## Kerranswell

Having problem with ui controls in array of structs



Code:


on init
    struct _p
        declare ui_switch s
    end struct

    declare &_p p[2]
  
end on

on ui_control (p[0].s)
    p[0].s := 1
end on


Gives error "p[0].s has not been declared"


----------



## andreasOL

Kerranswell said:


> Having problem with ui controls in array of structs
> 
> 
> 
> Code:
> 
> 
> on init
> struct _p
> declare ui_switch s
> end struct
> 
> declare &_p p[2]
> 
> end on
> 
> on ui_control (p[0].s)
> p[0].s := 1
> end on
> 
> 
> Gives error "p[0].s has not been declared"



If you compile this without the ui callback you get the code



Code:


{ Compiled on Fri Jul 29 14:43:26 2016 }
on init
declare %p__s[2]
declare ui_switch $p__s0
%p__s[0] := get_ui_id($p__s0)
declare ui_switch $p__s1
%p__s[1] := get_ui_id($p__s1)
end on


This in conjunction with the comment I found in the wiki under Structs means that you have to use the native variable name p.s0 (which gets expanded to $p__s0 by the compiler which is general and old behaviour for "." notation) for the callback, i.e.



Code:


on ui_control (p.s0)
   p.s0 := 1
  p[0].s->value := 1
end on


I also noted the two ways to set the value of the switch, either by using p.s0 or by using the ui_id which you get with p[0].s and set its "value" (p[0].s is just the ui_id which you would overwrite with your original assignment).


----------



## Kerranswell

andreasOL said:


> If you compile this without the ui callback you get the code
> 
> 
> 
> Code:
> 
> 
> { Compiled on Fri Jul 29 14:43:26 2016 }
> on init
> declare %p__s[2]
> declare ui_switch $p__s0
> %p__s[0] := get_ui_id($p__s0)
> declare ui_switch $p__s1
> %p__s[1] := get_ui_id($p__s1)
> end on
> 
> 
> This in conjunction with the comment I found in the wiki under Structs means that you have to use the native variable name p.s0 (which gets expanded to $p__s0 by the compiler which is general and old behaviour for "." notation) for the callback, i.e.
> 
> 
> 
> Code:
> 
> 
> on ui_control (p.s0)
> p.s0 := 1
> p[0].s->value := 1
> end on
> 
> 
> I also noted the two ways to set the value of the switch, either by using p.s0 or by using the ui_id which you get with p[0].s and set its "value" (p[0].s is just the ui_id which you would overwrite with your original assignment).



Indeed, thank you


----------



## FrozenPlain

andreasOL said:


> Is this an assignment on the same line with a "declare read"? Breaks for me, too, but that got me thinking.


Do you have an example of this please?


----------



## d.healey

New issue with iterate_macro and defines


----------



## FrozenPlain

d.healey said:


> New issue with iterate_macro and defines


Not a new issue! Don't use symbol prefixes for defines.


----------



## d.healey

FrozenPlain said:


> Not a new issue! Don't use symbol prefixes for defines.


Oh yea, duh, I knew that


----------



## tomaslobosk

andreasOL said:


> Is this an assignment on the same line with a "declare read"? Breaks for me, too, but that got me thinking.
> Andreas



yes, declare pers... I don't use read anymore, since on persistence_changed is awesome


----------



## FrozenPlain

Tiny update: 1.4.2.

Fix bug with initialising a pers/read variable
Macros now can have arguments with dots in them
Fix highlighting for function/macro arguments with dots in them
Fix define num args bug, fix define incorrect error message line
Add KEY_COLOR_DEFAULT
I think the compiler is pretty stable now. I'm not intending to do any more additions for a while (other than little bug fixes). BTW, the best place to post bug reports is the issues section on the GitHub https://github.com/nojanath/SublimeKSP/issues.


----------



## d.healey

FrozenPlain said:


> Tiny update: 1.4.2.
> 
> Fix bug with initialising a pers/read variable
> Macros now can have arguments with dots in them
> Fix highlighting for function/macro arguments with dots in them
> Fix define num args bug, fix define incorrect error message line
> Add KEY_COLOR_DEFAULT
> I think the compiler is pretty stable now. I'm not intending to do any more additions for a while (other than little bug fixes). BTW, the best place to post bug reports is the issues section on the GitHub https://github.com/nojanath/SublimeKSP/issues.


All your hard work is very greatly appreciated!


----------



## derstefmitf

Hi, thanks for the update. Just a quick question, do you guys also have problems with the Cmd+K shortcut on Mac? Since I installed the new SublimeKSP package via PackageControl, I always need to press the shortcut twice to get the compiler going.


----------



## d.healey

FrozenPlain said:


> I'm not intending to do any more additions for a while (other than little bug fixes).


Just as K5.6 in announced - https://www.native-instruments.com/en/products/komplete/samplers/kontakt-5/whats-new/


----------



## derstefmitf

The additions sound awesome


----------



## FrozenPlain

d.healey said:


> Just as K5.6 in announced - https://www.native-instruments.com/en/products/komplete/samplers/kontakt-5/whats-new/


Very interesting! As far as the compiler goes I'm sure macros and syntax shortcuts will still work and be relevant. However the addition of the new floating point numbers will complicate things. If we now have floating point literals in our scripts (e.g. 10.584), the compiler will not work without some changes to the parser to accept these. What I've been doing with the preprocessor is quite different to Nils's parser, so I'm not sure if I'm the right man for the job.


----------



## EvilDragon

I have an alpha version of original SublimeKSP that Nils sent me during K6 alpha period that contains support for all the new math stuff, so you might want to check that out... But I'm pretty sure Nils is gonna be on top of the game and sooner or latter update SublimeKSP officially to support new stuff in K5.6.


----------



## FrozenPlain

EvilDragon said:


> I have an alpha version of original SublimeKSP that Nils sent me during K6 alpha period that contains support for all the new math stuff, so you might want to check that out... But I'm pretty sure Nils is gonna be on top of the game and sooner or latter update SublimeKSP officially to support new stuff in K5.6.


Amazing!


----------



## tomaslobosk

Fantastic work indeed, thanks for the updates Sam


----------



## derstefmitf

Hi,

could it be possible that ALL_GROUPS does not work anymore with the KSP plugin? I have 3 groups in my nki but ALL_GROUPS only returns -1.

Thanks.


----------



## EvilDragon

ALL_GROUPS internal value *is* -1...


----------



## d.healey

derstefmitf said:


> Hi,
> 
> could it be possible that ALL_GROUPS does not work anymore with the KSP plugin? I have 3 groups in my nki but ALL_GROUPS only returns -1.
> 
> Thanks.


Could it be that you want to use $NUM_GROUPS?


----------



## derstefmitf

Oh man, seems the sun has already overcooked my brain today. Thanks!


----------



## neblix

EvilDragon said:


> I have an alpha version of original SublimeKSP that Nils sent me during K6 alpha period that contains support for all the new math stuff, so you might want to check that out... But I'm pretty sure Nils is gonna be on top of the game and sooner or latter update SublimeKSP officially to support new stuff in K5.6.



Is Nils going to update from his last version of SublimeKSP or is he going to get on the open source train and build from what these guys are doing in the public GitHub version? A lot of our scripting techniques right now rely very heavily on the new features, I would be very, very upset if we had to choose to forego scripting for 5.6 to retain those abilities (or lose those abilities to go to 5.6).

The idea of two competing SublimeKSP's seems superfluous not to mention, makes our lives harder... I really really hope I'm just overreacting.


----------



## EvilDragon

That question can only be answered by Nils himself... I think he'll continue updating his build, because from his perspective that's what makes the most sense and is probably least time consuming...

We all know Nils is a super-busy guy, so he'd probably go with the least time-intensive method of updating SublimeKSP. Then on top of that OP can update it with his compiler updates...


Also, there's no competition when both are free to use.


----------



## FrozenPlain

The preprocessor additions are pretty isolated. So if Nils does not use this version, I will hopefully just merge his version into the github repo.


----------



## neblix

EvilDragon said:


> Then on top of that OP can update it with his compiler updates...
> 
> Also, there's no competition when both are free to use.



Okay, sure. I didn't know how difficult merging them would be.

And when I said competing, I didn't mean for business, but rather just having two different ones that developers have to pick between:



FrozenPlain said:


> The preprocessor additions are pretty isolated. So if Nils does not use this version, I will hopefully just merge his version into the github repo.



That's good to hear. I didn't know how inter-connected it was, and how far the parser was from the new syntax features.


----------



## derstefmitf

Hi, is there any update planned for the KSP plugin including the new syntax for 5.6? Is anyone already using the new features like real variables?


----------



## d.healey

derstefmitf said:


> Hi, is there any update planned for the KSP plugin including the new syntax for 5.6? Is anyone already using the new features like real variables?


Scroll up this page to posts #106 and #107


----------



## FrozenPlain

I have merged Nils's version into my fork with support for 5.6, but haven't had a chance to test it yet. If anyone gets a chance to have a look that everything is working, I'm sure we can then push this to the package control version. https://github.com/nojanath/SublimeKSP/issues/40

You can download this test version as a zip from here: https://github.com/SamWindell/SublimeKSP/tree/5.6_Support


----------



## Lindon

FrozenPlain said:


> I have merged Nils's version into my fork with support for 5.6, but haven't had a chance to test it yet. If anyone gets a chance to have a look that everything is working, I'm sure we can then push this to the package control version. https://github.com/nojanath/SublimeKSP/issues/40
> 
> You can download this test version as a zip from here: https://github.com/SamWindell/SublimeKSP/tree/5.6_Support




..any progress on this?


----------



## EvilDragon

That 5.6 support fork works just fine over here... (after fixing builtins data and syntax just a liiiitle bit, see my posts here: https://github.com/nojanath/SublimeKSP/issues/40)


----------



## Lindon

..so can we promote this to package control then? -- and when I say "we"......


----------



## ScoringFilm

How do you install the 5.6 support files (Win 10)?


----------



## FrozenPlain

New version with support for 5.6 is on package control now. This is an automatic update.


----------



## Lindon

Well done!


----------



## olmerk

Using Sublime 3 I am a bit lost with what exact versions of KSP packages I installed previously. So now in the menu which allows to choose programming language I see three KSP names. And I can't tell which is which. Where inside Sublime can I see the author (Nils Liberg, SamWindell or nojanath) and the version of the package?


----------



## d.healey

olmerk said:


> Using Sublime 3 I am a bit lost with what exact versions of KSP packages I installed previously. So now in the menu which allows to choose programming language I see three KSP names. And I can't tell which is which. Where inside Sublime can I see the author (Nils Liberg, SamWindell or nojanath) and the version of the package?


Just remove all of them and install the one you want to use


----------



## olmerk

d.healey said:


> Just remove all of them and install the one you want to use



Then which one is more preferable? Is there any comparison list? Which forked from which?
For example SamWindell SublimeKSP forked from nojanath SublimeKSP which in its turn forked from Nils' official 1.1 plugin (as stated at GitHub). However Nils has released version 1.11 since then. So I'm a bit confused which one to use...


----------



## d.healey

olmerk said:


> Then which one is more preferable? Is there any comparison list? Which forked from which?
> For example SamWindell SublimeKSP forked from nojanath SublimeKSP which in its turn forked from Nils' official 1.1 plugin (as stated at GitHub). However Nils has released version 1.11 since then. So I'm a bit confused which one to use...


Go to the first post of this thread and follow the instructions


----------



## olmerk

First post gives the instructions on where to download and how to install nojanath version. 
Since then I see that SamWindell fork has been release with Kontakt 5.6 support. Is that the latest release I should use?


----------



## EvilDragon

Yes.

Bear in mind there's no support yet for ui_xy as introduced in 5.6.5. There seem to be some deeper changes in the compiler necessary. I've pinged Nils.


----------



## olmerk

Ok. I've deleted all the packages. Downloaded this one: https://github.com/SamWindell/SublimeKSP/tree/5.6_Support

Then just unpacked it to c:\Users\<user name>\AppData\Roaming\Sublime Text 3\Packages\, restarted Sublime, choose KSP in the list of languages. Good, but I couldn't launch the compilation, in Tools menu everything concerning KSP was greyed out. See the pic.

What can be wrong?

P.s. Installing the package through Package Control was just fine - compilation did work, but I think with this method I'm getting not the recent version by nojanath, right?


----------



## FrozenPlain

Hey olmerk, you can use the nojanath version just fine, it is just as up to date as my fork. Confusingly the readme hasn't been updated to show that it supports kontakt 5.6 and Nils' 1.11 compiler. Let me see if I can update that now.


----------



## geronimo

Sorry but I find nothing by following the instructions: "Type “KSP” or "Kontakt" _


----------



## olmerk

geronimo said:


> Sorry but I find nothing by following the instructions: "Type “KSP” or "Kontakt" _



Maybe you should get the latest Package Control? 
https://packagecontrol.io/installation


----------



## geronimo

Many thanks; It's arranged after a mistake of myself .


----------



## olmerk

I've found that autocomplete doesn't work here for me at all. As I start typing an existing variable, autocomplete opens, I see that variable in the list and select it, but when I press Enter or Tab the whole thing I've been typing just disappears. Any ideas what could be wrong?


----------



## EvilDragon

If you use the preceeding $, % or ! for the variable, that will happen. Don't use it and autocomplete works fine


----------



## olmerk

EvilDragon said:


> If you use the preceeding $, % or ! for the variable, that will happen. Don't use it and autocomplete works fine



Yes, indeed autocomplete works if I declare variables without prefixes $, %, etc. But it's hard to work not typing them, code's readability really decreases for me. Isn't there a work-around for that in Sublime under-hood settings?


----------



## EvilDragon

I'm not aware of any, and I don't think it's related to SublimeKSP options, this might be somewhere deep in SublimeKSP compiler...

In any case I don't think readability decreases, in fact it's the opposite for me. You know that if [ comes after a variable name it's an array. Etc.


----------



## derstefmitf

I try to make use of the added multidimensional array feature. So when I set up an array like this: 



Code:


declare up_trans_groups[12,12]


How do I assign a value only to the first index of the second dimension? I want to fill the array like this:



Code:


for i:=0 to play.up_trans_groups.SIZE_D1-1
    play.up_trans_groups[1,0] := find_group("up1_p")+i
    play.up_trans_groups[0,1] := find_group("up1_f")+i
end for


So I basically want to fill the first dimension with the piano transition groups and the second dimension with the forte groups.


----------



## derstefmitf

Oh, the loop should be this of course:



Code:


for i:=0 to play.up_trans_groups.SIZE_D1-1
     play.up_trans_groups[0+i,0] := find_group("up1_p")+i
     play.up_trans_groups[0,0+i] := find_group("up1_f")+i
end for


*[SOLVED] *Never mind guys, I got it


----------



## neblix

EvilDragon said:


> If you use the preceeding $, % or ! for the variable, that will happen. Don't use it and autocomplete works fine



While we do omit that stuff in our code style it IS a little absurd that someone need to modify a perfectly valid convention (using the prefix tokens of the language because... that's what the language looks like) in their coding style because of a bug in the SublimeKSP plugin. That part of the SublimeKSP plugin should really be fixed.


----------



## RustyPine

Any word on the progress of the 5.6.5 (ui_xy) additions?


----------



## EvilDragon

I got in touch with Nils and Sam, they both provided some input (since I had trouble getting it to work myself, using FrozenPlain's fork) and I have it working locally here. In due time, Nils will post update for vanilla SublimeKSP supporting XY pad functionality, and FrozenPlain's fork is already updated on GitHub: https://github.com/SamWindell/SublimeKSP


----------



## RustyPine

Ah fantastic! Also are real numbers not supported yet in task functions (taskfunc) as parameters?


----------



## EvilDragon

Very likely, taskfuncs are still integer only. Easy to check by opening taskfunc.py. It's just a few macros and functions, and the main buffer is just a regular int array (p[MEM_SIZE]).


----------



## RustyPine

Perhaps I'm being quite daft, but do the new commits for ui_xy in https://github.com/nojanath/SublimeKSP/ actually fully implement support or just allow the identifier to pass through compilation?

Since ui_xy requires array syntax for the number of nodes (eg declare ui_xy ?xyPad[4] will create a pad with 2 nodes according to the KSP Reference Manual) it should have similar parser treatment to ui_table. Looking through the compiler code it doesn't look like it, and when I compile I keep getting UI array output:



Code:


  declare ui_xy xyPad[4]


when compiled becomes



Code:


  declare %xyPad[4]
  declare ui_xy $xyPad0
  %xyPad[0] := get_ui_id($xyPad0)
  declare ui_xy $xyPad1
  %xyPad[1] := get_ui_id($xyPad1)
  declare ui_xy $xyPad2
  %xyPad[2] := get_ui_id($xyPad2)
  declare ui_xy $xyPad3
  %xyPad[3] := get_ui_id($xyPad3)


----------



## EvilDragon

You need that ? prefix there when declaring the pad. Compiler can't know (at least not in the state that it is right now) if what you want to create is an int or a real array. Thankfully you only need that prefix when declaring, but not when referencing the variable later in the code (similarly to string array and string var declarations).


----------



## RustyPine

switching it to


Code:


declare ui_xy ?xyPad[4]

produces the exact same thing. Could you provide a mini example? Many thanks!


----------



## EvilDragon

Works here.



Code:


on init
    declare ui_xy ?xyPad[4]
end on


compiles to:



Code:


{ Compiled on Wed Jan 11 23:23:44 2017 }
on init
declare ui_xy ?xyPad[4]
end on


----------



## RustyPine

hmm, I ran a clean install of Sublime Text 3, re-cloned SublimeKSP (https://github.com/nojanath/SublimeKSP/) in ~/Library/Application Support/Sublime Text 3/Packages/ & it still produces the wrong output :



Code:


on init
    declare ui_xy ?xyPad[4]
end on


compiles to



Code:


{ Compiled on Wed Jan 11 15:07:52 2017 }
on init
  declare $concat_it
  declare $concat_offset
  declare $string_it
  declare $list_it
  declare %xyPad[4]
  declare ui_xy $xyPad0
  %xyPad[0] := get_ui_id($xyPad0)
  declare ui_xy $xyPad1
  %xyPad[1] := get_ui_id($xyPad1)
  declare ui_xy $xyPad2
  %xyPad[2] := get_ui_id($xyPad2)
  declare ui_xy $xyPad3
  %xyPad[3] := get_ui_id($xyPad3)
end on


I'm running OSX 10.11.6

KSP settings are:
- extra syntax checks
- signal error on empty if/case statements


----------



## EvilDragon

Not sure. I am using what Sam sent me... https://github.com/SamWindell/SublimeKSP/


W10 here but I don't think that matters at all.


----------



## RustyPine

Strange. I'm using build 3126 for Sublime Text 3 & Python 2.7.10.

Any other Mac users have any luck? I'm going to test this out on Windows once I get my VM working again.


----------



## RustyPine

Just tested on Win10 and it didn't work for me again.


----------



## FrozenPlain

There does seem to be something funny going on here when putting the [] at the end of a ui_xy declaration. I will take a look tomorrow!


----------



## EvilDragon

So why does it work over here :D


----------



## Lindon

EvilDragon said:


> So why does it work over here :D


..because you're special, we all know that....


----------



## FrozenPlain

EvilDragon said:


> So why does it work over here :D


It was working earlier for me too, there's something spooky going on somewhere...

Anyway I believe I have fixed it. If you want an array of xy pads then it follows the pattern of the ui_table arrays. Let me know if it is working for you: https://github.com/SamWindell/SublimeKSP


----------



## EvilDragon

Seems fine here.

Would be great if it actually recognized the ui_xy keyword too, so that we don't necessarily need to use ? during declaration. With your latest fix, if we just do declare ui_xy xy[4], it will do what RustyPine initially reported, still...


----------



## EvilDragon

I got a new bug for ya, though. Seems like the compiler doesn't want to compile at all if I try to declare a real constant. This doesn't work, throws a "variable not declared" error:



Code:


on init
    declare const ~PI := ~NI_MATH_PI
end on


----------



## polypx

I'm getting strange behaviour with this latest version (Sublime on Mac). If I launch a .ksp file, first of all it's not recognized as such and it now gives the error "Error loading syntax file" with a pointer to the KSP.sublime-syntax file itself.

So I then manually load that file into Sublime, it does of course load, and close it again. Now my KSP file will compile (the controls are there, although the syntax highlighting is not).


----------



## FrozenPlain

EvilDragon said:


> Would be great if it actually recognized the ui_xy keyword too, so that we don't necessarily need to use ? during declaration. With your latest fix, if we just do declare ui_xy xy[4], it will do what RustyPine initially reported, still...


That's a good point, I will see what Nils does first if he releases a new version before doing anything, as this isn't related to the preprocessor.



EvilDragon said:


> I got a new bug for ya, though. Seems like the compiler doesn't want to compile at all if I try to declare a real constant. This doesn't work, throws a "variable not declared" error:


I think with this one it's deeper in the compiler, probably better off if Nils can address it. Unless of course this is a result of my changes?



polypx said:


> I'm getting strange behaviour with this latest version (Sublime on Mac). If I launch a .ksp file, first of all it's not recognized as such and it now gives the error "Error loading syntax file" with a pointer to the KSP.sublime-syntax file itself.
> 
> So I then manually load that file into Sublime, it does of course load, and close it again. Now my KSP file will compile (the controls are there, although the syntax highlighting is not).


Have you downloaded the package manually from zip this time? This could be to do with the folder names begin slightly different in the package control version to the manual version.


----------



## polypx

Yep. I remove all versions first. Although I didn't have the Package Control installed version at this point. Make sure there's no KSP there at all, and then unzip that folder and restart. It does "kind of work", except for that error and the lack of syntax highlighting.

If I remove the new one and install Package KSP version from Nils, I get the syntax highlighting back, but obviously no ?xy_pad compilation...


----------



## EvilDragon

FrozenPlain said:


> I think with this one it's deeper in the compiler, probably better off if Nils can address it. Unless of course this is a result of my changes?



Hmmm, looks like it's there in vanilla SublimeKSP as well... doesn't happen when Extra syntax checks is disabled... Gotta ping Nils, then, I guess.


----------



## Lindon

polypx said:


> Yep. I remove all versions first. Although I didn't have the Package Control installed version at this point. Make sure there's no KSP there at all, and then unzip that folder and restart. It does "kind of work", except for that error and the lack of syntax highlighting.
> 
> If I remove the new one and install Package KSP version from Nils, I get the syntax highlighting back, but obviously no ?xy_pad compilation...


Yeah I'm losing syntax highlighting too, or at least some of it - CONSTANTS for a start


----------



## FrozenPlain

polypx said:


> If I launch a .ksp file, first of all it's not recognized as such and it now gives the error "Error loading syntax file" with a pointer to the KSP.sublime-syntax file itself.



I have this same problem, but it is my understanding that it cannot be fixed by the package, it is a bug in Sublime Text. As a workaround you can just use ctrl+shift+p or cmd+shit+p and type the command to set the syntax to ksp.

My guess here is that the package control version has a different name, it is called "KSP (Kontakt Script Processor)" while if you download it manually the package is called "SublimeKSP". Sublime text caches the location of the syntax file, if this cached location is in in the other version that you have disabled it will through an error. I think there is a way to reset this cache. Someone mentions the .sublime_session file in here: https://github.com/joeferraro/MavensMate-SublimeText/issues/292

I haven't tried myself, but I wonder if changing the name of the folder from SublimeKSP to "KSP (Kontakt Script Processor)" would fix this.



Lindon said:


> Yeah I'm losing syntax highlighting too, or at least some of it - CONSTANTS for a start


Very strange, can you send a screenshot? I can't seem to reproduce this.


----------



## polypx

Right, thanks Sam! It seems the Local/Session.sublime_session file always points the syntax to "KSP (Kontakt Script Processor)", so by renaming the new folder that, restarting and resetting the syntax and scheme, I finally got it to stick. I'm on a Mac, so it might be interesting to see if anyone else on Mac finds the same bug/fix. 

I have completely removed the original KSP Install Package version, and always go into sublime-keymap and replace all the super-k to super-l, since super-k is a conflict in the Mac version of Sublime Text.

cheers, Dan


----------



## Lindon

FrozenPlain said:


> I have this same problem, but it is my understanding that it cannot be fixed by the package, it is a bug in Sublime Text. As a workaround you can just use ctrl+shift+p or cmd+shit+p and type the command to set the syntax to ksp.
> 
> My guess here is that the package control version has a different name, it is called "KSP (Kontakt Script Processor)" while if you download it manually the package is called "SublimeKSP". Sublime text caches the location of the syntax file, if this cached location is in in the other version that you have disabled it will through an error. I think there is a way to reset this cache. Someone mentions the .sublime_session file in here: https://github.com/joeferraro/MavensMate-SublimeText/issues/292
> 
> I haven't tried myself, but I wonder if changing the name of the folder from SublimeKSP to "KSP (Kontakt Script Processor)" would fix this.
> 
> 
> Very strange, can you send a screenshot? I can't seem to reproduce this.



as you see most syntax is working ok, but the NI Constants (like $CONTROL_PAR_KEY_CONTROL dont get any syntax love....


----------



## EvilDragon

That works fine here... Looks like you're not using the color theme that comes with SublimeKSP (the dark one or the bright one, I prefer the dark one, I tweaked it a bit), but the default Soda Monokai, which doesn't have KSP specific colors defined.


----------



## RustyPine

Ah, fantastic, thanks Sam!

Yes so far everything is working fine.


----------



## derstefmitf

Hi guys,
when I want to install sublimeKSP from package control, I am unable to find it in the repository. Is something wrong with my package control or was the package removed? Thanks.


----------



## EvilDragon

Not a problem here...


----------



## derstefmitf

Ok, so I'll try to reinstall package control.


----------



## noisyblocks

Is there a manual for SublimeKSP? I saw the wiki but it's pretty barebones and Nils' page seems more about basic KSP principles.

I'm specifically asking because I had seen the "Added features" page on Github: ui declarations using macros is excellent but I'm not following the logic of everything I see in their example loop. E.g.:



Code:


define NUM_CONTROLS := 40
declare pers ui_slider volumeSliders[NUM_CONTROLS] (0, 100)
declare ui_table tables[40] [100](2, 4, 100)
declare ui_switch switches[2, 2]
_switches0 -> value := 1 // Access the variable name of a multi-dim UI array with an underscore




Code:


define NUM_LAYERS := 4
define NUM_CONTROLS := 4
on init
   // Create all of the UI in one command. The total number of controls created
   // is simply equal to NUM_LAYERS * NUM_CONTROLS.
   declare pers ui_slider sliders[NUM_LAYERS, NUM_CONTROLS] (0, 100)
   declare i
   declare j
   for i := 0 to NUM_LAYERS - 1
       for j := 0 to NUM_CONTROLS - 1
           set_bounds(sliders[i, j], 10 + 40 * i, 10)
       end for
   end for
end on
function hideAllSliders()
   // Here is an example of how you might want to use the single dimension version
   // to effect all the sliders at once.
   for i := 0 to num_elements(_sliders)
       _sliders[i] -> hide := HIDE_WHOLE_CONTROL
   end for
end function
macro sliderCallbacks(#n#)
   on ui_control(_sliders#n#) // The single dimension version has an underscore.
       message(_sliders#n#)
   end on
end macro
iterate_macro(sliderCallbacks) := 0 to NUM_LAYERS * NUM_CONTROLS - 1


What is the first section for if NUM_CONTROLS his being specified (again?) in the second section? One is 40, the other is 4...

Also, I don't follow what this is doing:



Code:


set_bounds(sliders[i, j], 10 + 40 * i, 10)


Any insights?


----------



## derstefmitf

noisyblocks said:


> Is there a manual for SublimeKSP? I saw the wiki but it's pretty barebones and Nils' page seems more about basic KSP principles.
> 
> I'm specifically asking because I had seen the "Added features" page on Github: ui declarations using macros is excellent but I'm not following the logic of everything I see in their example loop. E.g.:
> 
> 
> 
> Code:
> 
> 
> define NUM_CONTROLS := 40
> declare pers ui_slider volumeSliders[NUM_CONTROLS] (0, 100)
> declare ui_table tables[40] [100](2, 4, 100)
> declare ui_switch switches[2, 2]
> _switches0 -> value := 1 // Access the variable name of a multi-dim UI array with an underscore
> 
> 
> 
> 
> Code:
> 
> 
> define NUM_LAYERS := 4
> define NUM_CONTROLS := 4
> on init
> // Create all of the UI in one command. The total number of controls created
> // is simply equal to NUM_LAYERS * NUM_CONTROLS.
> declare pers ui_slider sliders[NUM_LAYERS, NUM_CONTROLS] (0, 100)
> declare i
> declare j
> for i := 0 to NUM_LAYERS - 1
> for j := 0 to NUM_CONTROLS - 1
> set_bounds(sliders[i, j], 10 + 40 * i, 10)
> end for
> end for
> end on
> function hideAllSliders()
> // Here is an example of how you might want to use the single dimension version
> // to effect all the sliders at once.
> for i := 0 to num_elements(_sliders)
> _sliders[i] -> hide := HIDE_WHOLE_CONTROL
> end for
> end function
> macro sliderCallbacks(#n#)
> on ui_control(_sliders#n#) // The single dimension version has an underscore.
> message(_sliders#n#)
> end on
> end macro
> iterate_macro(sliderCallbacks) := 0 to NUM_LAYERS * NUM_CONTROLS - 1
> 
> 
> What is the first section for if NUM_CONTROLS his being specified (again?) in the second section? One is 40, the other is 4...
> 
> Also, I don't follow what this is doing:
> 
> 
> 
> Code:
> 
> 
> set_bounds(sliders[i, j], 10 + 40 * i, 10)
> 
> 
> Any insights?




Hi,

the wiki is all there is, but I find it sufficient. What exactly do need more clarification for you? 


Code:


set_bounds(sliders[i, j], 10 + 40 * i, 10)

set_bounds is a shortcut for setting the position and dimensions of an ui control. In this example there is a 2D UI array, holding multiple sliders. The two for loops go through the UI array and by using the variable i the x position offset is increased (40* i).


----------



## d.healey

Did you see this page at Nils' website - http://nilsliberg.se/ksp/scripts/tutorial/editor.html - ?


----------



## noisyblocks

Yes I saw that thanks...takes a lot of understanding of how KSP works to know what/how Nils' code is different. Learning curve.


----------



## Levitanus

by the way, I've made a little fork recently
https://github.com/nojanath/SublimeKSP/pull/81
It could be interesting at some points  Examples attached


----------



## derstefmitf

Hi, have some things changed in the compiler? I had to reinstall Sublime Text, so of course I also reinstalled the KSP package. Suddenly some things I put into external KSP files do not work, is something wrong with the import function or is it my KSP file? I got multiple KSP files in a subfolder besides my main script and I import them like this:


Code:


import 'dev/arp_var.ksp'

This one file does not "update" correctly when I want to compile my script, but when I move it out of the subfolder it works.
Maybe it has something to do with what I am doing in this KSP file? I have a macro in there which I use to declare a lot of variable and ui_controls which are part of multiple arpeggiator. I don't want to post the whole script here, but in general I do suff like this:


Code:


declare read ui_table #fam#.rhythm_max[32] (2,2,127)

#fam# is not really a family, I just use it for better readability. So I my main script I insert the macro like this:


Code:


set_up_arp_controls(arp1)

..for all the arpgeggiator I need. Either the import function is broken or my syntax is not compatible with some routines in the compiler or I don't know. Bottomline is: when I edit the file and save it, it is not loaded with the changes. Only when I move it one folder up.

Thanks.


----------



## derstefmitf

Hi, I have to add something. It seems to be simply something with the import function and subfolders. I now have the same probleme with another KSP file I import and in this file I simply declare some arrays in a macro.


----------



## EvilDragon

I use imports with subfolders and no such issues...


----------



## derstefmitf

Could something be wrong with my sublime text?


----------



## derstefmitf

I am not sure if this is the problem, but for now it seems resolved when I comment out this in the sublime text user settings:


Code:


"ignored_packages":
    [
        // "0_package_control_loader",
]

Hope it stays working now, but I also did some saving and reloading of files, maybe this was the problem...I don't know.


----------

