mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-08-21 14:59:01 +00:00
Compare commits
4 Commits
osc/v1.1.0
...
osc/v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| f9f763d6c4 | |||
| 786e71fd82 | |||
| a2adc3d2f4 | |||
| 4ec6bae5fe |
Generated
+1
-1
@@ -3648,7 +3648,7 @@
|
|||||||
},
|
},
|
||||||
"packages/osc": {
|
"packages/osc": {
|
||||||
"name": "@jwetzell/osc",
|
"name": "@jwetzell/osc",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "22.7.4",
|
"@types/node": "22.7.4",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@jwetzell/osc",
|
"name": "@jwetzell/osc",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export type OSCType = 's' | 'i' | 'f' | 'b' | 'T' | 'F' | 't' | 'r';
|
export type OSCType = 's' | 'i' | 'f' | 'b' | 'T' | 'F' | 't' | 'r' | 'N';
|
||||||
export type OSCArg = {
|
export type OSCArg = {
|
||||||
type: OSCType;
|
type: OSCType;
|
||||||
value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor;
|
value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OSCTimeTag = [number, number];
|
export type OSCTimeTag = [number, number];
|
||||||
@@ -24,8 +24,8 @@ export type OSCMessage = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type OSCTypeConverter = {
|
export type OSCTypeConverter = {
|
||||||
toBuffer: (value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor) => Uint8Array | undefined;
|
toBuffer: (value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null) => Uint8Array | undefined;
|
||||||
fromBuffer: (
|
fromBuffer: (
|
||||||
buffer: Uint8Array
|
buffer: Uint8Array
|
||||||
) => [string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | undefined, Uint8Array];
|
) => [string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null | undefined, Uint8Array];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -173,6 +173,10 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
|
|||||||
},
|
},
|
||||||
r: {
|
r: {
|
||||||
toBuffer: (color) => {
|
toBuffer: (color) => {
|
||||||
|
if (color === undefined || color === null){
|
||||||
|
throw new TypeError('osc type r called with undefined or null value');
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof color === 'object' && 'r' in color && 'g' in color && 'b' in color && 'a' in color) {
|
if (typeof color === 'object' && 'r' in color && 'g' in color && 'b' in color && 'a' in color) {
|
||||||
const view = new DataView(new ArrayBuffer(4));
|
const view = new DataView(new ArrayBuffer(4));
|
||||||
|
|
||||||
@@ -216,4 +220,12 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
|
|||||||
throw new Error('problem converting osc ');
|
throw new Error('problem converting osc ');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
N: {
|
||||||
|
toBuffer: () => {
|
||||||
|
return new Uint8Array(0);
|
||||||
|
},
|
||||||
|
fromBuffer: (buffer) => {
|
||||||
|
return [null, buffer];
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const tests = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
decription: 'resolume bundle example',
|
description: 'resolume bundle example',
|
||||||
bytes: new Uint8Array([
|
bytes: new Uint8Array([
|
||||||
0x23, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
0x23, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
0x28, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6c, 0x61, 0x79, 0x65, 0x72,
|
0x28, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6c, 0x61, 0x79, 0x65, 0x72,
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ const tests = [
|
|||||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22, 10]),
|
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22, 10]),
|
||||||
expected: { address: '/hello', args: [{ type: 'r', value: { r: 20, g: 21, b: 22, a: 10 } }] },
|
expected: { address: '/hello', args: [{ type: 'r', value: { r: 20, g: 21, b: 22, a: 10 } }] },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: 'simple address nil arg',
|
||||||
|
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 78, 0, 0]),
|
||||||
|
expected: { address: '/hello', args: [{ type: 'N', value: null }] },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: 'osc 1.0 spec example 1',
|
description: 'osc 1.0 spec example 1',
|
||||||
bytes: new Uint8Array([
|
bytes: new Uint8Array([
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ const tests = [
|
|||||||
message: { address: '/hello', args: [{ type: 'r', value: { r: 20, g: 21, b: 22, a: 10 } }] },
|
message: { address: '/hello', args: [{ type: 'r', value: { r: 20, g: 21, b: 22, a: 10 } }] },
|
||||||
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22, 10]),
|
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22, 10]),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: 'simple address nil arg',
|
||||||
|
message: { address: '/hello', args: [{ type: 'N', value: null }] },
|
||||||
|
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 78, 0, 0]),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: 'osc 1.0 spec example 1',
|
description: 'osc 1.0 spec example 1',
|
||||||
message: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },
|
message: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },
|
||||||
|
|||||||
Reference in New Issue
Block a user