From 930fd4cdf743169da609a3e794e69b611e71a79a Mon Sep 17 00:00:00 2001 From: Nicolas Clerc Date: Fri, 8 Jul 2022 21:10:08 +0200 Subject: [PATCH] Remove buggy button, and delay the random selection --- README.md | 6 ++--- .../browserRandomizerExtension.java | 26 +++++++------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d1c2be7..1f4ae36 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ When used several times, I get a chain ## Activation -Copy the released extension to you Bitwig extensions folder. +Copy the released extension to your Bitwig extensions folder. Activate it in the settings. @@ -36,15 +36,13 @@ https://user-images.githubusercontent.com/720491/177211070-ae224401-6a15-41cb-9f This extension allows users to select a random item from the browser. It could be any browser related item type, like device, plugin, wave file, preset, modulator… -Currently, it has tree buttons: +Currently, it has two buttons: - `Select random item` opens a browser if none is already opened and selects a random item from the current opened browser. - `Add current item` adds the current selected item. This is the same as `OK` in the browser. For me, it is convenient as it is close to the random button. -- `Surprise me!` is the same as the two others chained: opens the browser if none opened, selects a random item and adds it. - https://user-images.githubusercontent.com/720491/177211086-69c7c208-c25e-4787-9dcc-3000ff70adce.mp4 diff --git a/src/main/java/com/kernicpanel/browserRandomizerExtension.java b/src/main/java/com/kernicpanel/browserRandomizerExtension.java index d7ddc9a..44ba34e 100644 --- a/src/main/java/com/kernicpanel/browserRandomizerExtension.java +++ b/src/main/java/com/kernicpanel/browserRandomizerExtension.java @@ -26,16 +26,12 @@ public void init() { BrowserResultsItemBank resultsItemBank = popupBrowser.resultsColumn().createItemBank(100000); documentState - .getSignalSetting("Select", "browser", "Select random item") + .getSignalSetting("Select", "Randomize browser selection", "Select random item") .addSignalObserver( - selectRandomItem(host, popupBrowser, cursorTrack, resultsItemBank, rand, false)); + selectRandomItem(host, popupBrowser, cursorTrack, resultsItemBank, rand)); documentState - .getSignalSetting("Add", "browser", "Add current item") + .getSignalSetting("Add", "Randomize browser selection", "Add current item") .addSignalObserver(popupBrowser::commit); - documentState - .getSignalSetting("Random", "browser", "Surprise me!") - .addSignalObserver( - selectRandomItem(host, popupBrowser, cursorTrack, resultsItemBank, rand, true)); } private NoArgsCallback selectRandomItem( @@ -43,20 +39,18 @@ private NoArgsCallback selectRandomItem( PopupBrowser popupBrowser, CursorTrack cursorTrack, BrowserResultsItemBank resultsItemBank, - Random rand, - Boolean commit) { + Random rand) { return () -> { if (!popupBrowser.exists().getAsBoolean()) { cursorTrack.endOfDeviceChainInsertionPoint().browse(); } - resultsItemBank - .getItemAt(rand.nextInt(popupBrowser.resultsColumn().entryCount().get())) - .isSelected() - .set(true); - if (commit) { - host.scheduleTask(popupBrowser::commit, 300); - } + host.scheduleTask( + () -> { + Integer random = rand.nextInt(popupBrowser.resultsColumn().entryCount().get()); + resultsItemBank.getItemAt(random).isSelected().set(true); + }, + 300); }; }