21 Commits

Author SHA1 Message Date
jwetzell 1f214396ae bump @jwetzell/osc to v1.3.0 2024-10-14 19:48:24 -05:00
jwetzell 925ff2a409 Merge pull request #23 from jwetzell/osc-array-type
add support for osc array types
2024-10-14 19:47:54 -05:00
jwetzell 5a5a6ab0a5 add support for osc array types 2024-10-14 19:46:49 -05:00
jwetzell 512b2d63c0 Merge pull request #19 from jwetzell/dependabot/npm_and_yarn/typescript-5.6.3
Bump typescript from 5.6.2 to 5.6.3
2024-10-14 07:17:08 -05:00
jwetzell e592229815 Merge pull request #20 from jwetzell/dependabot/npm_and_yarn/types/node-22.7.5
Bump @types/node from 22.7.4 to 22.7.5
2024-10-14 07:17:01 -05:00
jwetzell 768d6d5a4b Merge pull request #21 from jwetzell/dependabot/npm_and_yarn/commander-12.1.0
Bump commander from 11.1.0 to 12.1.0
2024-10-14 07:16:42 -05:00
dependabot[bot] 119574743d Bump commander from 11.1.0 to 12.1.0
Bumps [commander](https://github.com/tj/commander.js) from 11.1.0 to 12.1.0.
- [Release notes](https://github.com/tj/commander.js/releases)
- [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tj/commander.js/compare/v11.1.0...v12.1.0)

---
updated-dependencies:
- dependency-name: commander
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-14 05:14:18 +00:00
dependabot[bot] 709312585f Bump @types/node from 22.7.4 to 22.7.5
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 22.7.4 to 22.7.5.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-14 05:14:13 +00:00
dependabot[bot] fdaa8b8ed1 Bump typescript from 5.6.2 to 5.6.3
Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.6.2 to 5.6.3.
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml)
- [Commits](https://github.com/microsoft/TypeScript/compare/v5.6.2...v5.6.3)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-14 05:14:07 +00:00
jwetzell 91fdf60737 Merge pull request #18 from jwetzell/osc-d-type
add support for osc d type
2024-10-13 21:45:29 -05:00
jwetzell e5d559eb1a add support for osc d type 2024-10-13 21:45:03 -05:00
jwetzell 1c68227aac npm run format:write 2024-10-13 21:36:19 -05:00
jwetzell f32b8ce679 Merge pull request #17 from jwetzell/osc-h-type
add support for osc h type
2024-10-13 21:35:32 -05:00
jwetzell 0df2dec5e9 add support for osc h type 2024-10-13 21:34:44 -05:00
jwetzell d587b0cf19 fix error message on time tag fromBuffer 2024-10-13 21:18:41 -05:00
jwetzell eca0639b38 Merge pull request #16 from jwetzell/osc-I-type
add support for osc infinitum type
2024-10-13 21:18:15 -05:00
jwetzell 7601cfb096 add support for osc infinitum type 2024-10-13 21:16:22 -05:00
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
11 changed files with 200 additions and 31 deletions
+1 -1
View File
@@ -21,7 +21,7 @@
"license": "MIT",
"dependencies": {
"@jwetzell/osc": "0.2.2",
"commander": "^11.0.0",
"commander": "^12.1.0",
"slip": "^1.0.2"
}
}
+1 -1
View File
@@ -21,6 +21,6 @@
"license": "MIT",
"dependencies": {
"@jwetzell/osc": "1.0.0",
"commander": "^11.0.0"
"commander": "^12.1.0"
}
}
+1 -1
View File
@@ -21,7 +21,7 @@
"license": "MIT",
"dependencies": {
"@jwetzell/osc": "0.2.2",
"commander": "^11.0.0",
"commander": "^12.1.0",
"slip": "^1.0.2"
}
}
+16 -13
View File
@@ -23,7 +23,7 @@
"license": "MIT",
"dependencies": {
"@jwetzell/osc": "0.2.2",
"commander": "^11.0.0",
"commander": "^12.1.0",
"slip": "^1.0.2"
},
"bin": {
@@ -40,7 +40,7 @@
"license": "MIT",
"dependencies": {
"@jwetzell/osc": "1.0.0",
"commander": "^11.0.0"
"commander": "^12.1.0"
},
"bin": {
"readosc": "src/main.js"
@@ -56,7 +56,7 @@
"license": "MIT",
"dependencies": {
"@jwetzell/osc": "0.2.2",
"commander": "^11.0.0",
"commander": "^12.1.0",
"slip": "^1.0.2"
},
"bin": {
@@ -255,9 +255,10 @@
"peer": true
},
"node_modules/@types/node": {
"version": "22.7.4",
"version": "22.7.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz",
"integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.19.2"
}
@@ -611,10 +612,11 @@
"license": "MIT"
},
"node_modules/commander": {
"version": "11.1.0",
"license": "MIT",
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz",
"integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==",
"engines": {
"node": ">=16"
"node": ">=18"
}
},
"node_modules/concat-map": {
@@ -3406,9 +3408,10 @@
}
},
"node_modules/typescript": {
"version": "5.6.2",
"version": "5.6.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
"integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -3648,12 +3651,12 @@
},
"packages/osc": {
"name": "@jwetzell/osc",
"version": "1.1.0",
"version": "1.3.0",
"license": "MIT",
"devDependencies": {
"@types/node": "22.7.4",
"@types/node": "22.7.5",
"rimraf": "6.0.1",
"typescript": "5.6.2"
"typescript": "5.6.3"
}
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@jwetzell/osc",
"version": "1.1.0",
"version": "1.3.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -25,8 +25,8 @@
},
"license": "MIT",
"devDependencies": {
"@types/node": "22.7.4",
"@types/node": "22.7.5",
"rimraf": "6.0.1",
"typescript": "5.6.2"
"typescript": "5.6.3"
}
}
+47 -5
View File
@@ -33,12 +33,29 @@ export function messageToBuffer(message: OSCMessage): Uint8Array {
throw new Error('problem encoding address');
}
const typeString = message.args.map((arg) => arg.type).join('');
const typesBuffer = oscTypeConverterMap.s.toBuffer(`,${typeString}`);
let typeString = ','
const flatOSCArgs: OSCArg[] = []
message.args.forEach((oscArg)=> {
if(Array.isArray(oscArg)){
typeString += '['
oscArg.forEach((oscArg)=>{
typeString += oscArg.type
flatOSCArgs.push(oscArg)
})
typeString += ']'
}else {
typeString += oscArg.type
flatOSCArgs.push(oscArg)
}
})
const typesBuffer = oscTypeConverterMap.s.toBuffer(typeString);
if (typesBuffer === undefined) {
throw new Error('problem encoding types');
}
const argsBuffer = argsToBuffer(message.args);
const argsBuffer = argsToBuffer(flatOSCArgs);
const buffer = new Uint8Array(addressBuffer.length + typesBuffer.length + argsBuffer.length);
buffer.set(addressBuffer, 0);
buffer.set(typesBuffer, addressBuffer.length);
@@ -51,7 +68,7 @@ export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, U
throw new Error('osc message must start with a /');
}
const oscArgs: OSCArg[] = [];
const oscArgs: (OSCArg | OSCArg[])[] = [];
const [address, bytesAfterAddress] = oscTypeConverterMap.s.fromBuffer(bytes);
if (typeof address === 'string') {
@@ -61,9 +78,30 @@ export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, U
throw new Error('osc type string must start with a ,');
}
let argsBuffer = bytesAfterType;
let oscArrayArg: OSCArg[] = [];
let insideArgArray = false;
for (let index = 1; index < typeString.length; index++) {
const argType = typeString.charAt(index) as OSCType;
if (argType === '['){
if (insideArgArray){
throw new Error('osc arg array opened without closing previous arg array')
}
oscArrayArg = [];
insideArgArray = true;
continue;
}
if (argType === ']'){
if (!insideArgArray){
throw new Error('osc arg array closed without opening arg array')
}
oscArgs.push(oscArrayArg);
oscArrayArg = [];
insideArgArray = false;
continue;
}
const oscTypeConverter = oscTypeConverterMap[argType];
if (oscTypeConverter === undefined) {
throw new Error('unknown OSC type');
@@ -74,7 +112,11 @@ export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, U
type: argType,
value: value,
};
oscArgs.push(arg);
if(insideArgArray){
oscArrayArg.push(arg)
}else {
oscArgs.push(arg);
}
}
argsBuffer = remainingBytes;
}
+7 -5
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 | bigint | null;
};
export type OSCTimeTag = [number, number];
@@ -20,12 +20,14 @@ export type OSCBundle = {
export type OSCMessage = {
address: string;
args: OSCArg[];
args: (OSCArg | OSCArg[])[];
};
export type OSCTypeConverter = {
toBuffer: (value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor) => Uint8Array | undefined;
toBuffer: (
value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null | bigint
) => Uint8Array | undefined;
fromBuffer: (
buffer: Uint8Array
) => [string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | undefined, Uint8Array];
) => [string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null | bigint | undefined, Uint8Array];
};
+70 -1
View File
@@ -160,7 +160,7 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
},
fromBuffer: (buffer) => {
if (buffer.length < 8) {
throw new Error('osc time tag must be greater than 8 bytes');
throw new Error('osc time tag must be at least 8 bytes');
}
const [seconds, bytesAfterSeconds] = oscTypeConverterMap.i.fromBuffer(buffer);
const [fractional, bytesAfterFractional] = oscTypeConverterMap.i.fromBuffer(bytesAfterSeconds);
@@ -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,69 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
throw new Error('problem converting osc ');
},
},
N: {
toBuffer: () => {
return new Uint8Array(0);
},
fromBuffer: (buffer) => {
return [null, buffer];
},
},
I: {
toBuffer: () => {
return new Uint8Array();
},
fromBuffer: (buffer) => {
return [Number.MAX_SAFE_INTEGER, buffer];
},
},
h: {
toBuffer: (number) => {
const view = new DataView(new ArrayBuffer(8));
if (typeof number === 'number') {
view.setBigInt64(0, BigInt(number));
} else if (typeof number === 'bigint') {
view.setBigInt64(0, number);
} else {
throw new TypeError('osc type h toBuffer called with non number or bigint value');
}
return new Uint8Array(view.buffer);
},
fromBuffer: (buffer) => {
if (buffer.length < 8) {
throw new Error('osc int64 must be at least 8 bytes');
}
const view = new DataView(new ArrayBuffer(8));
buffer.subarray(0, 8).forEach((byte, index) => {
view.setUint8(index, byte);
});
return [view.getBigInt64(0), buffer.subarray(8)];
},
},
d: {
toBuffer: (number) => {
if (typeof number === 'number') {
const view = new DataView(new ArrayBuffer(8));
view.setFloat64(0, number);
return new Uint8Array(view.buffer);
}
throw new TypeError('osc type d toBuffer called with non number value');
},
fromBuffer: (buffer) => {
if (buffer.length < 8) {
throw new Error('not enough bytes to read a osc float');
}
const view = new DataView(new ArrayBuffer(8));
buffer.subarray(0, 8).forEach((byte, index) => {
view.setUint8(index, byte);
});
const value = view.getFloat64(0);
return [value, buffer.subarray(8)];
},
},
};
+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,
+29
View File
@@ -43,6 +43,35 @@ 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: 'simple address Inifinitum arg',
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 73, 0, 0]),
expected: { address: '/hello', args: [{ type: 'I', value: Number.MAX_SAFE_INTEGER }] },
},
{
description: 'simple address int64 arg',
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 104, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255]),
expected: { address: '/hello', args: [{ type: 'h', value: 281474976710655n }] },
},
{
description: 'simple address float64 arg',
bytes: new Uint8Array([
47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9, 0xe6,
]),
expected: { address: '/hello', args: [{ type: 'd', value: 12.7654763 }] },
},
{
description: 'simple address array arg',
bytes: new Uint8Array([
47, 104, 101, 108, 108, 111, 0, 0, 44, 91, 100, 105, 93, 0, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9, 0xe6, 0, 0, 3, 232
]),
expected: { address: '/hello', args: [[{ type: 'd', value: 12.7654763 }, { type: 'i', value: 1000}]] },
},
{
description: 'osc 1.0 spec example 1',
bytes: new Uint8Array([
+24
View File
@@ -43,6 +43,30 @@ 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: 'simple address int64 arg',
message: { address: '/hello', args: [{ type: 'h', value: 281474976710655n }] },
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 104, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255]),
},
{
description: 'simple address float64 arg',
message: { address: '/hello', args: [{ type: 'd', value: 12.7654763 }] },
expected: new Uint8Array([
47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9, 0xe6,
]),
},
{
description: 'simple address array arg',
message: { address: '/hello', args: [[{ type: 'd', value: 12.7654763 }, { type: 'i', value: 1000}]] },
expected: new Uint8Array([
47, 104, 101, 108, 108, 111, 0, 0, 44, 91, 100, 105, 93, 0, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9, 0xe6, 0, 0, 3, 232
]),
},
{
description: 'osc 1.0 spec example 1',
message: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },