# SublimeKSP Updates (current version: 1.13.1)



## EvilDragon

*Dec 23rd, 2022 - version 1.13.1*

This is a hotfix update resolving a couple of issues from 1.13.0.

*FIXED* Macro argument expansion within strings still didn't work with literate/iterate macros
*FIXED* Certain scripts wouldn't compile properly due to lacking regular expression for parsing real numbers. This is now much improved
*FIXED* Binary numbers would be colorized as valid numbers even if they contained digits other than 0 and 1!
*FIXED* Negative numbers wouldn't have their minus sign syntax colorized if they were right next to brackets []
*IMPROVED* Added a few more tests to cover above cases

*Dec 21st, 2022 - version 1.13.0*

*ADDED* A LOT of new KSP commands were added with Kontakt 7.1.3, so SublimeKSP now supports them all!
*IMPROVED* SublimeKSP should now work without issues in Sublime Text 4 (autocompletion and snippets etc.)
*ADDED* Basic SublimeKSP commands (Compile, Recompile, Preferences) are now available through Sublime Text's command palette
*ADDED* New option to compile all open scripts that have save_compiled_source pragma directive set up successively in one go (press *Shift+F5*)!
*ADDED *New option to combine any duplicate callbacks found into one
*FIXED* Issue #222 (certain const related code works in Kontakt but doesn't compile in SublimeKSP)
*FIXED* Issue #220 (macro expansion within strings was not working properly since version 1.12.2)
*FIXED* Issue #257 (caused by addition of new K7.1.3 commands like log2() that clashed with Koala implementation that used namespaces)
*ADDED *Implemented issue #42 (compiler will now warn if built-in incrementer is not properly closed with END_INC)
*ADDED* More functions with forced parentheses, which helps with their proper autocompletion to also include those parentheses
*ADDED *Event parameters ($EVENT_PAR_0, $EVENT_PAR_VELOCITY) etc. can now use the same -> shorthand syntax as control parameters, i.e. e -> volume := -1000
*IMPROVED *Compiler will now not throw an error when attempting to evaluate a division by zero (it will inline 0 instead)
*IMPROVED* Compiler will now throw a parse error if any variables are declared outside of init callback
*ADDED* Snippet for const array
*ADDED *const/struct/list blocks are now added to the symbols list in Sublime Text
*REVERTED* Commit 0cdc9a9 that forced real number syntax to contain a number after decimal point
*REMOVED* "Raise error on empty if or case statements" option, since it's been fixed for ages now - does anyone still develop code for Kontakt versions older than 4.2?
*ADDED *Files with .ksp extension will now have a Kontakt logo icon in Sublime Text's folder view
*ADDED* Compiler progress messages are now also logged inside Sublime Text's console, for a more permanent history of what was completed (and also so that you can track the successive compilation of all open scripts)
*ADDED *Infrastructure-wise, any pull request committed to the SublimeKSP repository will now be ran against a battery of unit tests.
This will hopefully help in preventing issues like #220 happening again).
More tests are always welcome in form of pull requests, to increase coverage of use cases (see issue #266)!
Major props and huge thanks to Jack Williams from Fracture Sounds for committing most of these features and fixes in!

Previous versions:



Spoiler



*Oct 28th, 2022 - version 1.12.2*

*FIXED* Massively slowed down compile times when lots of defines are used (see PR #216)
*ADDED* tcm.wait_async() command, so that wait_async() can be used with taskfuncs
*KNOWN ISSUE* Macro expansion in text strings is not working as a consequence of PR #216!

*Oct 2nd, 2022 - version 1.12.1*

*FIXED* num_elements() stopped working for real arrays, as a consequence of two fixes in 1.12.0

*Sep 29th, 2022 - version 1.12.0*

*ADDED* New KSP commands introduced in Kontakt 7.0.11!
*ADDED* Two new SublimeKSP commands: iterate_post_macro() and literate_post_macro() (see Wiki for more info)
*FIXED* watch_array_idx() did not accept string or real arrays as an argument, when "Extra Syntax Checks" was enabled
*FIXED* Real arrays used to be valid arguments for load_array()/save_array(), which doesn't work in Kontakt, so now compiler will throw an error if you do this
*IMPROVED* Superfluous trailing whitespace used to be added in compiled output for all UI widget declaration lines - not anymore


*Apr 29th, 2022 - version 1.11.1*

*ADDED* Real numbers: allow negative exponents in scientific notation, allow decimal numbers without integer part, f.i. .025 (issue #194)
*ADDED* Raise an exception if a constant is declared as an array - requires Extra syntax checks enabled (issue #86)
*FIXED* Syntax coloring for multiple nested block comments (issue #197)
*IMPROVED* More than one whitespace before pragma keyword (issue #198)
*IMPROVED* Raise a syntax error if iterate/literate_macro declarations are missing parameters or incomplete (issue #200)
*IMPROVED* Increase the number of passes for resolving nested define statements

*Feb 23rd, 2022 - version 1.11.0*

*ADDED *Kontakt 6.7 engine parameters now supported!
*ADDED* Snippets for USE_CODE_IF/_NOT preprocessor directives
*IMPROVED* Optimized inline string array declaration (no more lines of code wasted on empty string assignments)
*IMPROVED* import_nckp() now handles \ and / paths correctly regardless of OS
*FIXED* redirect_output definition
*FIXED* Syntax coloring for end list

*Apr 20th 2021 - version 1.10.4*

*ADDED* New KSP commands and engine/control parameters from Kontakt 6.5
*ADDED* TCM exception handling can now be disabled by using SET_CONDITION(TCM_DISABLE_EXCEPTION_HANDLING)
*IMPROVED* Syntax coloring of the -> control parameter shorthand now also works if there are spaces around the arrow
*FIXED* Exception was not raised in case of an empty .nckp file being imported, which would prevent compilation from working properly

*Oct 23rd 2020 - version 1.10.3*

SublimeKSP now properly recognizes $EVENT_PAR_CUSTOM.


*Oct 19th 2020 - version 1.10.2*

In the fix for the last issue with the logger, the bug of define evaluation happening in strings was re-introduced. The following fix is verified to have fixed both problems.


*Oct 2nd 2020 - version 1.10.1*

This is a quick release fix for 1.10.0 breaking the use of the debug log after shifting string compilation to a stage too late where the logger needed to read the filepath.


*Sep 28th 2020 - version 1.10.0*

With SublimeKSP 1.10.0 comes a few improvements to the compilation process, as well as full support for Kontakt 6.4 engine parameters.

Syntax now supports Kontakt 6.4 engine parameters and commands
There was an issue where strings were calling define macros inside of them if matching any names (for example, using the word "sum" would call a define macro sum() if it existed)
Compilation now correctly allows variables that start with a number when using persistence shorthands (pers and read)
When using literate_macro, #n# now supports replacing the index of the #l# constant in the LITERALS define.





Update from Sublime Text's Package Control or from GitHub repository.


----------



## polypx

Thanks Mario. Can you briefly explain how to use the second item, the ui_id array initialization?


----------



## EvilDragon

It's just a slight improvement of already existing UI Arrays (see sKSP wiki). The difference is in how things look after compilation.

Previously, this line:


Code:


declare ui_switch Test[10]

would compile to:


Code:


declare %Test[10]
declare ui_switch $Test0
%Test[0] := get_ui_id($Test0)
declare ui_switch $Test1
%Test[1] := get_ui_id($Test1)
declare ui_switch $Test2
%Test[2] := get_ui_id($Test2)
declare ui_switch $Test3
%Test[3] := get_ui_id($Test3)
declare ui_switch $Test4
%Test[4] := get_ui_id($Test4)
declare ui_switch $Test5
%Test[5] := get_ui_id($Test5)
declare ui_switch $Test6
%Test[6] := get_ui_id($Test6)
declare ui_switch $Test7
%Test[7] := get_ui_id($Test7)
declare ui_switch $Test8
%Test[8] := get_ui_id($Test8)
declare ui_switch $Test9
%Test[9] := get_ui_id($Test9)

From 1.9.0 onward, it will look like this:


Code:


declare $preproc_i
declare %Test[10]
declare ui_switch $Test0
declare ui_switch $Test1
declare ui_switch $Test2
declare ui_switch $Test3
declare ui_switch $Test4
declare ui_switch $Test5
declare ui_switch $Test6
declare ui_switch $Test7
declare ui_switch $Test8
declare ui_switch $Test9
$preproc_i := 0
while ($preproc_i<=9)
%Test[$preproc_i] := get_ui_id($Test0)+$preproc_i
inc($preproc_i)
end while
...


This saves a ton of lines of compiled code when you get into larger UI arrays (or multidimensional ones).


----------



## polypx

I see. Brilliant, thanks!


----------



## FrancescoSabatini

Hi guys,

as Mario said now is possible to import the nckp format from Creator Tools and I wanted to add few more side notes on the integration I did:

- I'm the QA for the Kontakt Instruments team but I wanted to clarify that this is not an "official" NI participation but more an internally agreed initiative to hopefully push more of you to use our new tool.
- Mario have been beta testing my changes but you're very welcome to do the same, just whatever issue you may experience while using this new function please write to me directly or raise an issue on the github repo, and I'll try to sort it out asap.

Happy development to everybody


----------



## EvilDragon

SublimeKSP is updated to version 1.9.1! Minor (but some of them important if you use Optimize compiled code option!) fixes.


----------



## EvilDragon

SublimeKSP is updated to version 1.9.2! Some slightly more important fixes this time around


----------



## azrulsaleh

EvilDragon said:


> Sublime's autocomplete now supports variables starting with `$` prefixes. Requested by many!



YES!! So nice to have this finally!


----------



## EvilDragon

Two very quick updates happened yesterday, so we are at version 1.9.4 now!


----------



## dfhagai

*Can I downgrade the update to the previous version?* 
Since the automatic update , trying to compile a very important code that I'm working on (for more then a year now) causes sublime to crash.
The compiling process gets stuck at:




And then, after a loooooooong wait - Sublime crashes 

- The same code was perfectly fine 4 days ago.
- I've also tried to compile older version of the same code to no avail (I back up each progress).
- Sublime crashes both on my laptop & desktop.
- Uninstalling and reinstalling Sublime didn't help....

Major SOS here...any tip about downgrading would be much appreciated!:emoji_rose:


----------



## EvilDragon

Would be really good if we could inspect the code, so if you can please PM me the whole source.

As for downgrading, you can:

Download this commit: https://github.com/nojanath/SublimeKSP/tree/029148f6462b4103e487eb7476c6ba7e6dcc5ad0

Then uninstall SublimeKSP from Package Control, and just unpack the ZIP to Sublime Text 3’s Data/Packages folder.


----------



## neblix

dfhagai said:


> *Can I downgrade the update to the previous version?*
> Since the automatic update , trying to compile a very important code that I'm working on (for more then a year now) causes sublime to crash.
> The compiling process gets stuck at:
> 
> 
> 
> 
> And then, after a loooooooong wait - Sublime crashes
> 
> - The same code was perfectly fine 4 days ago.
> - I've also tried to compile older version of the same code to no avail (I back up each progress).
> - Sublime crashes both on my laptop & desktop.
> - Uninstalling and reinstalling Sublime didn't help....
> 
> Major SOS here...any tip about downgrading would be much appreciated!:emoji_rose:



The only way I can possibly debug this issue is to directly compile your code and read the output of python. I have compiled a variety of complex projects with a lot of imported files and extra features with no issues, so there isn't anything I can use to find the potential problem by myself. Since there is no error being given, and it's just crashing, it's even less likely that I can guess the issue since I don't even know the line of code it happens on.

Like Mario said, you can downgrade by uninstalling KSP in the Package Control and instead just manually installing the older version that he linked by placing it directly in the folder.


----------



## neblix

*Update:*

In the code that happens at that compilation step, I found an extraneous python print() statement, which is what I use to debug functions. It may be possible the repeated print()'s overloaded your system for some reason or another, and Sublime became unresponsive as a result.

I have scheduled a quick 1.9.6 release that removes the prints. Please check the latest automatic update before downgrading if this fixes your issue, and let me know if it doesn't.

Also, when you do, please verify you are on 1.9.6. You can do this by bringing up the Package Control "List Packages" command, and observing KSP in the list. It will say the version number.


----------



## dfhagai

neblix said:


> *Update:*
> 
> In the code that happens at that compilation step, I found an extraneous python print() statement, which is what I use to debug functions. It may be possible the repeated print()'s overloaded your system for some reason or another, and Sublime became unresponsive as a result.
> 
> I have scheduled a quick 1.9.6 release that removes the prints. Please check the latest automatic update before downgrading if this fixes your issue, and let me know if it doesn't.
> 
> Also, when you do, please verify you are on 1.9.6. You can do this by bringing up the Package Control "List Packages" command, and observing KSP in the list. It will say the version number.


Thanks for helping out so quickly, much appreciated!
Is 1.9.6 out yet? I'm currently on 1.9.4.


----------



## EvilDragon

It is out. You can always check through Package Control.


----------



## dfhagai

EvilDragon said:


> It is out. You can always check through Package Control.


How do I do that? the list shows that I'm on 1.9.4...


----------



## EvilDragon

Run the Upgrade Package command (search for it after you press Ctrl+Shift+P).


----------



## dfhagai

Tried it.


----------



## dfhagai

I should also point out that I've uninstalled and reinstalled the package, and i'ts still 1.9.4.


----------



## EvilDragon

You could still download the latest state of the master branch directly from github...


----------



## neblix

Updates take time to make it to the Package Control. I have no control over how long it takes, unfortunately.

EDIT: The update is out now. You can upgrade it through the package control menu directly, and also, you must restart Sublime for it to take effect.


----------



## dfhagai

My code is back on!!!
Thank you ever so much 😍


----------



## tonewill

Since latest update 1.9.10 this doesn't compile:


Code:


on init
    USE_CODE_IF_NOT(TEST)
    // a comment...
    declare poo
    END_USE_CODE
    message(poo)
end on

It's because of the 3 (or more) dots in the comment. I know, easily avoided but just so happens that I had that in my code and couldn't figure out why code that compiled yesteday wouldn't compile today. Thought I should mention it in case someone else has the same problem.


----------



## neblix

tonewill said:


> Since latest update 1.9.10 this doesn't compile:
> 
> 
> Code:
> 
> 
> on init
> USE_CODE_IF_NOT(TEST)
> // a comment...
> declare poo
> END_USE_CODE
> message(poo)
> end on
> 
> It's because of the 3 (or more) dots in the comment. I know, easily avoided but just so happens that I had that in my code and couldn't figure out why code that compiled yesteday wouldn't compile today. Thought I should mention it in case someone else has the same problem.



1.9.11 will be out very soon today with a fix.


----------



## maxchristensenaudio

I noticed an issue today. 
If you use the "declare pers..." function and only use numbers as the variable name, then it won't compile correctly and not add the $ at make_persistent.



Code:


on init

    declare pers ui_button $5

end on


{ Compiled on Fri Jul 31 20:25:42 2020 }
on init
  declare $concat_it
  declare $concat_offset
  declare $string_it
  declare $list_it
  declare $preproc_i
  declare ui_button $5
  make_persistent(5)
end on


----------



## EvilDragon

Nice catch! Found what caused it and the fix will be in the next update.

In practice, it's always a good idea not to use just numbers for variable names


----------



## maxchristensenaudio

I think I might have found another one.
My parent panel assignments aren't working properly with my macros.
The compiled code only uses the ui controls name and not its ui_id as it's done in the manual.



Code:


on init

macro declare_var (#name#)
    declare $#name#
    declare $pnl_#name#
    #name# -> parent_panel := $pnl_#name#
end macro

declare_var(A)
declare_var(B)

end on


{ Compiled on Mon Aug 31 20:11:26 2020 }
on init
  declare $concat_it
  declare $concat_offset
  declare $string_it
  declare $list_it
  declare $preproc_i
  declare $A
  declare $pnl_A
  set_control_par($A,$CONTROL_PAR_PARENT_PANEL,$pnl_A)
  declare $B
  declare $pnl_B
  set_control_par($B,$CONTROL_PAR_PARENT_PANEL,$pnl_B)
end on


----------



## polypx

with panels, both sides need to be inside get_ui_id(panel_name)
#name# -> parent_panel := get_ui_id($pnl_#name#)


----------



## maxchristensenaudio

I might have found another bug (if this is not the right place to post bug reports please redirect me!)

One of my simple help text functions is outputting the wrong string....
When I compile it and then hover over that control in Kontakt it outputs "stereo 350"



Code:


macro view.layer.block(#side#, x, y, width, height, mouse)

    family layers

          view.layers.slider(stereo_width_#side#, "", x + $x_off * 2 + $x_off_dist, y + $y_off_top, 500000, 1000000, 500000, mouse)
    
        layers.sli_stereo_width_#side# -> HELP := "stereo width"   

    end family       
end macro


----------



## EvilDragon

The proper place for bug reporting is Issues section of sKSP github 

But your code is kinda wrong. Macro tokens always must have # around them. So: #side#, #x#, #y#, #width#, #height#, #mouse#


----------



## maxchristensenaudio

Thanks, I'll take a look at the forum there.

However I'm not having issues with my code. Everything else works fine and as intended.
In my experience the # are only required when the tokens are to be made a part of a longer string.
So layers.sli_stereo_width_#side# is neccessary but for the rest they are inserted and work just fine because they stand alone.


----------



## EvilDragon

No, the main problem is that x alone is considered a variable, or worse, a shorthand for $CONTROL_PAR_POS_X. You don't want that. # is always required when you want to do a text replacement with macros. Even in standalone case, not as a part of a longer string necessarily.

So yeah, your code should be:



Code:


view.layers.slider(stereo_width_#side#, "", #x# + $x_off * 2 + $x_off_dist, #y# + $y_off_top, 500000, 1000000, 500000, #mouse#)


----------



## Locks

I had no idea there was a KSP plugin for Sublime. That's awesome.


----------



## EvilDragon

Updated for 1.10.4!


----------



## EvilDragon

Updated for 1.11.0!


----------



## EvilDragon

Updated for 1.11.1!


----------



## tonewill

Small insignificant bug for when next updating:
list !string[]
...
list
removes the colour formatting for the first list keyword.


----------



## EvilDragon

Thanks! Pretty easy fix.


----------



## EvilDragon

Updated for version 1.12.0/1.12.1.


----------



## tonewill

Thanks ED. Can't see the updates in the wiki though.


----------



## EvilDragon

Updated now. See iterate/literate macro sections.


----------



## tonewill

Something seems to have broken since this update. I can't compile my previously working projects any more if they have something like this (simplified to show the problem):


Code:


on init
    declare ui_switch switch[3]
    define SWITCH_PICTURES := pic1, pic2, pic3
    literate_macro(_switch#n# -> picture := "#l#") on SWITCH_PICTURES
end on


----------



## EvilDragon

Basically the same thing as here.


----------



## tonewill

Thanks, will continue over there.


----------



## EvilDragon

Updated for 1.13.0! Pretty major update this time around, folks!


----------



## AlexRuger

Wow, 1.13.0 is a hell of an update. Well done to all involved!


----------



## EvilDragon

Updated for 1.13.1 hotfix.

Will propagate to Package Control in a few hours!


----------



## tonewill

I don't know python but I was looking through some of the commits on github and noticed that in ksp_compiler.py there was:


Code:


self.traverse(ast, parent_funciton=None, function_params=[], parent_families=[])

parent_function is spelt wrong so I did a search for it and this is the only place it shows up with that spelling. Maybe a bug waiting to happen or maybe not, thought I should mention it though.

EDIT: I opened a github account and posted it as an issue.


----------



## EvilDragon

Thanks for noticing!


----------

