Skip to content

Commit

Permalink
Remove buggy button, and delay the random selection
Browse files Browse the repository at this point in the history
  • Loading branch information
kernicPanel committed Jul 8, 2022
1 parent a161286 commit 930fd4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand Down
26 changes: 10 additions & 16 deletions src/main/java/com/kernicpanel/browserRandomizerExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,31 @@ 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(
ControllerHost host,
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);
};
}

Expand Down

0 comments on commit 930fd4c

Please sign in to comment.