4 Commits

Author SHA1 Message Date
jwetzell f9f763d6c4 bump @jwetzell/osc to v1.2.0 2024-10-13 17:18:01 -05:00
jwetzell 786e71fd82 Merge pull request #15 from jwetzell/osc-N-type
add support for osc nil type
2024-10-13 17:17:19 -05:00
jwetzell a2adc3d2f4 fix bundle test description 2024-10-13 17:15:19 -05:00
jwetzell 4ec6bae5fe add support for osc nil type 2024-10-13 17:15:02 -05:00
7 changed files with 29 additions and 7 deletions
+1 -1
View File
@@ -3648,7 +3648,7 @@
},
"packages/osc": {
"name": "@jwetzell/osc",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",
"devDependencies": {
"@types/node": "22.7.4",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@jwetzell/osc",
"version": "1.1.0",
"version": "1.2.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
+4 -4
View File
@@ -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 = {
type: OSCType;
value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor;
value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null;
};
export type OSCTimeTag = [number, number];
@@ -24,8 +24,8 @@ export type OSCMessage = {
};
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: (
buffer: Uint8Array
) => [string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | undefined, Uint8Array];
) => [string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null | undefined, Uint8Array];
};
+12
View File
@@ -173,6 +173,10 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
},
r: {
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) {
const view = new DataView(new ArrayBuffer(4));
@@ -216,4 +220,12 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
throw new Error('problem converting osc ');
},
},
N: {
toBuffer: () => {
return new Uint8Array(0);
},
fromBuffer: (buffer) => {
return [null, buffer];
},
},
};
+1 -1
View File
@@ -21,7 +21,7 @@ const tests = [
},
},
{
decription: 'resolume bundle example',
description: 'resolume bundle example',
bytes: new Uint8Array([
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,
@@ -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]),
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',
bytes: new Uint8Array([
@@ -43,6 +43,11 @@ const tests = [
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]),
},
{
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',
message: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },