Adding bry shortcut for binrhythm
This commit is contained in:
@ -1650,6 +1650,7 @@ export class UserAPI {
|
|||||||
let tobin: boolean[] = convert.split("").map((x: string) => x === "1");
|
let tobin: boolean[] = convert.split("").map((x: string) => x === "1");
|
||||||
return this.beat(div) && tobin.beat(div);
|
return this.beat(div) && tobin.beat(div);
|
||||||
};
|
};
|
||||||
|
bry = this.binrhythm;
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
// Low Frequency Oscillators
|
// Low Frequency Oscillators
|
||||||
@ -1775,7 +1776,7 @@ export class UserAPI {
|
|||||||
* @see noise
|
* @see noise
|
||||||
*/
|
*/
|
||||||
const period = 1 / freq;
|
const period = 1 / freq;
|
||||||
const t = (Date.now() / 1000 ) % period;
|
const t = (Date.now() / 1000) % period;
|
||||||
return (t / period < duty ? 1 : -1);
|
return (t / period < duty ? 1 : -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2659,4 +2660,5 @@ export class UserAPI {
|
|||||||
public getThemes = (): string[] => {
|
public getThemes = (): string[] => {
|
||||||
return Object.keys(colorschemes);
|
return Object.keys(colorschemes);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,29 +6,29 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { registerSound, onTriggerSample } from "superdough";
|
import { registerSound, onTriggerSample } from "superdough";
|
||||||
|
|
||||||
export const isAudioFile = (filename: string) => ['wav', 'mp3'].includes(filename.split('.').slice(-1)[0]);
|
export const isAudioFile = (filename: string) => ['wav', 'mp3'].includes(filename.split('.').slice(-1)[0]);
|
||||||
|
|
||||||
interface samplesDBConfig {
|
interface samplesDBConfig {
|
||||||
dbName: string,
|
dbName: string,
|
||||||
table: string,
|
table: string,
|
||||||
columns: string[],
|
columns: string[],
|
||||||
version: number
|
version: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const samplesDBConfig = {
|
export const samplesDBConfig = {
|
||||||
dbName: 'samples',
|
dbName: 'samples',
|
||||||
table: 'usersamples',
|
table: 'usersamples',
|
||||||
columns: ['data_url', 'title'],
|
columns: ['data_url', 'title'],
|
||||||
version: 1
|
version: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bufferToDataUrl(buf: Buffer) {
|
async function bufferToDataUrl(buf: Buffer) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
var blob = new Blob([buf], { type: 'application/octet-binary' });
|
var blob = new Blob([buf], { type: 'application/octet-binary' });
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = function (event: Event) {
|
reader.onload = function(event: Event) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
resolve(event.target.result);
|
resolve(event.target.result);
|
||||||
};
|
};
|
||||||
@ -65,7 +65,7 @@ const processFilesForIDB = async (files: FileList) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const registerSamplesFromDB = (config: samplesDBConfig, onComplete = () => {}) => {
|
export const registerSamplesFromDB = (config: samplesDBConfig, onComplete = () => { }) => {
|
||||||
openDB(config, (objectStore: IDBObjectStore) => {
|
openDB(config, (objectStore: IDBObjectStore) => {
|
||||||
let query = objectStore.getAll();
|
let query = objectStore.getAll();
|
||||||
query.onsuccess = (event: Event) => {
|
query.onsuccess = (event: Event) => {
|
||||||
@ -107,49 +107,49 @@ export const registerSamplesFromDB = (config: samplesDBConfig, onComplete = () =
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const openDB = (config: samplesDBConfig, onOpened: Function) => {
|
export const openDB = (config: samplesDBConfig, onOpened: Function) => {
|
||||||
const { dbName, version, table, columns } = config
|
const { dbName, version, table, columns } = config
|
||||||
|
|
||||||
if (!('indexedDB' in window)) {
|
if (!('indexedDB' in window)) {
|
||||||
console.log('This browser doesn\'t support IndexedDB')
|
console.log('This browser doesn\'t support IndexedDB')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const dbOpen = indexedDB.open(dbName, version);
|
const dbOpen = indexedDB.open(dbName, version);
|
||||||
|
|
||||||
|
|
||||||
dbOpen.onupgradeneeded = (_event) => {
|
dbOpen.onupgradeneeded = (_event) => {
|
||||||
const db = dbOpen.result;
|
const db = dbOpen.result;
|
||||||
const objectStore = db.createObjectStore(table, { keyPath: 'id', autoIncrement: false });
|
const objectStore = db.createObjectStore(table, { keyPath: 'id', autoIncrement: false });
|
||||||
columns.forEach((c: any) => {
|
columns.forEach((c: any) => {
|
||||||
objectStore.createIndex(c, c, { unique: false });
|
objectStore.createIndex(c, c, { unique: false });
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
dbOpen.onerror = function(err: Event) {
|
||||||
|
console.log('Error opening DB: ', (err.target as IDBOpenDBRequest).error);
|
||||||
|
}
|
||||||
|
dbOpen.onsuccess = function(_event: Event) {
|
||||||
|
const db = dbOpen.result;
|
||||||
|
db.onversionchange = function() {
|
||||||
|
db.close();
|
||||||
|
alert("Database is outdated, please reload the page.")
|
||||||
};
|
};
|
||||||
dbOpen.onerror = function (err: Event) {
|
const writeTransaction = db.transaction([table], 'readwrite'),
|
||||||
console.log('Error opening DB: ', (err.target as IDBOpenDBRequest).error);
|
objectStore = writeTransaction.objectStore(table);
|
||||||
}
|
// Writing in the database here!
|
||||||
dbOpen.onsuccess = function (_event: Event) {
|
onOpened(objectStore)
|
||||||
const db = dbOpen.result;
|
}
|
||||||
db.onversionchange = function() {
|
|
||||||
db.close();
|
|
||||||
alert("Database is outdated, please reload the page.")
|
|
||||||
};
|
|
||||||
const writeTransaction = db.transaction([table], 'readwrite'),
|
|
||||||
objectStore = writeTransaction.objectStore(table);
|
|
||||||
// Writing in the database here!
|
|
||||||
onOpened(objectStore)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const uploadSamplesToDB = async (config: samplesDBConfig, files: FileList) => {
|
export const uploadSamplesToDB = async (config: samplesDBConfig, files: FileList) => {
|
||||||
await processFilesForIDB(files).then((files) => {
|
await processFilesForIDB(files).then((files) => {
|
||||||
const onOpened = (objectStore: IDBObjectStore, _db: IDBDatabase) => {
|
const onOpened = (objectStore: IDBObjectStore, _db: IDBDatabase) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
files.forEach((file: File) => {
|
files.forEach((file: File) => {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
objectStore.put(file);
|
objectStore.put(file);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
openDB(config, onOpened);
|
openDB(config, onOpened);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -788,7 +788,7 @@ const completionDatabase: CompletionDatabase = {
|
|||||||
name: "counter",
|
name: "counter",
|
||||||
category: "patterns",
|
category: "patterns",
|
||||||
description: "Counter/iterator",
|
description: "Counter/iterator",
|
||||||
example: "counter('my_counter_, 20, 1)",
|
example: "counter('my_counter', 20, 1)",
|
||||||
},
|
},
|
||||||
drunk: {
|
drunk: {
|
||||||
name: "drunk",
|
name: "drunk",
|
||||||
|
|||||||
@ -578,12 +578,11 @@ export class Editor {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.hydra_backend = new Hydra({
|
this.hydra_backend = new Hydra({
|
||||||
canvas: this.interface.hydra_canvas as HTMLCanvasElement,
|
canvas: this.interface.hydra_canvas as HTMLCanvasElement,
|
||||||
width: 1280,
|
|
||||||
height: 768,
|
|
||||||
detectAudio: false,
|
detectAudio: false,
|
||||||
enableStreamCapture: false,
|
enableStreamCapture: false,
|
||||||
});
|
});
|
||||||
this.hydra = this.hydra_backend.synth;
|
this.hydra = this.hydra_backend.synth;
|
||||||
|
this.hydra.setResolution(1280, 768);
|
||||||
(globalThis as any).hydra = this.hydra;
|
(globalThis as any).hydra = this.hydra;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user