Context Menu - Factory Method?
-
OK, so I'm a real novice at this. Been following the tutorial after compiling the latest HISE from GitHub source. All going well until I get to the section referring to adding the various controls to the plugin. Created the first 'modWheelAttKnob' but then creating subsequent knobs I get lost....
The tutorial says:
'If you rewrite the widget definition as factory method, you'll end up with something like this:
inline function createMusicBoxKnob(name, x, y)
{
local widget = Content.addKnob(name, x, y);Content.setPropertiesFromJSON(name, { "width": 32, "height": 38, "filmstripImage": "{PROJECT_FOLDER}knob_128frames.png", "numStrips": "128" }); return widget;
};
const var modWheelAttKnob = createMusicBoxKnob("modWheelAttKnob", 87, 99);
This does not seem to be less code, but from now on, you can add the same knob type with a simple line:
const var clickAttackKnob = createMusicBoxKnob("clickAttackKnob", 127, 99);
Now comes the best part: HISE can automatically convert a widget definition plus its JSON properties into a factory method. Select everything you want to move into the factory method (in this case the widget definition line and all JSON code including the comments), and select "Convert to UI factory method" in the context menu. Enter a name for the method (start with createXXX) and it will replace the definition with the lines shown above:'
How do I get to the context menu to do this? Highlighted the required code, tried ESC but there is no Convert to UI factory method shown.......
Looked through the documentation on Scripting and Script Panel, but couldn't work out how to do this.......
Sorry to be a nuisance and asking basic questions but again I'm stuck and any help much appreciated..... -
It's the context menu in the code editor. Just highlight the code and right click.
-
I did that, but can't access Convert to UI factory method in the options - see attached screenshot
Am I in the wrong area? I put the code in ScriptEditor Interface. oninit. Highlighted the relevant code, right clicked and got the attached context menu, but the option is greyed out so unavailable.....
Many thanks for your patience -
Oh, that's a misunderstanding. The tool in the context menu creates the very code you've already pasted.
-
Thanks for responding, but I'm more confused than ever.
I'm still none the wiser as to how I would create a factory function.....
I've tried adding this code:
inline function createMusicBoxKnob(name, x, y)
{}
in the script editor, highlighting it and right clicking. Still the Convert to UI factory method is greyed out.....
Tried just adding inline function by itself and opening context menu - same result.
In simple terms, how do I create a factory function?
Incidentally, I'm using version 1.1.0 compiled yesterday from the latest source code on a Windows 10 Pro machine x-64.
Thought I'd try going back to the download version 1.0.0 from the website, but after installing this, I can't get it to run anymore (it worked well previously) - double click the icon and apart from the spinning wheel icon for a few seconds, nothing happens at all. Tried uninstalling it and reinstalling with same result. Is there a problem with having both versions 1.1.0 and 1.0.0 installed at the same time? Should I remove the both the later version (1.1.0) and the 1.0.0 version totally and try starting from scratch?
If I had any hair left it would all have been pulled out by now :) -
Alright first things first :)
If you create a widget and set its properties, you'll end up with code like this:
const var modWheelAttKnob = Content.addKnob("modWheelAttKnob", 87, 99); // [JSON modWheelAttKnob] Content.setPropertiesFromJSON("modWheelAttKnob", { "width": 32, "height": 38, "filmstripImage": "{PROJECT_FOLDER}knob_128frames.png", "numStrips": "128" }); // [/JSON modWheelAttKnob]
The problem is that if you want to duplicate this widget, you'll end up with a lot of duplicated code. In order to avoid this, you can now select the code (make sure you select exactly the code shown above), right click on the code editor and choose create UI Factory method and it will transform this code to:
inline function createMusicBoxKnob(name, x, y) { local widget = Content.addKnob(name, x, y); Content.setPropertiesFromJSON(name, { "width": 32, "height": 38, "filmstripImage": "{PROJECT_FOLDER}knob_128frames.png", "numStrips": "128" }); return widget; }; const var modWheelAttKnob = createMusicBoxKnob("modWheelAttKnob", 87, 99);
From then on you can use the factory function as one liner to create the other controls.
Now the other problem with going back to 1.0.0 is a really annoying issue, because I changed how the layout system stores its state and if you try to load a "1.1.0" layout with the "1.0.0" version, it crashes (the other way around it detects this and prints a graceful error message, but unfortunately I can't change the code on 1.0.0 :). The solution is to delete the file
editorData.json
found in the%APPDATA%/HISE
directory then 1.0.0 will work again. -
OK - many thanks for the response. Appreciate you taking the time to help me out :)
Now I see how it works! Did as you suggested above and managed to create the factory function successfully - now onward and upwards with the remaining controls and the reast of the tutorial....Also located the editorData.json file, deleted it and yes, 1.0.0 now starts OK
Now I'm wondering how best to pause a project overnight and reload it the next day to continue. I tried File -> Close Project, shutdown HISE, restarted and attempted to load the project(MusicBox), but there was nothing displayed - it was if it was an empty project.
Tried File -> Open File -> Presets folder and selected the latest autosave.hip and there was my tutorial stuff - except the keyboard now only plays the mallet sound, no musical notes. I may have stuffed something up by switching between versions 1.1.0 and 1.0.0 so I'll manually delete the MusicBox project folder and sub folders and start from the beginning again using version 1.0.0What is the recommended way to save a project to enable a computer shutdown so that I can pick up again the next day?
Sorry for all the questions!