• Stars
    star
    120
  • Rank 286,953 (Top 6 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created about 5 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interact with the browser using the Freedrum sensors in JavaScript

Freedrum.js 🥁

Play Air Drums and interact with the browser using the Freedrum sensors.

Blog post

Demo:

demo

Watch an actual demo video here.

Current status

Working but could be improved. More services could be added such as the one to get motion data but I don't have the time right now.😞

The Web Bluetooth version will only work with browsers that support the Web Bluetooth API.

Features

Currently, I've only had the time to work on reading the BLE MIDI data coming from the sensors.

It should be possible to also write to the sensors if you want to reposition the space each drum pad takes for example... but I will try to look into that later.

Installation

There are 2 ways to use Freedrum.js, either directly in the browser or as a Node.js package.

Using web bluetooth

Add the following script tag to your HTML file:

<script src="https://raw.githubusercontent.com/charliegerard/freedrum.js/master/freedrum.js"></script>

Using Node.js

npm install freedrum

How to use

Using web bluetooth:

Each sensor has a unique uuid you can use to determine which sensor you're trying to connect to:

// These may be different.
// You can also find devices by name "FD2 v8" and "FD2 v9" and then look for their uuid.

/*
XrnS1FRG/q/kM7ecsfErcg==

T/P6X0jDSadbdUXxRjjAVw==

6lASiqGNnfck4kO66nRlGw==

dJTKMPg47ZLgP4PAEBuWZw==
*/

You need to start by instantiating a sensor:

const freedrumSensor = new FreedrumSensor(uuid);

// example: new FreedrumSensor("XrnS1FRG/q/kM7ecsfErcg==");

Then, to connect, the web bluetooth API requires an input gesture by the user, in the following case, a click:

const freeDrumStickOne = new FreedrumSensor("XrnS1FRG/q/kM7ecsfErcg==");

document.querySelector('button').addEventListener('click', event => {
  freeDrumStickOne.request()
  .then(_ => freeDrumStickOne.connect())
  .then(_ => freeDrumStickOne.setup())
  .then(characteristic => 
    characteristic.addEventListener('characteristicvaluechanged', (event) => 
      handleSensorData(event.target.value)))
  .catch(error => { console.log(error) });
});

const handleSensorData = data => {
  // data is of type DataView with byteLength of 5 because it contains 5 integers.
  // e.g: [128,128,153,50,0]
  // [Header byte, Timestamp byte, Status byte, Data byte, Data byte]
}

This will connect to the sensor, and subscribe to the changes of data coming from the bluetoothLEMIDI service and its characteristic.

You can try the demo in the example folder if you want. Turn on each sensor, click on the connect button and connect each sensor to the page.


Using Node.js:

To use the module in your Node.js application, you need to start by importing it:

const freedrumJS = require('freedrum');

To start using it, you need to pass a uuid:

const sensorUuid = 'b50b6d66efb145f4b1c04f1dea0fbdb9';
const sensor = freedrumJS(sensorUuid);

If you don't know the uuid of your sensors yet, you can use their device name "FD2 v8" and "FD2 v9".

const sensor = freedrumJS("FD2 v8");

And then to get the data, you need to call the following function:

const sensor = freedrumJS("FD2 v8");
sensor.onStateChange(function(data){
  // do something with data
})

The data

The data comes back as an array of 5 integers with the following format:

[Header byte, Timestamp byte, Status byte, Data byte, Data byte]

// example: [128,128,143,44,90]

The header and timestamp byte are set to 128 but it doesn't seem to really matter as we don't need it.

The 3rd element is the status code representing the MIDI command, the 4th is the note and the 5th is the velocity we can use for volume.

// example

// with WebBluetooth:
const handleSensorData = data => {
  let command = data.getUint8(2);
  let note = data.getUint8(3);
  let velocity = data.getUint8(4);
}

//With Node.js
sensor.onStateChange(function(data){
  let command = data[2];
  let note = data[3];
  let velocity = data.[4];
})

Depending on the audio library you'll use with it, you might want to normalize the velocity. To do this, you can use the following formula:

// Example for Howler.js
// ----------------------
/*

The volume property in Howler.js is normalized (between 0 - 1)
The velocity value in MIDI ranges from 0 - 127

To normalize, here's the equation:
z = (x - min(x)) / (max(x) - min(x))

*/

let normalizedVolume = (velocity - Math.min(0,127)) / (Math.max(0,127) - Math.min(0,127));

Status byte

The status byte represents commands such as noteOn, noteOff, etc...

  • 153: noteOn
  • 137: noteOff
  • 176: Continuous controller / Control Change (CC) - (seem to always return 16 or 24 / controller & controller value)

Services and Characteristics available

I've mainly used the bluetoothLEMidi service but there are others available, including the freedrums service to get access to motion data.

Resources

More info on these docs:

Sounds used in the example are from this website


Hope it helps! 💚

More Repositories

1

Epoc.js

Node.js addon for the Emotiv C++ SDK
C
782
star
2

gaze-detection

👀 Use machine learning in JavaScript to detect eye movements and build gaze-controlled experiences.
JavaScript
583
star
3

safe-space

Github action that checks the toxicity level of comments and PR reviews to help make repos safe spaces.
JavaScript
471
star
4

mock-interview-questions

382
star
5

whereami.js

Node.js module to predict indoor location using machine learning and WiFi information 📶
JavaScript
356
star
6

dev-notes

Quick notes of things I learn
221
star
7

beat-pose

Play a Beat Saber clone with hand movements using Tensorflow.js & PoseNet
JavaScript
202
star
8

flappy-windows

Flappy Bird with browser windows
JavaScript
174
star
9

ultrasonic-payments

Experiment using ultrasonic data transmission in JavaScript as a payment method. 💸
JavaScript
155
star
10

washOS

Automatic detection of water running to trigger a countdown in the browser
JavaScript
138
star
11

tfjs-recycling

[WIP] Using Tensorflow.js to detect objects and help recycle
JavaScript
107
star
12

whoosh

[Prototype] Control a 3D spaceship with hand movements
JavaScript
106
star
13

interactive-frame-tfjs

Interactive digital art with head-coupled perspective effect using Three.js and TensorFlow.js
JavaScript
94
star
14

splat

Motion-controlled Fruit Ninja clone using Three.js & Tensorflow.js
JavaScript
94
star
15

webusb-rtlsdr-aircraft-radar-system

Build an aircraft radar system using WebUSB and a RTL-SDR dongle to receive live data from airplanes 📡 ✈️
JavaScript
91
star
16

dark-mode-clap-extension

Chrome extension to toggle dark mode on Netlify by clapping hands 👏
JavaScript
84
star
17

gestures-ml-js

[WIP] - Gesture recognition using hardware and Tensorflow.js
JavaScript
77
star
18

hvbrd-sockets

Interactive hoverboard prototype using JavaScript and WebSockets
JavaScript
74
star
19

speak-extension

Chrome extension with speech-to-text functionality to make your presentations more accessible with live captions
HTML
73
star
20

hidden

Script to make inaccessible elements invisible to everyone, until their accessibility issues are fixed
JavaScript
70
star
21

pride-vscode-themes

Pride-inspired VSCode themes
56
star
22

windows-equalizer

Prototype of music equalizer using browser windows and the Web Audio API
JavaScript
49
star
23

rbd-thought-sensor

[WIP] A thought sensor for react-beautiful-dnd, built with Epoc.js and the Emotiv Epoc sensor
JavaScript
45
star
24

myo-web-bluetooth.js

Connect to the Myo armband with Web Bluetooth
JavaScript
43
star
25

squid-game-tfjs

Squid Game's "Green light, red light" using body tracking with TensorFlow.js
JavaScript
42
star
26

Threejs-VR

Experiments using Three.js to create Virtual Reality experiences
JavaScript
37
star
27

rainbrow

Clone of the Rainbrow iOS game in JavaScript
JavaScript
36
star
28

webxr-pacman

Pac-Man prototype in WebXR using Three.js
JavaScript
36
star
29

leap_sphero

Experiment using the Leap Motion to control the Sphero
JavaScript
30
star
30

lifi

Prototype of Li-Fi technology using Arduino and JavaScript 💡
JavaScript
29
star
31

ARPoster

C#
19
star
32

leap_drone

Control the Parrot AR drone with the Leap Motion
JavaScript
19
star
33

daydream-node

Quick Node.js module to connect to the Daydream controller and receive all the data
JavaScript
18
star
34

teachable-keyboard

JavaScript
16
star
35

myo_sphero

Using the Myo armband to control the Sphero
JavaScript
15
star
36

browser-pong

Browser pong game
JavaScript
15
star
37

hand-control-figma-plugin

Prototype of Figma plugin to create UIs with hand movements using Tensorflow.js
JavaScript
14
star
38

fem-ml-workshop

Repository for my FrontEnd Masters workshop on Machine Learning in JavaScript
JavaScript
13
star
39

quaruntine

Prototype of motion controlled running app
JavaScript
11
star
40

face-pong

WIP - Pong game with face tracking
JavaScript
8
star
41

solidjs-netlify-starter

SolidJS + Netlify starter template
JavaScript
8
star
42

street-fighter-arduino-tflite

Prototype of Street Fighter game to play with hand movements using the Arduino Nano 33 BLE Sense and TensorFlow Lite
C
8
star
43

docker-tutorial

Source code for my tutorial on Docker for front-end devs
JavaScript
7
star
44

neurosky-brainwaves-visualizer

A Visualizer for the Neurosky Brain Sensor in Node.js
JavaScript
7
star
45

ml-image-recognition

[WIP]
Python
6
star
46

charliegerard.github.io

Portfolio
HTML
6
star
47

demo-restaurant-contentful-solid

JavaScript
6
star
48

cylon-projects

Hardware projects using Cylon.js
JavaScript
5
star
49

event-triggered-netlify-function

Demo showing how to use event-triggered Netlify Functions.
HTML
5
star
50

myo_drone

Using the Myo armband to control the Parrot AR Drone
JavaScript
5
star
51

neurosky-drone

Controlling the Parrot AR Drone with the Neurosky
JavaScript
4
star
52

EscPosEncoder.js

Browser version of EscPosEncoder to send commands to a receipt printer 🖨️
JavaScript
4
star
53

starwars

Recreating the Star Wars opening crawl using Three.js
HTML
4
star
54

spectrm

An Interactive Music Visualizer using the Web Audio API and Three.js
JavaScript
3
star
55

charliegerard

3
star
56

arduino-workshop

WIP
C++
2
star
57

react-native-prototype

JavaScript
2
star
58

Perspective

Experiment using head tracking
JavaScript
2
star
59

demo-restaurant-contentful-next

JavaScript
1
star
60

Morse

Prototype of Android app to translate Morse code
Java
1
star
61

webrebels2017

CSS
1
star
62

test-animations

Tests with canvas, two.js and three.js
JavaScript
1
star
63

smashdatcat

Javascript mini game
JavaScript
1
star
64

test

test
JavaScript
1
star
65

parcel-transformer-markdoc

📦 Parcel transformer for Markdown files using Markdoc
JavaScript
1
star
66

leapsync

Interactive visualization of sign language with the Leap Motion
HTML
1
star
67

nodeschool

JavaScript
1
star
68

neurosky-sphero-cylon

Control the Sphero with the Neurosky headset in Cylon.js
JavaScript
1
star
69

Processing_sketches

Processing sketches
Processing
1
star
70

Device_orientation_game

A quick game using device orientation
JavaScript
1
star
71

touch-table-prototype

Prototype of touch table using Processing and the Kinect
Processing
1
star
72

sydjs

SydJS talk on robots and programming for hardware
JavaScript
1
star