Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
kernicPanel committed Jul 4, 2022
0 parents commit 606f499
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/${bitwig.extension.directory}
/target
.DS_Store
last-build.bin
fileHashes.lock
/.settings/
/.classpath
/.project
/.idea
*.iml
/bin/
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@



# browserRandomizer

Bitwig browser random selection

## WARNING

This WILL lead to unexpected results, be sure to lower your volume before using.

## Motivation

I enjoy surprises, and I think that creativity comes from constraints.

So I wanted to make a script that would randomly select a Bitwig browser item.
This allows me two main things:
- Select unexpected items, which open up possibilities for me to explore.
- Force me to use a forgotten device, plugin… etc. to try to master it.

When used several times, I get a chain

## Activation

Copy the released extension to you bitwig extensions folder.

Activate it in the settings.

https://user-images.githubusercontent.com/720491/177204726-4d17190c-1852-4a35-961f-2be9593b6d7f.mp4

## Usage

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:
- `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/177204748-10d5f19a-0846-47ba-b016-e25fd0b46d84.mp4
65 changes: 65 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kernicpanel</groupId>
<artifactId>browserRandomizer</artifactId>
<packaging>jar</packaging>
<name>browserRandomizer</name>
<version>0.1</version>

<repositories>
<repository>
<id>bitwig</id>
<name>Bitwig Maven Repository</name>
<url>https://maven.bitwig.com</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.bitwig</groupId>
<artifactId>extension-api</artifactId>
<version>17</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<optimize>true</optimize>
<fork>true</fork>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<maxmem>1024m</maxmem>
</configuration>
</plugin>

<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>rename-file</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>/home/nc/Bitwig Studio/Extensions/browserRandomizer.bwextension</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

105 changes: 105 additions & 0 deletions src/main/java/com/kernicpanel/browserRandomizerExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.kernicpanel;

import com.bitwig.extension.callback.NoArgsCallback;
import com.bitwig.extension.controller.api.*;
import com.bitwig.extension.controller.ControllerExtension;

import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.IntStream;

public class browserRandomizerExtension extends ControllerExtension {
protected browserRandomizerExtension(
final browserRandomizerExtensionDefinition definition, final ControllerHost host) {
super(definition, host);
}

@Override
public void init() {
final ControllerHost host = getHost();

final DocumentState documentState = host.getDocumentState();
final PopupBrowser popupBrowser = host.createPopupBrowser();
popupBrowser.exists().markInterested();
final CursorTrack cursorTrack = host.createCursorTrack(0, 0);

AtomicReference<Integer> numberOfChoices = new AtomicReference<>(0);
AtomicReference<Integer> nextChoice = new AtomicReference<>(0);
Random rand = new Random();
popupBrowser
.resultsColumn()
.entryCount()
.addValueObserver(
newValue -> {
if (newValue > 0) {
numberOfChoices.set(newValue);
}
});

documentState
.getSignalSetting("Select", "browser", "Select random item")
.addSignalObserver(
selectRandomItem(
host, popupBrowser, cursorTrack, numberOfChoices, nextChoice, rand, false));
documentState
.getSignalSetting("Add", "browser", "Add current item")
.addSignalObserver(popupBrowser::commit);
documentState
.getSignalSetting("Random", "browser", "Surprise me!")
.addSignalObserver(
selectRandomItem(
host, popupBrowser, cursorTrack, numberOfChoices, nextChoice, rand, true));
}

private NoArgsCallback selectRandomItem(
ControllerHost host,
PopupBrowser popupBrowser,
CursorTrack cursorTrack,
AtomicReference<Integer> numberOfChoices,
AtomicReference<Integer> nextChoice,
Random rand,
Boolean commit) {
return () -> {
if (!popupBrowser.exists().getAsBoolean()) {
cursorTrack.endOfDeviceChainInsertionPoint().browse();
}
// go back to first item
// unfortunately, selecting the first item does not work
// popupBrowser.selectFirstFile();
// TODO: replace this ugly trick with a proper way to select the first item
IntStream.range(0, numberOfChoices.get())
.forEach(
i -> {
host.println("up " + i);
popupBrowser.selectPreviousFile();
});

// go to next random choice
// once again, I did not find a proper way to select a specific item
if (numberOfChoices.get() > 0) {
nextChoice.set(rand.nextInt(numberOfChoices.get()));
host.println("nextChoice " + nextChoice.get());
IntStream.range(0, nextChoice.get())
.forEach(
i -> {
host.println("down " + i);
popupBrowser.selectNextFile();
});

if (commit) {
host.scheduleTask(popupBrowser::commit, 300);
}
}
};
}

@Override
public void exit() {
// TODO: Perform any cleanup once the driver exits
}

@Override
public void flush() {
// TODO Send any updates you need here.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.kernicpanel;

import java.util.UUID;

import com.bitwig.extension.api.PlatformType;
import com.bitwig.extension.controller.AutoDetectionMidiPortNamesList;
import com.bitwig.extension.controller.ControllerExtensionDefinition;
import com.bitwig.extension.controller.api.ControllerHost;

public class browserRandomizerExtensionDefinition extends ControllerExtensionDefinition {
private static final UUID DRIVER_ID = UUID.fromString("5c4b743f-cc91-41cf-be42-092ecac4a64b");

public browserRandomizerExtensionDefinition() {}

@Override
public String getName() {
return "browserRandomizer";
}

@Override
public String getAuthor() {
return "kernicPanel";
}

@Override
public String getVersion() {
return "0.1";
}

@Override
public UUID getId() {
return DRIVER_ID;
}

@Override
public String getHardwareVendor() {
return "kernicPanel";
}

@Override
public String getHardwareModel() {
return "browserRandomizer";
}

@Override
public int getRequiredAPIVersion() {
return 17;
}

@Override
public int getNumMidiInPorts() {
return 0;
}

@Override
public int getNumMidiOutPorts() {
return 0;
}

@Override
public void listAutoDetectionMidiPortNames(
final AutoDetectionMidiPortNamesList list, final PlatformType platformType) {}

@Override
public browserRandomizerExtension createInstance(final ControllerHost host) {
return new browserRandomizerExtension(this, host);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.kernicpanel.browserRandomizerExtensionDefinition

0 comments on commit 606f499

Please sign in to comment.