Skip to content

Commit

Permalink
Add random name generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kernicPanel committed Jul 8, 2022
1 parent 930fd4c commit ebd1fa0
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 4 deletions.
110 changes: 110 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?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>
<name>browserRandomizer</name>
<version>0.2</version>
<build>
<plugins>
<plugin>
<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>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>com.bitwig:extension-api</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>net.datafaker:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
<filter>
<artifact>dk.brics.automaton:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
<filter>
<artifact>com.github.mifmif:generex:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
</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>${user.home}/Bitwig Studio/Extensions/browserRandomizer.bwextension</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<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>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
64 changes: 63 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>browserRandomizer</artifactId>
<packaging>jar</packaging>
<name>browserRandomizer</name>
<version>0.1</version>
<version>0.2</version>

<repositories>
<repository>
Expand All @@ -22,6 +22,11 @@
<artifactId>extension-api</artifactId>
<version>17</version>
</dependency>
<dependency>
<groupId>net.datafaker</groupId>
<artifactId>datafaker</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>

<build>
Expand All @@ -40,6 +45,63 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>com.bitwig:extension-api</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>net.datafaker:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
<filter>
<artifact>dk.brics.automaton:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
<filter>
<artifact>com.github.mifmif:generex:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
</plugin>

<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
Expand Down
57 changes: 55 additions & 2 deletions src/main/java/com/kernicpanel/browserRandomizerExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import com.bitwig.extension.callback.NoArgsCallback;
import com.bitwig.extension.controller.api.*;
import com.bitwig.extension.controller.ControllerExtension;
import net.datafaker.Faker;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Locale;
import java.util.Random;

public class browserRandomizerExtension extends ControllerExtension {
Expand All @@ -12,26 +17,43 @@ protected browserRandomizerExtension(
super(definition, host);
}

private void printer(ControllerHost host, String s) {
host.println(s);
java.lang.System.out.println(s);
}

Random rand = new Random();
Faker faker = new Faker();

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

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

popupBrowser.resultsColumn().entryCount().markInterested();
BrowserResultsItemBank resultsItemBank = popupBrowser.resultsColumn().createItemBank(100000);

SettableBooleanValue useDate =
host.getPreferences().getBooleanSetting("Prepend date for filename", "Random name", true);

documentState
.getSignalSetting("Select", "Randomize browser selection", "Select random item")
.addSignalObserver(
selectRandomItem(host, popupBrowser, cursorTrack, resultsItemBank, rand));
documentState
.getSignalSetting("Add", "Randomize browser selection", "Add current item")
.addSignalObserver(popupBrowser::commit);

SettableStringValue filenameOutput =
documentState.getStringSetting("Filename", "Random name", 50, "");
SettableStringValue nameOutput = documentState.getStringSetting("Name", "Random name", 50, "");
documentState
.getSignalSetting(" ", "Random name", "Generate")
.addSignalObserver(randomName(useDate, filenameOutput, nameOutput));
}

private NoArgsCallback selectRandomItem(
Expand All @@ -54,6 +76,37 @@ private NoArgsCallback selectRandomItem(
};
}

private NoArgsCallback randomName(
SettableBooleanValue useDate,
SettableStringValue filenameOutput,
SettableStringValue nameOutput) {
return () -> {
String[] moods = {faker.mood().emotion(), faker.mood().tone(), faker.mood().feeling()};
String mood = moods[rand.nextInt(moods.length)];

String[] names = {
faker.superhero().power(),
faker.hacker().ingverb(),
faker.hacker().noun(),
faker.hacker().verb(),
};
String name = names[rand.nextInt(names.length)];

String[] generators = {mood, name};
String generatedString = String.join(" ", Arrays.asList(generators));
nameOutput.set(generatedString.toLowerCase(Locale.ROOT));

if (useDate.get()) {
LocalDate dateObj = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String date = dateObj.format(formatter);
generatedString = date + "_" + generatedString;
}

filenameOutput.set(generatedString.replace(" ", "_").toLowerCase(Locale.ROOT));
};
}

@Override
public void exit() {
// TODO: Perform any cleanup once the driver exits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public String getAuthor() {

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

@Override
Expand Down

0 comments on commit ebd1fa0

Please sign in to comment.