10 Commits

Author SHA1 Message Date
jwetzell f75b663812 bump @jwetzell/osc to v1.1.0 2024-10-13 16:45:46 -05:00
jwetzell 7a72853e41 disable npm version git tagging 2024-10-13 16:44:54 -05:00
jwetzell 81e0a542c5 npm run format:write 2024-10-13 16:43:32 -05:00
jwetzell 278d09bb6f Merge pull request #14 from jwetzell/bundle-multiple-content-chunks
fix osc bundles not parsing multiple content chunks correctly
2024-10-13 16:43:08 -05:00
jwetzell 4b56f09a64 add test osc bundle from resolume 2024-10-13 16:42:11 -05:00
jwetzell b44e5d306a fix osc bundles not parsing multiple content chunks correctly 2024-10-13 16:41:49 -05:00
jwetzell 7a3ad57482 Merge pull request #13 from jwetzell/osc-r-type
add support for osc color type
2024-10-13 16:40:08 -05:00
jwetzell 13a8334504 add test for color type 2024-10-13 16:39:31 -05:00
jwetzell e0bae3b386 remove app build workflows 2024-10-13 16:38:52 -05:00
jwetzell 2716ccc349 add support for osc color type 2024-10-13 16:38:14 -05:00
14 changed files with 196 additions and 124 deletions
-25
View File
@@ -1,25 +0,0 @@
name: Check makeosc builds
on:
pull_request:
branches:
- main
paths:
- 'apps/makeosc/**'
jobs:
build-webui:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Node.js
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version-file: '.nvmrc'
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Install Node.js dependencies
run: npm ci --workspace makeosc
- run: npm run build --workspace makeosc
-25
View File
@@ -1,25 +0,0 @@
name: Check readosc builds
on:
pull_request:
branches:
- main
paths:
- 'apps/readosc/**'
jobs:
build-webui:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Node.js
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version-file: '.nvmrc'
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Install Node.js dependencies
run: npm ci --workspace readosc
- run: npm run build --workspace readosc
-25
View File
@@ -1,25 +0,0 @@
name: Check sendosc builds
on:
pull_request:
branches:
- main
paths:
- 'apps/sendosc/**'
jobs:
build-webui:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Node.js
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version-file: '.nvmrc'
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Install Node.js dependencies
run: npm ci --workspace sendosc
- run: npm run build --workspace sendosc
+1
View File
@@ -0,0 +1 @@
git-tag-version=false
+3 -5
View File
@@ -10,18 +10,16 @@ program.description('simple util to read osc packets from stdin');
program.action(() => {
process.stdin.on('data', (data) => {
try {
let remainingBytes = data
while(remainingBytes.length > 0){
let remainingBytes = data;
while (remainingBytes.length > 0) {
try {
const [message, bytesAfterMessage] = osc.messageFromBuffer(remainingBytes);
remainingBytes = bytesAfterMessage
remainingBytes = bytesAfterMessage;
console.log(JSON.stringify(message));
} catch (error) {
console.error({ error: error.toString() });
}
}
} catch (error) {
console.error({ error: error.toString() });
}
+6 -1
View File
@@ -46,6 +46,11 @@
"readosc": "src/main.js"
}
},
"apps/readosc/node_modules/@jwetzell/osc": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@jwetzell/osc/-/osc-1.0.0.tgz",
"integrity": "sha512-242gA8R4k9vBbRJydqoKAG1WiQ9BUO6tFoemuC3eywRt5ns5qrlzIBEIwX0poQyMZdZB7XyzvR5rtbFC5tadKg=="
},
"apps/sendosc": {
"version": "1.0.1",
"license": "MIT",
@@ -3643,7 +3648,7 @@
},
"packages/osc": {
"name": "@jwetzell/osc",
"version": "1.0.0",
"version": "1.1.0",
"license": "MIT",
"devDependencies": {
"@types/node": "22.7.4",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@jwetzell/osc",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
+41 -31
View File
@@ -22,42 +22,52 @@ export function bundleFromBuffer(bytes: Uint8Array): [OSCBundle | undefined, Uin
let endOfBundle = false;
let [contentSize, remainingBytes] = oscTypeConverterMap.i.fromBuffer(bytesAfterTimeTag);
if (typeof contentSize === 'number') {
while (!endOfBundle) {
if (remainingBytes.length < contentSize) {
throw new Error('bundle does not contain enough data');
}
// let [contentSize, remainingBytes] = oscTypeConverterMap.i.fromBuffer(bytesAfterTimeTag);
let remainingBytes = bytesAfterTimeTag;
const bundleContentBytes = remainingBytes.subarray(0, contentSize);
while (!endOfBundle) {
let [contentSize, bytesAfterContentSize] = oscTypeConverterMap.i.fromBuffer(remainingBytes);
if (bundleContentBytes[0] === 35) {
// # character indicating contents is a bundle
const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
if (content) {
bundleContents.push(content);
}
} else if (bundleContentBytes[0] === 47) {
const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
if (content && content !== undefined) {
bundleContents.push(content);
}
} else {
throw new Error('bundle contents does not look like a OSC message or bundle');
}
remainingBytes = remainingBytes.subarray(contentSize);
if (remainingBytes.length === 0) {
endOfBundle = true;
}
if (typeof contentSize !== 'number') {
throw new Error('problem decoding content size');
}
remainingBytes = bytesAfterContentSize;
if (remainingBytes.length < contentSize) {
throw new Error('bundle does not contain enough data');
}
const bundleContentBytes = bytesAfterContentSize.subarray(0, contentSize);
if (bundleContentBytes[0] === 35) {
// # character indicating contents is a bundle
const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
if (content) {
bundleContents.push(content);
}
} else if (bundleContentBytes[0] === 47) {
const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
if (content && content !== undefined) {
bundleContents.push(content);
}
} else {
throw new Error('bundle contents does not look like a OSC message or bundle');
}
remainingBytes = bytesAfterContentSize.subarray(contentSize);
if (remainingBytes.length === 0) {
endOfBundle = true;
}
return [{
timeTag,
contents: bundleContents,
},remainingBytes];
}
return [undefined, undefined]
return [
{
timeTag,
contents: bundleContents,
},
remainingBytes,
];
}
export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
+8 -5
View File
@@ -78,11 +78,14 @@ export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, U
}
argsBuffer = remainingBytes;
}
return [{
address,
args: oscArgs,
}, argsBuffer];
return [
{
address,
args: oscArgs,
},
argsBuffer,
];
}
}
return [undefined, undefined]
return [undefined, undefined];
}
+13 -4
View File
@@ -1,11 +1,18 @@
export type OSCType = 's' | 'i' | 'f' | 'b' | 'T' | 'F' | 't';
export type OSCType = 's' | 'i' | 'f' | 'b' | 'T' | 'F' | 't' | 'r';
export type OSCArg = {
type: OSCType;
value: string | number | Uint8Array | boolean | OSCTimeTag;
value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor;
};
export type OSCTimeTag = [number, number];
export type OSCColor = {
r: number;
g: number;
b: number;
a: number;
};
export type OSCBundle = {
timeTag: OSCTimeTag;
contents: (OSCBundle | OSCMessage)[];
@@ -17,6 +24,8 @@ export type OSCMessage = {
};
export type OSCTypeConverter = {
toBuffer: (value: string | number | Uint8Array | boolean | OSCTimeTag) => Uint8Array | undefined;
fromBuffer: (buffer: Uint8Array) => [string | number | Uint8Array | boolean | OSCTimeTag | undefined, Uint8Array];
toBuffer: (value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor) => Uint8Array | undefined;
fromBuffer: (
buffer: Uint8Array
) => [string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | undefined, Uint8Array];
};
+45
View File
@@ -171,4 +171,49 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
return [undefined, bytesAfterFractional];
},
},
r: {
toBuffer: (color) => {
if (typeof color === 'object' && 'r' in color && 'g' in color && 'b' in color && 'a' in color) {
const view = new DataView(new ArrayBuffer(4));
view.setUint8(0, color.r);
view.setUint8(1, color.g);
view.setUint8(2, color.b);
view.setUint8(3, color.a);
return new Uint8Array(view.buffer);
}
throw new TypeError('osc type r called with non OSCColor object');
},
fromBuffer: (buffer) => {
if (buffer.length < 4) {
throw new Error('osc color must be at least 4 bytes');
}
const red = buffer[0];
const green = buffer[1];
const blue = buffer[2];
const alpha = buffer[3];
if (red !== undefined && green !== undefined && blue !== undefined && alpha !== undefined) {
if (
typeof red === 'number' &&
typeof green === 'number' &&
typeof blue === 'number' &&
typeof alpha === 'number'
) {
return [
{
r: red,
g: green,
b: blue,
a: alpha,
},
buffer.subarray(4),
];
}
}
throw new Error('problem converting osc ');
},
},
};
+67 -1
View File
@@ -20,13 +20,79 @@ const tests = [
contents: [{ address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] }],
},
},
{
decription: '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,
0x73, 0x2f, 0x31, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d,
0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x2c, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x2f, 0x70, 0x6f, 0x73, 0x69,
0x74, 0x69, 0x6f, 0x6e, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x3c, 0x2f, 0x63,
0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x2f, 0x31,
0x2f, 0x63, 0x6c, 0x69, 0x70, 0x73, 0x2f, 0x34, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f,
0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c,
0x9c, 0x00, 0x00, 0x00, 0x38, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73,
0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x63, 0x6c, 0x69, 0x70, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f,
0x72, 0x74, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00,
0x3d, 0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x28, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
0x6e, 0x2f, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x2f, 0x31, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x2c, 0x2f, 0x63, 0x6f, 0x6d, 0x70,
0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x6c, 0x61, 0x79,
0x65, 0x72, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c,
0x9c, 0x00, 0x00, 0x00, 0x3c, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6c,
0x61, 0x79, 0x65, 0x72, 0x73, 0x2f, 0x31, 0x2f, 0x63, 0x6c, 0x69, 0x70, 0x73, 0x2f, 0x34, 0x2f, 0x74, 0x72, 0x61,
0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00,
0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x38, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73,
0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x63, 0x6c, 0x69, 0x70, 0x2f,
0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00,
0x00, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c, 0x9c,
]),
expected: {
timeTag: [0, 1],
contents: [
{
address: '/composition/layers/1/position',
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
},
{
address: '/composition/selectedlayer/position',
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
},
{
address: '/composition/layers/1/clips/4/transport/position',
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
},
{
address: '/composition/selectedclip/transport/position',
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
},
{
address: '/composition/layers/1/position',
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
},
{
address: '/composition/selectedlayer/position',
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
},
{
address: '/composition/layers/1/clips/4/transport/position',
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
},
{
address: '/composition/selectedclip/transport/position',
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
},
],
},
},
];
describe('OSC Bundle Decoding', () => {
tests.forEach((bundleTest) => {
it(bundleTest.description, () => {
const [encoded, remainingBytes] = osc.bundleFromBuffer(bundleTest.bytes);
equal(remainingBytes.length, 0)
equal(remainingBytes.length, 0);
deepEqual(encoded, bundleTest.expected);
});
});
+6 -1
View File
@@ -38,6 +38,11 @@ const tests = [
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 70, 0, 0]),
expected: { address: '/hello', args: [{ type: 'F', value: false }] },
},
{
description: 'simple address color arg',
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: 'osc 1.0 spec example 1',
bytes: new Uint8Array([
@@ -70,7 +75,7 @@ describe('OSC Message Decoding', () => {
tests.forEach((messageTest) => {
it(messageTest.description, () => {
const [decoded, remainingBytes] = osc.messageFromBuffer(messageTest.bytes);
equal(remainingBytes.length, 0)
equal(remainingBytes.length, 0);
deepEqual(decoded, messageTest.expected);
});
});
@@ -38,6 +38,11 @@ const tests = [
message: { address: '/hello', args: [{ type: 'F', value: false }] },
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 70, 0, 0]),
},
{
description: 'simple address color arg',
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: 'osc 1.0 spec example 1',
message: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },