Skip to content

Instantly share code, notes, and snippets.

@sc0ttj
sc0ttj / findMidiDevices.js
Created June 12, 2025 08:58 — forked from lukewestby/findMidiDevices.js
Get MIDI input and output devices from the Web MIDI API by name
function findMidiDevices(name) {
return navigator
.requestMIDIAccess()
.then((midiAccess) => {
let input, output;
midiAccess.inputs.forEach((currentInput) => {
if(currentInput.name === name) input = currentInput;
});
midiAccess.outputs.forEach((currentOutput) => {
if(currentOutput.name === name) output = currentOutput;
@sc0ttj
sc0ttj / select-midi-port.js
Last active June 12, 2025 08:58 — forked from jussi-kalliokoski/example.js
Web MIDI API with maps (select ports)
var select = document.createElement('select');
var selectedPort = null;
var onMessage = function (event) {
// TODO: Use the message
};
var selectPort = function (id) {
var newPort = midiAccess.inputs.get(id);
@sc0ttj
sc0ttj / draw-waveform.js
Created June 12, 2025 08:57 — forked from jussi-kalliokoski/draw-waveform.js
Waveform drawing
function getAudioData (url, time) {
return new Promise(function (resolve, reject) {
var context = new AudioContext();
var track = new Audio(url);
var bufferLength = time * context.sampleRate;
var buffer = new Float32Array(bufferLength);
var collector = context.createScriptProcessor(0, 1);
var audioSource = context.createMediaElementSource(track);
var samplesCollected = 0;
const NOTE = 69;
const NOTE_ON = 0x90;
const NOTE_OFF = 0x80;
const SECONDS = 1000;
function startSequencer (destination) {
let active = false;
setInterval(() => {
const now = performance.now();
const type = active ? NOTE_OFF : NOTE_ON;
@sc0ttj
sc0ttj / midi.js
Created June 12, 2025 08:54 — forked from dustMason/midi.js
Simple web midi implementation
var OP1MidiInterface = function(midi) {
var data, cmd, channel, type, note, velocity;
midi.inputs.forEach(function(input) {
if (input.name.indexOf('OP-1') > -1) {
document.dispatchEvent(new Event('midi-connected'));
input.onmidimessage = onMIDIMessage;
}
});
midi.onstatechange = onStateChange;
@sc0ttj
sc0ttj / index.js
Created June 12, 2025 08:52 — forked from adambutler/index.js
Web Midi - Hello World
// Source: https://jsfiddle.net/KeithMcMillenInstruments/zma6pzt9
var midi, data;
// request MIDI access
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess({
sysex: false
}).then(onMIDISuccess, onMIDIFailure);
} else {
alert("No MIDI support in your browser.");
@sc0ttj
sc0ttj / akai_apc_mini_leds_webmidi.js
Created June 12, 2025 08:51 — forked from xangadix/akai_apc_mini_leds_webmidi.js
Controlling Leds on an AKAI APC mini through WebMidi
// Check this image, with all the buttons etc.
// https://s3.amazonaws.com/ext.agencewebdiffusion.com/Daniel/APCmini-vMix.PNG
// these are the available colors
var OFF = 0;
var GREEN = 1;
var GREEN_BLINK = 2;
var RED = 3;
var RED_BLINK = 4;
var YELLOW = 5;
@sc0ttj
sc0ttj / aws-wormhole-login.sh
Created June 2, 2025 10:33 — forked from igilham/aws-wormhole-login.sh
Fetch AWS credentials for CLI usage via Wormhole
#!/bin/bash
# reconfigure AWS CLI credentials
set -e
function requires() {
if ! command -v "$1" &>/dev/null; then
echo "Requires $1"
exit 1
fi
@sc0ttj
sc0ttj / example.sh
Created May 20, 2025 16:12
Simple shell deps functions
#!/bin/bash
# Declare requirements in bash scripts
set -e
function requires() {
if ! command -v $1 &>/dev/null; then
echo "Requires $1"
exit 1
fi
@sc0ttj
sc0ttj / lightweight-js-game-resources.md
Last active June 13, 2025 09:50
lightweight JS game resources