magneto538
Product Engineer
Hi all.
I am setting up an NKA-based presets management system. In order to easily import NKAs, I will have the user triggering manually the scan using the File Selector (just like it happens with the scan in Output Exhale).
I have two UI elements here, a button (presets_scan) and a File Selector (presets_list). When presets_scan is clicked, it triggers presets_list's UI callback using fs_navigate.
presets_list's callback acts like a big 'for' loop. Within PRESETS_BUFFER (which is the name of the array containing the current preset's data) is a unique ID which identifies each NKA preset. After loading PRESETS_BUFFER from disk, this UID is compared to the ones which are saved inside a UID buffer: if the UID is NOT in the buffer yet, the array data are added to some menus (basically, I am loading the name of the array in the menus so I can load the preset easily).
When the data has been loaded, another fs_navigate is triggered, so the callback is triggered again (just like a 'for' loop). The callback is triggered as long as the UID of the loaded preset is NOT in the UID buffer: when this happens, it means that the file selector has completed a full round of loading, so it stops.
This is a good solution in my mind, the problem is that every now and then - with no specific pattern - the UID is not loaded correctly. Sometimes I get an UID from a previously loaded array instead of the one in the array I am currently loading, so the loop stops before finishing the scan. I thought about a failed array load, but I checked the async status for each cycle and the array is loaded correctly everytime. I really don't know where the problem might be, because everything seems to be OK but sometimes the wrong UID is retrieved from the array. I am sure that all the UIDs are different in each source NKA because I have manually checked them.
Here's (part of) the script:
Any ideas?
I am setting up an NKA-based presets management system. In order to easily import NKAs, I will have the user triggering manually the scan using the File Selector (just like it happens with the scan in Output Exhale).
I have two UI elements here, a button (presets_scan) and a File Selector (presets_list). When presets_scan is clicked, it triggers presets_list's UI callback using fs_navigate.
presets_list's callback acts like a big 'for' loop. Within PRESETS_BUFFER (which is the name of the array containing the current preset's data) is a unique ID which identifies each NKA preset. After loading PRESETS_BUFFER from disk, this UID is compared to the ones which are saved inside a UID buffer: if the UID is NOT in the buffer yet, the array data are added to some menus (basically, I am loading the name of the array in the menus so I can load the preset easily).
When the data has been loaded, another fs_navigate is triggered, so the callback is triggered again (just like a 'for' loop). The callback is triggered as long as the UID of the loaded preset is NOT in the UID buffer: when this happens, it means that the file selector has completed a full round of loading, so it stops.
This is a good solution in my mind, the problem is that every now and then - with no specific pattern - the UID is not loaded correctly. Sometimes I get an UID from a previously loaded array instead of the one in the array I am currently loading, so the loop stops before finishing the scan. I thought about a failed array load, but I checked the async status for each cycle and the array is loaded correctly everytime. I really don't know where the problem might be, because everything seems to be OK but sometimes the wrong UID is retrieved from the array. I am sure that all the UIDs are different in each source NKA because I have manually checked them.
Here's (part of) the script:
Code:
on ui_control (presets_scan) // button
// Reset everything and trigger the real scan (which happens in presets_list callback)
if presets_scan = ON
// Reset UID buffer. I will load the current UID in this array.
for i := 0 to num_elements(uid_buffer)
uid_buffer[i] := -1
end for
// ...Additional reset operations...
// fs_navigate triggers the File Selector callback by default.
// This one is here in order to trigger it.
fs_navigate(get_ui_id(presets_list), 1)
end if
end on
on ui_control (presets_list)
// After setting up everything in presets_scan, this callback is triggered.
if presets_scan = ON
// Load next preset data, then load it from disk
@sel_preset_name := fs_get_filename(get_ui_id(presets_list), 0)
@sel_preset_path := fs_get_filename(get_ui_id(presets_list), 2) & '.nka'
// PRESET_BUFFER is the array where I store all the presets data, including an unique ID for each preset.
P_ASYNC_ID := load_array_str(PRESET_BUFFER, @sel_preset_path)
// Wait for Async green light. P_ASYNC_ID is processed by async callback.
while P_ASYNC_ALLOW # ON
if P_ASYNC_ALLOW = -1
P_ASYNC_ALLOW := OFF
exit
end if
wait(1000)
end while
P_ASYNC_ALLOW := OFF
// If the current UID is not in the buffer yet, it means that the current .nka has not been imported, so import it.
// If the current UID is already in the buffer, it means that the scan is complete, so get the hell out.
if search(uid_buffer, PRESET_BUFFER[P_UID_IDX]) = -1
uid_buffer[pc] := PRESET_BUFFER[P_UID_IDX]
// ...here's where I place the script to load the presets to some menus...
inc(pc)
// Goto the next file in the File Selector. fs_navigate triggers this callback again, so it's like being in a big for loop.
// This pseudo-loop ends when the condition above is not met (aka the 'else' statement below is triggered).
fs_navigate(get_ui_id(presets_list), 1)
else
presets_scan := OFF
exit
end if
end if
end on
Any ideas?
Last edited: