Skip to content

Instantly share code, notes, and snippets.

@alanwhite
alanwhite / miclist.java
Created September 26, 2023 07:45
List microphones in java
package xyz.arwhite;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
@alanwhite
alanwhite / Indigesturing.java
Created June 2, 2022 20:34
Example Mac OSX Magnify and Rotate gestures in a Swing app that will compile on all platform but only work on Mac (help with other platforms welcome)
package xyz.arwhite.swing;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@alanwhite
alanwhite / Indigesturing.java
Last active March 4, 2024 08:19
Sample code to capture MacOS touchpad gestures
package xyz.arwhite.swing;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseAdapter;
import javax.swing.JFrame;
import javax.swing.JPanel;
@alanwhite
alanwhite / log.ascii
Created December 22, 2021 12:29
Trying to install libusbmuxd
==> Downloading https://ghcr.io/v2/homebrew/core/m4/manifests/1.4.19
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/m4/blobs/sha256:e0fec6a49fd80cc7279c71f319d70d01ed49e894b53cd91e39f170288232fa93
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:e0fec6a49fd80cc7279c71f319d70d01ed49e894b53cd91e39f
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/automake/manifests/1.16.5
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/automake/blobs/sha256:ae77a247a13ea860236a29b02769f5327395f712413f694d8a8d20cb6c21332d
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:ae77a247a13ea860236a29b02769f5327395f712413f694d8a8
######################################################################## 100.0%
@alanwhite
alanwhite / AbstractAutoBeam.java
Created December 20, 2021 08:37
Base class with utility methods for classes implementing automatic beaming algos
package xyz.arwhite.music.helpers;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import xyz.arwhite.music.models.BaseNoteModel;
import xyz.arwhite.music.models.BeamEnum;
import xyz.arwhite.music.models.MeasureModel;
@alanwhite
alanwhite / AutoBeamCommon.java
Last active December 20, 2021 08:36
Algo that implements a common beam style for music, where the primary subdivision of the beat is used to direct hooks
package xyz.arwhite.music.helpers;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import xyz.arwhite.music.models.BaseNoteModel;
import xyz.arwhite.music.models.BeamEnum;
@alanwhite
alanwhite / AutoBeamSimple.java
Last active December 20, 2021 08:36
Simple algo to automatically add beams to music
package xyz.arwhite.music.helpers;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import xyz.arwhite.music.models.BaseNoteModel;
import xyz.arwhite.music.models.BeamEnum;
@alanwhite
alanwhite / TimeSigUtils.java
Last active December 4, 2021 16:38
Helper class for exposing characteristics of a time signature
public class TimeSigUtil {
public static boolean isCompoundTime(TimeSigModel model) {
if ( model.getTop() == 3 )
return false;
if ( model.getTop() % 3 == 0 )
return true;
public class Divisions {
public static int divisionsPerBeat(MusicalContext mcx) {
var div = mcx.getDivisions() * 4;
var top = mcx.getTimeSig().getTop();
var bot = mcx.getTimeSig().getBottom();
var bpb = TimeSigUtil.beatsPerBar(mcx.getTimeSig());
return (div * top) / bot / bpb;
@alanwhite
alanwhite / AutoBeamSimpleTimeAlgo1.java
Created December 4, 2021 15:40
Example tests for the simplest autobeam algo
class AutoBeamSimpleTestAlgo1 {
// for divisions = 840
private static Map<Integer, Integer> durations = Map.of(
BaseNoteModel.semiBreve, 3360,
BaseNoteModel.minim, 1680,
BaseNoteModel.crotchet, 840,
BaseNoteModel.quaver, 420,
BaseNoteModel.semiQuaver, 210,
BaseNoteModel.demiSemiQuaver, 105,