Random additions
This commit is contained in:
63
src/API.ts
63
src/API.ts
@ -1,5 +1,9 @@
|
|||||||
import { seededRandom } from "zifferjs";
|
import { seededRandom } from "zifferjs";
|
||||||
import { MidiCCEvent, MidiConnection, MidiNoteEvent } from "./IO/MidiConnection";
|
import {
|
||||||
|
MidiCCEvent,
|
||||||
|
MidiConnection,
|
||||||
|
MidiNoteEvent,
|
||||||
|
} from "./IO/MidiConnection";
|
||||||
import { tryEvaluate, evaluateOnce } from "./Evaluator";
|
import { tryEvaluate, evaluateOnce } from "./Evaluator";
|
||||||
import { DrunkWalk } from "./Utils/Drunk";
|
import { DrunkWalk } from "./Utils/Drunk";
|
||||||
import { Editor } from "./main";
|
import { Editor } from "./main";
|
||||||
@ -32,6 +36,7 @@ export async function loadSamples() {
|
|||||||
registerSynthSounds()
|
registerSynthSounds()
|
||||||
),
|
),
|
||||||
registerZZFXSounds(),
|
registerZZFXSounds(),
|
||||||
|
samples("github:Bubobubobubobubo/Dough-Fox/main"),
|
||||||
samples("github:Bubobubobubobubo/Dough-Samples/main"),
|
samples("github:Bubobubobubobubo/Dough-Samples/main"),
|
||||||
samples("github:Bubobubobubobubo/Dough-Amiga/main"),
|
samples("github:Bubobubobubobubo/Dough-Amiga/main"),
|
||||||
samples("github:Bubobubobubobubo/Dough-Amen/main"),
|
samples("github:Bubobubobubobubo/Dough-Amen/main"),
|
||||||
@ -448,7 +453,9 @@ export class UserAPI {
|
|||||||
this.MidiConnection.panic();
|
this.MidiConnection.panic();
|
||||||
};
|
};
|
||||||
|
|
||||||
public active_note_events = (channel?: number): MidiNoteEvent[] | undefined => {
|
public active_note_events = (
|
||||||
|
channel?: number
|
||||||
|
): MidiNoteEvent[] | undefined => {
|
||||||
/**
|
/**
|
||||||
* @returns A list of currently active MIDI notes
|
* @returns A list of currently active MIDI notes
|
||||||
*/
|
*/
|
||||||
@ -458,9 +465,9 @@ export class UserAPI {
|
|||||||
} else {
|
} else {
|
||||||
events = this.MidiConnection.activeNotes;
|
events = this.MidiConnection.activeNotes;
|
||||||
}
|
}
|
||||||
if (events.length > 0) return events
|
if (events.length > 0) return events;
|
||||||
else return undefined;
|
else return undefined;
|
||||||
}
|
};
|
||||||
|
|
||||||
public transmission(): boolean {
|
public transmission(): boolean {
|
||||||
/**
|
/**
|
||||||
@ -476,50 +483,54 @@ export class UserAPI {
|
|||||||
const notes = this.active_note_events(channel);
|
const notes = this.active_note_events(channel);
|
||||||
if (notes && notes.length > 0) return notes.map((e) => e.note);
|
if (notes && notes.length > 0) return notes.map((e) => e.note);
|
||||||
else return undefined;
|
else return undefined;
|
||||||
}
|
};
|
||||||
|
|
||||||
public kill_active_notes = (): void => {
|
public kill_active_notes = (): void => {
|
||||||
/**
|
/**
|
||||||
* Clears all active notes
|
* Clears all active notes
|
||||||
*/
|
*/
|
||||||
this.MidiConnection.activeNotes = [];
|
this.MidiConnection.activeNotes = [];
|
||||||
}
|
};
|
||||||
|
|
||||||
public sticky_notes = (channel?: number): number[] | undefined => {
|
public sticky_notes = (channel?: number): number[] | undefined => {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param channel
|
* @param channel
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
let notes;
|
let notes;
|
||||||
if (channel) notes = this.MidiConnection.stickyNotesFromChannel(channel);
|
if (channel) notes = this.MidiConnection.stickyNotesFromChannel(channel);
|
||||||
else notes = this.MidiConnection.stickyNotes;
|
else notes = this.MidiConnection.stickyNotes;
|
||||||
if (notes.length > 0) return notes.map((e) => e.note);
|
if (notes.length > 0) return notes.map((e) => e.note);
|
||||||
else return undefined;
|
else return undefined;
|
||||||
}
|
};
|
||||||
|
|
||||||
public kill_sticky_notes = (): void => {
|
public kill_sticky_notes = (): void => {
|
||||||
/**
|
/**
|
||||||
* Clears all sticky notes
|
* Clears all sticky notes
|
||||||
*/
|
*/
|
||||||
this.MidiConnection.stickyNotes = [];
|
this.MidiConnection.stickyNotes = [];
|
||||||
}
|
};
|
||||||
|
|
||||||
public buffer = (channel?: number): boolean => {
|
public buffer = (channel?: number): boolean => {
|
||||||
/**
|
/**
|
||||||
* Return true if there is last note event
|
* Return true if there is last note event
|
||||||
*/
|
*/
|
||||||
if (channel) return this.MidiConnection.findNoteFromBufferInChannel(channel) !== undefined;
|
if (channel)
|
||||||
|
return (
|
||||||
|
this.MidiConnection.findNoteFromBufferInChannel(channel) !== undefined
|
||||||
|
);
|
||||||
else return this.MidiConnection.noteInputBuffer.length > 0;
|
else return this.MidiConnection.noteInputBuffer.length > 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
public buffer_event = (channel?: number): MidiNoteEvent | undefined => {
|
public buffer_event = (channel?: number): MidiNoteEvent | undefined => {
|
||||||
/**
|
/**
|
||||||
* @returns Returns latest unlistened note event
|
* @returns Returns latest unlistened note event
|
||||||
*/
|
*/
|
||||||
if (channel) return this.MidiConnection.findNoteFromBufferInChannel(channel);
|
if (channel)
|
||||||
|
return this.MidiConnection.findNoteFromBufferInChannel(channel);
|
||||||
else return this.MidiConnection.noteInputBuffer.shift();
|
else return this.MidiConnection.noteInputBuffer.shift();
|
||||||
}
|
};
|
||||||
|
|
||||||
public buffer_note = (channel?: number): number | undefined => {
|
public buffer_note = (channel?: number): number | undefined => {
|
||||||
/**
|
/**
|
||||||
@ -527,7 +538,7 @@ export class UserAPI {
|
|||||||
*/
|
*/
|
||||||
const note = this.buffer_event(channel);
|
const note = this.buffer_event(channel);
|
||||||
return note ? note.note : undefined;
|
return note ? note.note : undefined;
|
||||||
}
|
};
|
||||||
|
|
||||||
public last_note_event = (channel?: number): MidiNoteEvent | undefined => {
|
public last_note_event = (channel?: number): MidiNoteEvent | undefined => {
|
||||||
/**
|
/**
|
||||||
@ -535,7 +546,7 @@ export class UserAPI {
|
|||||||
*/
|
*/
|
||||||
if (channel) return this.MidiConnection.lastNoteInChannel[channel];
|
if (channel) return this.MidiConnection.lastNoteInChannel[channel];
|
||||||
else return this.MidiConnection.lastNote;
|
else return this.MidiConnection.lastNote;
|
||||||
}
|
};
|
||||||
|
|
||||||
public last_note = (channel?: number): number => {
|
public last_note = (channel?: number): number => {
|
||||||
/**
|
/**
|
||||||
@ -543,7 +554,7 @@ export class UserAPI {
|
|||||||
*/
|
*/
|
||||||
const note = this.last_note_event(channel);
|
const note = this.last_note_event(channel);
|
||||||
return note ? note.note : 60;
|
return note ? note.note : 60;
|
||||||
}
|
};
|
||||||
|
|
||||||
public last_cc = (control: number, channel?: number): number => {
|
public last_cc = (control: number, channel?: number): number => {
|
||||||
/**
|
/**
|
||||||
@ -553,17 +564,19 @@ export class UserAPI {
|
|||||||
if (this.MidiConnection.lastCCInChannel[channel]) {
|
if (this.MidiConnection.lastCCInChannel[channel]) {
|
||||||
return this.MidiConnection.lastCCInChannel[channel][control];
|
return this.MidiConnection.lastCCInChannel[channel][control];
|
||||||
} else return 64;
|
} else return 64;
|
||||||
}
|
} else return this.MidiConnection.lastCC[control] || 64;
|
||||||
else return this.MidiConnection.lastCC[control] || 64;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public has_cc = (channel?: number): boolean => {
|
public has_cc = (channel?: number): boolean => {
|
||||||
/**
|
/**
|
||||||
* Return true if there is last cc event
|
* Return true if there is last cc event
|
||||||
*/
|
*/
|
||||||
if (channel) return this.MidiConnection.findCCFromBufferInChannel(channel) !== undefined;
|
if (channel)
|
||||||
|
return (
|
||||||
|
this.MidiConnection.findCCFromBufferInChannel(channel) !== undefined
|
||||||
|
);
|
||||||
else return this.MidiConnection.ccInputBuffer.length > 0;
|
else return this.MidiConnection.ccInputBuffer.length > 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
public buffer_cc = (channel?: number): MidiCCEvent | undefined => {
|
public buffer_cc = (channel?: number): MidiCCEvent | undefined => {
|
||||||
/**
|
/**
|
||||||
@ -571,7 +584,7 @@ export class UserAPI {
|
|||||||
*/
|
*/
|
||||||
if (channel) return this.MidiConnection.findCCFromBufferInChannel(channel);
|
if (channel) return this.MidiConnection.findCCFromBufferInChannel(channel);
|
||||||
else return this.MidiConnection.ccInputBuffer.shift();
|
else return this.MidiConnection.ccInputBuffer.shift();
|
||||||
}
|
};
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
// Ziffers related functions
|
// Ziffers related functions
|
||||||
@ -924,7 +937,7 @@ export class UserAPI {
|
|||||||
this.app.clock.nudge = nudge;
|
this.app.clock.nudge = nudge;
|
||||||
}
|
}
|
||||||
return this.app.clock.nudge;
|
return this.app.clock.nudge;
|
||||||
}
|
};
|
||||||
|
|
||||||
public bpm = (n?: number): number => {
|
public bpm = (n?: number): number => {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import teletype_performance from "./teletype_performance.png";
|
||||||
|
|
||||||
export const about = (): string => {
|
export const about = (): string => {
|
||||||
return `
|
return `
|
||||||
# About Topos
|
# About Topos
|
||||||
|
|||||||
14
src/main.ts
14
src/main.ts
@ -37,7 +37,7 @@ import { makeStringExtensions } from "./StringExtensions";
|
|||||||
localStorage.openpages = Date.now();
|
localStorage.openpages = Date.now();
|
||||||
window.addEventListener(
|
window.addEventListener(
|
||||||
"storage",
|
"storage",
|
||||||
function(e) {
|
function (e) {
|
||||||
if (e.key == "openpages") {
|
if (e.key == "openpages") {
|
||||||
// Listen if anybody else is opening the same page!
|
// Listen if anybody else is opening the same page!
|
||||||
localStorage.page_available = Date.now();
|
localStorage.page_available = Date.now();
|
||||||
@ -110,7 +110,7 @@ export class Editor {
|
|||||||
|
|
||||||
// Audio stuff
|
// Audio stuff
|
||||||
audioContext: AudioContext;
|
audioContext: AudioContext;
|
||||||
dough_nudge: number = 0.25;
|
dough_nudge: number = 20;
|
||||||
view: EditorView;
|
view: EditorView;
|
||||||
clock: Clock;
|
clock: Clock;
|
||||||
manualPlay: boolean = false;
|
manualPlay: boolean = false;
|
||||||
@ -268,7 +268,6 @@ export class Editor {
|
|||||||
"audio_nudge"
|
"audio_nudge"
|
||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
|
|
||||||
|
|
||||||
// Dough nudge range
|
// Dough nudge range
|
||||||
dough_nudge_range: HTMLInputElement = document.getElementById(
|
dough_nudge_range: HTMLInputElement = document.getElementById(
|
||||||
"dough_nudge"
|
"dough_nudge"
|
||||||
@ -607,12 +606,11 @@ export class Editor {
|
|||||||
|
|
||||||
this.audio_nudge_range.addEventListener("input", () => {
|
this.audio_nudge_range.addEventListener("input", () => {
|
||||||
this.clock.nudge = parseInt(this.audio_nudge_range.value);
|
this.clock.nudge = parseInt(this.audio_nudge_range.value);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
this.dough_nudge_range.addEventListener("input", () => {
|
this.dough_nudge_range.addEventListener("input", () => {
|
||||||
this.dough_nudge = parseInt(this.dough_nudge_range.value);
|
this.dough_nudge = parseInt(this.dough_nudge_range.value);
|
||||||
})
|
});
|
||||||
|
|
||||||
this.upload_universe_button.addEventListener("click", () => {
|
this.upload_universe_button.addEventListener("click", () => {
|
||||||
const fileInput = document.createElement("input");
|
const fileInput = document.createElement("input");
|
||||||
@ -745,6 +743,10 @@ export class Editor {
|
|||||||
|
|
||||||
this.settings_button.addEventListener("click", () => {
|
this.settings_button.addEventListener("click", () => {
|
||||||
// Populate the font family selector
|
// Populate the font family selector
|
||||||
|
this.dough_nudge_range.value = this.dough_nudge.toString();
|
||||||
|
// @ts-ignore
|
||||||
|
document.getElementById("doughnumber")!.value =
|
||||||
|
this.dough_nudge.toString();
|
||||||
this.font_family_selector.value = this.settings.font;
|
this.font_family_selector.value = this.settings.font;
|
||||||
|
|
||||||
if (this.settings.font_size === null) {
|
if (this.settings.font_size === null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user