# How to make a file browser? Where to start?



## maxchristensenaudio (Jan 20, 2021)

I would like to make a pop up file browser for my instrument, and I have seen that even scrollbars are potentially possible.
I'm just not sure where to even start to research how to do this.

Can someone point me in the right direction?


----------



## Paul SAS (Jan 20, 2021)

Well, that depends on what you want to do with the file browser... You could either use the standard file browser from Kontakt, which is easier to script but less eye candy. The newer ones you see are all graphically created with a lot of individual graphics


----------



## Scripter (Jan 24, 2022)

Paul SAS said:


> Well, that depends on what you want to do with the file browser... You could either use the standard file browser from Kontakt, which is easier to script but less eye candy. The newer ones you see are all graphically created with a lot of individual graphics


Ok any example on how the more eyecandy ones could work?


----------



## maxchristensenaudio (Jan 25, 2022)

Scripter said:


> Ok any example on how the more eyecandy ones could work?


Make a button for each file browser entry -- display them in a nice grid and come up with a coded system for browsing through entries. This could either be a slider that moves all the buttons and hides/reveals certain buttons once they come in to view, or you change "pages" with buttons that all reveal a group of buttons/entries of your current browser


----------



## Scripter (Jan 26, 2022)

maxchristensenaudio said:


> Make a button for each file browser entry -- display them in a nice grid and come up with a coded system for browsing through entries. This could either be a slider that moves all the buttons and hides/reveals certain buttons once they come in to view, or you change "pages" with buttons that all reveal a group of buttons/entries of your current browser


Thank you so much. Any code example on how to make a slider that hides/reveales buttons? Also isn‘t it tedious to declare 200 buttons for each preset/filebrowser entry? Or is there a more efficient way?


----------



## maxchristensenaudio (Jan 26, 2022)

Kontakt GUI design is nothing but tedious my friend  
Kontakt really isn't user friendly in the way it handles graphics.
You CAN make it look really nice, but it's often achieved by very round about ways.
I made a file browser myself but it took many weeks and lines of code to behave properly and look nice at the same time.
If this is important to you then this is something you will need to figure out.
Otherwise I would say adjust your design so that it works with the built in file browser and menus


----------



## d.healey (Jan 26, 2022)

maxchristensenaudio said:


> I made a file browser myself but it took many weeks


One line in HISE 

`FileSystem.browse();`


----------



## maxchristensenaudio (Jan 26, 2022)

I'm very keen on learning HISE next but I'm glad I found my entry to coding through Kontakt.
I think HISE would have overwhelmed me in the beginning and now that I've had to do the brute forcing way through Kontakt I can much better appreciate all the things HISE allows you to do.
While at the same time understanding each platforms limitations and strengths better


----------



## Scripter (Jan 26, 2022)

maxchristensenaudio said:


> Kontakt GUI design is nothing but tedious my friend
> Kontakt really isn't user friendly in the way it handles graphics.
> You CAN make it look really nice, but it's often achieved by very round about ways.
> I made a file browser myself but it took many weeks and lines of code to behave properly and look nice at the same time.
> ...


Haha ok than I do it the tedious way. Really want to learn that kind of stuff. But I really don't have a clue on how such a browser could work. Cause i thing you have to get the position of the slider in order to define how much buttons should be moved in y-direction accordingly, right?


----------



## Scripter (Jan 26, 2022)

maxchristensenaudio said:


> I'm very keen on learning HISE next but I'm glad I found my entry to coding through Kontakt.
> I think HISE would have overwhelmed me in the beginning and now that I've had to do the brute forcing way through Kontakt I can much better appreciate all the things HISE allows you to do.
> While at the same time understanding each platforms limitations and strengths better


Also really glad to learn kontakt ksp it's literally the first scripting language I understand... don't know why. With other languages like Java or C+ it ended always in me screwing up. But now with ksp it is somehow just fun. :D


----------



## Mike Greene (Jan 26, 2022)

Scripter said:


> Also really glad to learn kontakt ksp it's literally the first scripting language I understand... don't know why. With other languages like Java or C+ it ended always in me screwing up. But now with ksp it is somehow just fun. :D


KSP is very linear, so it's easy to follow what it does, line by line. Do this, then do that, then do that - one line after the other, without a lot of jumping around. Easy.

