Most virtual software synthesizers use the knob GUI elemnt, which is imported from physical synthesizers. Musicians like knobs. On a physical synthesizer you can manipulate the knob with your hand, and have it change a parameter for the sound. In a virtual softsynth, the knob can be manipulated with the mouse.
Knobs present a technical challenge for the synth GUI programmer. In most cases it looks terrible if you just put up an image of your knob, and rotate it when the user moves the mouse. Rotating the mouse does not take the lighting conditions into effect, and it's.. ugly.
There are multiple ways to fix this, but most ofen GUI programmers "cheat", and use a set of prerendered images of the knob turned in different positions. For instance, 128 images of the knob in different positions is usually enough discrete steps that you'll not notice that it's not a continous rotation.
It would be tedious to draw all 128 images by hand, so people turn to tools to help. Knobster is basically such a tool.
Other tools exist to solve this problem.
- Knobman: http://www.g200kg.com/en/software/knobman.html Knobman is a GUI based tool. Because it has a GUI, there are limitations to its flexibility.
Knobster uses GLSL fragment shaders to generate images on the GPU. This might sound like a weird way to do it, but it has some advantages.
- A large community of people who are really good at generating graphics with fragment shaders exist.
- It's very flexible.
- You can change the generation code on the fly, without compiling or restarting the program.
Here is a relevant blog post.
To use Knobster you need to do two things:
- Create or edit a generator file (a GLSL fragment shader)
- Call knobster with the right command-line arguments
The generator is a fragment shader file that contains two functions:
vec4 generate(vec2 pos, float v)
This function takes two arguments: the point we're rendering (pos) and the position of the the knob (v).
pos
is avec2
containing the normalized rendering point, that is, both x and y coordinates have been scaled to fit into the range 0.0 to 1.0.v
is the normalized knob position. If you specify that you want to generate a strip with 128 knob images, for image 0v
will be 0.0, and for image 127,v
will be 1.0.
The return color must be in linear space, that is, must not be gamma corrected.
vec4 gamma(vec4 col)
This function must return a gamma corrected version of col
. If you do not wish to do gamma correction, you can just return col
unmodified from this function.
The reason we have a separate function for gamma correction, is that the oversampling must be done in linear space for best results. And if we returned a gamma corrected color from generate
, that wouldn't be possible.
Knobster has two modes, display and generate:
- In display mode, Knobster opens a window in which the knob is drawn. The window is updated when the generator file is changed.
-
- In generate mode, Knobster opens a window and draws the downsampled knobs as fast as possible, copies them to a png file, and exits.
-d
,--display
select display mode-g
,--generate
select generate mode
-k <path>
,--knobfile <path>
path to generator file
-w <arg>
,--width <arg>
image width in pixels-h <arg>
,--height <arg>
image height in pixels-o <arg>
,--oversampling <arg>
oversampling factor
-n <arg>
,--num <arg>
number of knob images in strip-f <arg>
,--file <arg>
path to ouput PNG file
Knobster uses premake to generate Visual Studio solution and project files. You can read more about premake here: http://industriousone.com/premake-quick-start
- Clone this repository
- Clone the '64klibs' repository into the same parent folder, so that the two repositories are side by side
- Make sure that you have premake5.exe in your $PATH, or put it directly into the root of the knobster folder, along the premake5.lua file. You can find premake5.exe in 64klibs/premake.
- Open a command window
cd
into the knobster folder- run
premake5.exe <toolset>
where toolset is the toolset you want to generate build files for, e.g. vs2012. You can see options on the premake quick start page, linked above. - Open up the solution file now generated in build/knobster.sln
- Proceed as normal