improvements on osc input
This commit is contained in:
14
src/API.ts
14
src/API.ts
@ -1,5 +1,5 @@
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { sendToServer, type OSCMessage } from "./IO/OSC";
|
||||
import { sendToServer, type OSCMessage, oscMessages } from "./IO/OSC";
|
||||
import { getAllScaleNotes, nearScales, seededRandom } from "zifferjs";
|
||||
import {
|
||||
MidiCCEvent,
|
||||
@ -2109,6 +2109,18 @@ export class UserAPI {
|
||||
} as OSCMessage);
|
||||
}
|
||||
|
||||
public getOSC = (address?: string): any[] => {
|
||||
/**
|
||||
* Give access to incoming OSC messages. If no address is specified, returns the raw oscMessages array. If an address is specified, returns only the messages who contain the address and filter the address itself.
|
||||
*/
|
||||
if (address) {
|
||||
let messages = oscMessages.filter((msg) => msg.address === address);
|
||||
messages = messages.map((msg) => msg.data);
|
||||
return messages
|
||||
} else {
|
||||
return oscMessages;
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================
|
||||
// Transport functions
|
||||
|
||||
@ -9,9 +9,18 @@ export interface OSCMessage {
|
||||
export let outputSocket = new WebSocket("ws://localhost:3000");
|
||||
export let inputSocket = new WebSocket("ws://localhost:3001");
|
||||
|
||||
inputSocket.onmessage= function (event) {
|
||||
console.log("Received: ", event.data);
|
||||
}
|
||||
// Queue of 1000 last messages
|
||||
export let oscMessages : any[] = [];
|
||||
|
||||
inputSocket.addEventListener('message', (event) => {
|
||||
let data = JSON.parse(event.data);
|
||||
if (oscMessages.length > 1000) {
|
||||
oscMessages.shift();
|
||||
}
|
||||
oscMessages.push(data);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// @ts-ignore
|
||||
outputSocket.onopen = function (event) {
|
||||
@ -20,7 +29,7 @@ outputSocket.onopen = function (event) {
|
||||
outputSocket.send(
|
||||
JSON.stringify({
|
||||
address: "/successful_connexion",
|
||||
args: true,
|
||||
port: 3000, args: {}
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@ -16,9 +16,12 @@ To use **OSC** with Topos, you will need to download the <ic>ToposServer</ic> by
|
||||
- 3) Start the server using <ic>npm start</ic>.
|
||||
- 4) Open the <ic>Topos</ic> application in your web browser.
|
||||
|
||||
This server can be used both for **OSC** _input_ and _output_.
|
||||
|
||||
## Input
|
||||
|
||||
Send an **OSC** message to the server at the address <ic>localhost:30000</ic>. You will receive your message in Topos as an Array containing the address and data of your message.
|
||||
|
||||
## Output
|
||||
|
||||
Once the server is loaded, you are ready to send an **OSC** message:
|
||||
|
||||
@ -4,7 +4,7 @@ import { scriptBlinkers } from "./Visuals/Blinkers";
|
||||
import { javascript } from "@codemirror/lang-javascript";
|
||||
import { markdown } from "@codemirror/lang-markdown";
|
||||
import { Extension } from "@codemirror/state";
|
||||
import { outputSocket } from "./IO/OSC";
|
||||
import { outputSocket, oscMessages } from "./IO/OSC";
|
||||
import {
|
||||
initializeSelectedUniverse,
|
||||
AppSettings,
|
||||
@ -206,6 +206,7 @@ export class Editor {
|
||||
// Loading universe from URL (if needed)
|
||||
loadUniverserFromUrl(this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private getBuffer(type: string): any {
|
||||
|
||||
Reference in New Issue
Block a user