Even with functions or macros, they're all self contained in the same script, easy to find and see what they do. Totally the opposite of Java, Python, or any of the C's, where they often call processes from _other_ scripts, which can make things a lot more confusing.

These other languages are much more powerful, of course, but for simplicity, it's tough to beat KSP.

If I were going to design a coding course, I'd start with KSP doing easy linear stuff. After the class understands the logic of how basic code works, _then_ I'd add functions. And then macros. Once the class understands functions and macros, _then_ we'd be able to move on to Python or C++ or whatever.


----------



## Scripter (Jan 26, 2022)

Mike Greene said:


> KSP is very linear, so it's easy to follow what it does, line by line. Do this, then do that, then do that - one line after the other, without a lot of jumping around. Easy.
> 
> Even with functions or macros, they're all self contained in the same script, easy to find and see what they do. Totally the opposite of Java, Python, or any of the C's, where they often call processes from _other_ scripts, which can make things a lot more confusing.
> 
> ...


Nailed it. :D It just makes sense. And yes it's tedious af - already programmed 150+ Knobs and 30+ Sub menus in my first months of scripting so far, but it just makes sense... even if my script gets really big and cluttered haha. But I like it. It does exactly what I imagine, even if the learning ressources are ... bare (especially if you stick to free ones). Luckily I found VI Control at the beginning. Really helped me so far. All the nice people here, it's awesome.


----------



## Mike Greene (Jan 26, 2022)

Scripter said:


> And yes it's tedious af - already programmed 150+ Knobs and 30+ Sub menus in my first months of scripting so far ...


One of the nice things about KSP is you can add complexity as you're ready for it. You can create each of those knobs the normal way, which is really tedious, but very easy to understand. (I stuck with that method for a long time, because it was comfortable for me.)

And then when you're ready to make the jump, you can use a macro, like this. A little less "simple," but way more efficient:


```
macro createAmazingKnob (#slider#, id)
    declare ui_slider $Knob_#slider# (0, 100)
    %Knob_id_Array[id] := get_ui_id($Knob_#slider#)
    set_control_par_str  (get_ui_id($Knob_#slider#), $CONTROL_PAR_PICTURE, "Knob_Image")
    set_control_par        (get_ui_id($Knob_#slider#), $CONTROL_PAR_WIDTH, 32)
    set_control_par        (get_ui_id($Knob_#slider#), $CONTROL_PAR_HEIGHT, 32)
    set_control_par        (get_ui_id($Knob_#slider#), $CONTROL_PAR_MOUSE_BEHAVIOUR, 2000)
    set_control_par        (get_ui_id($Knob_#slider#), $CONTROL_PAR_DEFAULT_VALUE, 50)
    set_text ($$Knob_#slider#, "")
end macro

createAmazingKnob(Master,  0)
createAmazingKnob(Kick,     1)
createAmazingKnob(Snare,   2)
createAmazingKnob(HiHat,    3)
createAmazingKnob(Toms,    4)
createAmazingKnob(Ride,      5)
createAmazingKnob(Crash,    6)
createAmazingKnob(Cowbell, 7)
createAmazingKnob(Tamb,     8)
```

