Checking elements of an array in the "if" operator
-
@d-healey Is the ID of the SampleMap. The console print is showing it correctly.
const var currentSampleMapId1 = Sampler1.getCurrentSampleMapId();
-
@bendurso Yeah but is it "Pad 1" or "Pad 1.xml" or something different?
-
@d-healey Oh, it's just "Pad 1".
I just noticed that when I hit "compile" the panel shows or hides as it should. But it doesn't happen when I change the samplemap. I think placing "updateKeyboardPanelVisibility()" inside the samplemap selectors doesn't work because they can't check each other's state.
-
@bendurso Yeah you'll need to trigger the function from a callback or a broadcaster otherwise it won't know when to change.
-
@d-healey Oh thanks, that's new for me. I'll investigate how to implement it :)
-
@d-healey I have simplified the code to only check the SampleMap of one sampler. I also changed the constant variables to local variables within the inline function updateKeyboardPanelVisibility(). After making these changes, I called the function "updateKeyboardPanelVisibility()" on the sample selector, and it started working. However, I noticed that the panels only update after changing the sample map twice. I mean, when one panel is active and the other has to be activated, the change only takes effect after two switches. Any insights into why this might be happening?
const var pnlKeyboard1 = Content.getComponent("pnlKeyboard1"); const var pnlKeyboard2 = Content.getComponent("pnlKeyboard2"); inline function updateKeyboardPanelVisibility() { local currentSampleMapId1 = Sampler1.getCurrentSampleMapId(); local PadSampleMaps = ["Pad 1", "Pad 2", "Pad 3", "Pad 4"]; if (PadSampleMaps.contains(currentSampleMapId1)) { pnlKeyboard1.showControl(true); pnlKeyboard2.showControl(false); } else { pnlKeyboard1.showControl(false); pnlKeyboard2.showControl(true); } } inline function onpnlSampleSelector1Control(component, value) { if (value) { local array = component.get("popupMenuItems").split("\n"); local t = array[value - 1]; local t2 = t.substring(t.indexOf(":") + 2, t.length); lblSampler1.set("text", t2); Sampler1.loadSampleMap(t2); updateKeyboardPanelVisibility(); } };
-
@bendurso I'm not sure it's a good idea to call your variable
array
as that is a type, but perhaps it won't hurt...When you load a sample map it doesn't happen instantaneously, but your call to
updateKeyboardPanelVisibility()
does happen straight after yourloadSampleMap
call. But at that point the sample map ID will still be for the old one, because the new one hasn't finished loading. You need to handle this in the preload callback.I showed how to do this last month in my auto colouring the keyboard video on Patreon.
By the way, why are you hiding/showing keyboards?
-
@d-healey The auto colorouing keyboard should be a perfect solution hehe. I placed two colored panels above the real (floating tile) keyboard to show the range of each selected sample map in a different color. (I have two samplers, so I'll duplicate this function)
Ohh, I just tried and it worked! Thank you so much!
pnlSampleSelector1.setLoadingCallback(function(isPreloading) { updateKeyboardPanelVisibility(); });
-
to show the range of each selected sample map in a different color.
Why not just colour the keys?
-
@d-healey Is it possible to color each sampler with a different color? Like this:
I should have started there hehe.
-
@bendurso Go watch my video, that's exactly what I show how to do :p