For each of your other 150 knobs, you simply add one more:
createAmazingKnob(Xxxxx, ##)

-------------------------

*EDIT *- I realize that macro may be confusing, so here's what it does:

macro createAmazingKnob (#slider#, id) receives two variables. So when the macro is called with:
createAmazingKnob(Master, 0), the first variable is "Master" and the second variable is 0.
#slider# = "Master"
id = 0

Where it says: #slider# - the two # symbols mean substitute the text literally. So this command:
declare ui_slider $Knob_#slider# (0, 100)
results in:
declare ui_slider $Knob_Master (0, 100)

And of course, the next ones will be:
declare ui_slider $Knob_Kick (0, 100)
declare ui_slider $Knob_Snare (0, 100)
declare ui_slider $Knob_HiHat (0, 100), etc.

The second variable (in this case it's a number) gets used in this line:
%Knob_id_Array[id] := get_ui_id($Knob_#slider#)
Which becomes:
%Knob_id_Array[0] := get_ui_id($Knob_Master)

And the next ones will be:
%Knob_id_Array[1] := get_ui_id($Knob_Kick)
%Knob_id_Array[2] := get_ui_id($Knob_Snare)
%Knob_id_Array[3] := get_ui_id($Knob_HiHat)

Hopefully that makes sense.


----------



## Scripter (Jan 27, 2022)

Mike Greene said:


> One of the nice things about KSP is you can add complexity as you're ready for it. You can create each of those knobs the normal way, which is really tedious, but very easy to understand. (I stuck with that method for a long time, because it was comfortable for me.)
> 
> And then when you're ready to make the jump, you can use a macro, like this. A little less "simple," but way more efficient:
> 
> ...


Hey thank you very much. Do I have to use Sublime Ksp? Done all my work for now in the plain text editor in kontakt xd. And actually have no glue about sublime. Also how could you control things with the different knobs (on ui_control)?


----------



## Scripter (Jan 27, 2022)

Mike Greene said:


> One of the nice things about KSP is you can add complexity as you're ready for it. You can create each of those knobs the normal way, which is really tedious, but very easy to understand. (I stuck with that method for a long time, because it was comfortable for me.)
> 
> And then when you're ready to make the jump, you can use a macro, like this. A little less "simple," but way more efficient:
> 
> ...


Also lets say i declare the knobs Independently, how would such a self build scrollbar system work? I know the elements have to get Hidden when they cross the borders of the gui for example y=0 and y=250. But how does the scrolling of the buttons with the slider work?


----------



## Scripter (Jan 27, 2022)

Mike Greene said:


> One of the nice things about KSP is you can add complexity as you're ready for it. You can create each of those knobs the normal way, which is really tedious, but very easy to understand. (I stuck with that method for a long time, because it was comfortable for me.)
> 
> And then when you're ready to make the jump, you can use a macro, like this. A little less "simple," but way more efficient:
> 
> ...


Also just wanted to thank you for helping me. :D Huge thanks.


----------



## d.healey (Jan 27, 2022)

Scripter said:


> Done all my work for now in the plain text editor in kontakt


Wow! Get SublimeKSP and learn how to use it.


----------



## Scripter (Jan 27, 2022)

d.healey said:


> Wow! Get SublimeKSP and learn how to use it.


Haha yeah procrastinating quite some time cause yeah I got really everything done this way till now and not even needed that much time.


----------



## Mike Greene (Jan 27, 2022)

Scripter said:


> Do I have to use Sublime Ksp?


Yes. Everyone here does, and most code examples you’ll see here will assume you’ll compile with Sublime KSP. I made a video showing how to install it:






How to Install Sublime Text with KSP add-on


This question seems to come up from time to time, so I put together a video showing how to install Sublime, then Package Control, then the KSP add-on. I also added Super Calculator and Increment Selection, which I find handy.




vi-control.net


----------



## Scripter (Feb 9, 2022)

Mike Greene said:


> Yes. Everyone here does, and most code examples you’ll see here will assume you’ll compile with Sublime KSP. I made a video showing how to install it:
> 
> 
> 
> ...


Is it already available for sublime text 4?


----------



## maxchristensenaudio (Feb 9, 2022)

use move_control() with the slider


----------



## Scripter (Feb 9, 2022)

I already tried that but than the things just get moved 1 time.


```
on init

make_perfview

declare ui_slider $s (0,1000000)

declare ui_button $b

declare $i := 0

end on


on ui_control($s)

move_control_px($b, 1,0)

end on
```

I know that it can not work this way cause the callback gets only triggered one time. Somehow I have to get the position of the slider I guess to determine how the scrolling could work. Or what could I do?


----------



## maxchristensenaudio (Feb 9, 2022)

you need to implement some math if you want them to move fluently or figure out some logic system that moves them in bulk.
Could be something like:


```
on slider
    for i := 0 to num_buttons - 1
        button_ui_array(i) -> POS_X := slider * (insert math here to have them move as you want)
    end for
```


----------



## EvilDragon (Feb 9, 2022)

Scripter said:


> Is it already available for sublime text 4?


No, I doubt it's going to be updated for ST4 any time soon.


----------



## Scripter (Feb 9, 2022)

EvilDragon said:


> No, I doubt it's going to be updated for ST4 any time soon.


Ok than I have to go with S3.


----------



## Scripter (Feb 9, 2022)

maxchristensenaudio said:


> you need to implement some math if you want them to move fluently or figure out some logic system that moves them in bulk.
> Could be something like:
> 
> 
> ...


Thank you just saw it now
Meanwhile I figured out that myself:


```
on init
make_perfview
set_ui_height_px(550)

declare $i := 0

declare ui_button $up
declare ui_button $down
declare ui_slider $s (1,10)

declare ui_button $Test
move_control_px($Test,300,80+$i)



end on

on ui_control($up)
$i:= $i-20
move_control_px($Test,300,80+$i)
end on

on ui_control($down)
$i:= $i+20
move_control_px($Test,300,80+$i)
end on

on ui_control($s) {Here the problem occures.}
$i:= $i+1*($s*1)
move_control_px($Test,300,80+1*$i)
end on
```

But I guess I have a problem with the maths cause my slider scrolls it but only downwards in one direction. Guess I've done something wrong with the maths but what?


----------



## thesteelydane (Feb 12, 2022)

I would


Scripter said:


> Hey thank you very much. Do I have to use Sublime Ksp? Done all my work for now in the plain text editor in kontakt xd. And actually have no glue about sublime. Also how could you control things with the different knobs (on ui_control)?


I would highly, highly recommend you do. Makes everything so much easier.


----------



## Scripter (Feb 15, 2022)

thesteelydane said:


> I would
> 
> I would highly, highly recommend you do. Makes everything so much easier.


Yes thanks downloaded it, but still have to get used to it and learn it a little more.


----------



## Scripter (Feb 15, 2022)

Scripter said:


> Thank you just saw it now
> Meanwhile I figured out that myself:
> 
> 
> ...


But anyone can help me? I still couldn’t figure out how to get it to work.
No matter what the slider moves the button only in one direction negative or positive. So when I move the slider completely up all buttons move let’s say downwards. If I move the slider back to 0 the buttons don‘t move back to their init position but they move even more downwards. 

So something with the math has to be wrong. 
As I know sliders can only have positive values from 0 to 1000000 right?

So if I do 1*$slider it is obvious that it only will be able to move things in a positive direction.

But when I do -1*$slider it moves things only in negative direction.

So what can I do that the scrollbar works as supposed to in both directions?
Please help me.


----------



## EvilDragon (Feb 16, 2022)

The slider needs to give you an absolute position in the list of files, not a relative one.


----------



## Scripter (Feb 17, 2022)

Ok but how is this achieved? I don‘t quite understand how to get there... sorry


EvilDragon said:


> The slider needs to give you an absolute position in the list of files, not a relative one.


----------



## Scripter (Feb 22, 2022)

EvilDragon said:


> The slider needs to give you an absolute position in the list of files, not a relative one.


Bumping this cause I‘m still stuck. I guess with an absolute position you mean let‘s say for the button position x= 50 and y = 60.

So like that?


```
move_control_px($Test,50,60)
```


----------



## EvilDragon (Feb 23, 2022)

No, you need to think in browser index offsets (0 being the very first browser entry). So depending on the number of entires you're supposed to display in the browser, the slider should offset what is being displayed. For example, you have 200 browser entries, and your slider has a range of (0, 1000000), and let's say you have 15 buttons to show browser entries. Then you need the slider to generate values between 0 and 184 (so that you don't end up with an empty last "page"), so you divide 1000000 with 184 to get the browser index offset, then you can refresh what is being displayed using this offset.


----------



## Scripter (Feb 23, 2022)

Ah ok thank you.  Now I understand. :D
Saved me again ED.


----------



## Scripter (Mar 3, 2022)

thesteelydane said:


> I would
> 
> I would highly, highly recommend you do. Makes everything so much easier.


Got it but I can’t find any resources on how to learn the shortcut, how to use macros... are there tutorials available anywhere?


----------



## d.healey (Mar 3, 2022)

Scripter said:


> Got it but I can’t find any resources on how to learn the shortcut, how to use macros... are there tutorials available anywhere?





Nils Liberg's Kontakt Script Editor











Added Features · nojanath/SublimeKSP Wiki


Fork of Nils Liberg's SublimeKSP plugin. See README for details. - Added Features · nojanath/SublimeKSP Wiki




github.com


----------



## Scripter (Mar 3, 2022)

Thank you.


----------



## thesteelydane (Mar 4, 2022)

Scripter said:


> Thank you.


I would also highly recommend @d.healey's paid tutorials. I think in lesson 3 he gets to Sublime KSP...


----------



## Scripter (Mar 4, 2022)

thesteelydane said:


> I would also highly recommend @d.healey's paid tutorials. I think in lesson 3 he gets to Sublime KSP...


Yep currently saving for this. XD but will take a few months more for me as a student.


----------

